一 命令执行漏洞的理论基础
01 命令执行漏洞的原理
在操作系统中, & 、&& 、| 、 || 都可以作为命令连接符使用,用户通过浏览器提交执行命令,由于服务器端没有对执行函数进行过滤,从而造成可以执行危险命令.
Windows系列支持的管道符如下所示:
1. "|" : 直接执行后面的语句. 例如: ping 127.0.0.1|ipconfig
2. "||" : 如果前面执行的语句执行出错, 则执行后面的语句, 前面的语句只能为假. 例如: ping 2||ipconfig
3. "&" : 如果前面的语句为假则直接执行后面的语句,前面的语句可真可假. 例如: ping 127.0.0.1&ipconfig
4. "&&" : 如果前面的语句为假则直接出错, 也不执行后面的语句, 前面的语句只能为真. 例如: ping 127.0.0.1&&ipconfig
02 PHP的命令执行函数
PHP的命令执行函数主要有: :system、exec、passthru、shell_exec
二 DWVA实验演示
01 启动服务
02 登录DWVA
03 查看源码
Command Injection Source
vulnerabilities/exec/source/low.php
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>