命令注入(Command Injection),对一些函数的参数没有做过滤或过滤不严导致的,可以执行系统或者应用指令(CMD命令或者bash命令)的一种注入攻击手段。PHP命令注入攻击漏洞是PHP应用程序中常见的脚本漏洞之一。
以上三种连接符在windows和linux环境下都支持
难度(低)
审计代码
{$cmd}
";
}
?>
可以发现直接针对操作系统类型进行ping,没有对输入的数据作出任何过滤,非常危险。
开始操作:
选择命令注入模块
![](https://img1.php1.cn/3cd4a/24bf4/cd5/6c6299e9b405ca68.jpeg)
在文本框里输入”192.168.0.1 && net user”,得到以下系统中所有的用户
![](https://img1.php1.cn/3cd4a/24bf4/cd5/cf5c90c4a0de47d3.jpeg)
发现乱码,
乱码解决方法:
解决此问题的方法:在DVWA-master\dvwa\include目录下找到dvwaPage.inc.php文件中所有的”charset=utf-8″,修改”charset=gb2312″,即可
![](https://img1.php1.cn/3cd4a/24bf4/cd5/c4ac8e0518057b26.jpeg)
显示效果
![](https://img1.php1.cn/3cd4a/24bf4/cd5/d0012e155fa3df49.jpeg)
192.168.0.1 && net user
![](https://img1.php1.cn/3cd4a/24bf4/cd5/edf8d05fedd937ad.jpeg)
难度(中)
代码审计
'',
';' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// 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 "{$cmd}
";
}
?>
可以看到,相比Low级别的代码,服务器端对ip参数做了一定过滤,即把”&” 、”;”删除,本质上采用的是黑名单机制,因此依旧存在安全问题。
漏洞利用
输入127.0.0.1 |迪尔
![](https://img1.php1.cn/3cd4a/24bf4/cd5/ba71246e6029e56e.jpeg)
127.0.0.1 & ipconfig
![](https://img1.php1.cn/3cd4a/24bf4/cd5/061751c3125c4077.jpeg)
难度(高)
代码审计
'',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// 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 "{$cmd}
";
}
?>
相比Medium级别的代码,High级别的代码进一步完善了黑名单,但由于黑名单机制的局限性,我们依然可以绕过。
黑名单看似过滤了所有的非法字符,但仔细观察到是把|(注意这里|后有一个空格)替换为空字符,于是 |成了”漏网之鱼”。
漏洞利用
127.0.0.1|目录
![](https://img1.php1.cn/3cd4a/24bf4/cd5/e514fe68664e6fb0.jpeg)