简介
原题复现:
考察知识点:无参数命令执行
线上平台:https://buuoj.cn(北京联合大学公开的CTF平台) 榆林学院内可使用信安协会内部的CTF训练平台找到此题
源码审计
代码
1 <?php 2 error_reporting(0); 3 //听说你很喜欢数学,不知道你是否爱它胜过爱flag 4 if(!isset($_GET['c'])){ 5 show_source(__FILE__); 6 }else{ 7 //例子 c=20-1 8 $content = $_GET['c']; 9 if (strlen($content) >= 80) { 10 die("太长了不会算"); 11 } 12 $blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]']; 13 foreach ($blacklist as $blackitem) { 14 if (preg_match('/' . $blackitem . '/m', $content)) { 15 die("请不要输入奇奇怪怪的字符"); 16 } 17 } 18 //常用数学函数http://www.w3school.com.cn/php/php_ref_math.asp 19 $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']; 20 preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs); 21 foreach ($used_funcs[0] as $func) { 22 if (!in_array($func, $whitelist)) { 23 die("请不要输入奇奇怪怪的函数"); 24 } 25 } 26 //帮你算出答案 27 eval('echo '.$content.';'); 28 }