文章更新于:2020-04-11
注:如何搭建环境参见:搭建DVWA Web渗透测试靶场
DVWA之命令注入漏洞
一、介绍
1.1、官方说明
The purpose of the command injection attack is to inject and execute commands specified by the attacker in the vulnerable application. In situation like this, the application, which executes unwanted system commands, is like a pseudo system shell, and the attacker may use it as any authorized system user. However, commands are executed with the same privileges and environment as the web service has.
Command injection attacks are possible in most cases because of lack of correct input data validation, which can be manipulated by the attacker (forms, cookies, HTTP headers etc.).
The syntax and commands may differ between the Operating Systems (OS), such as Linux and Windows, depending on their desired actions.
This attack may also be called “Remote Command Execution (RCE)”.
1.2、总结
总的来说就是如果Web服务器没有配置妥当,则可能产生命令注入漏洞。究其原因,是没有进行充分的验证访问者身份。
不同的操作系统比如(Linux 和 Windows)的命令格式是不相同的。
这种攻击方式也称为 远程命令执行 (RCE)
。
二、命令注入实践
2.1、安全级别:LOW
>> 查看源码
- 此对话框原意是输入一个 IP 或域名进行 PING 测试。
- 输入IP测试
- 点击页面右下角
View Source
得到如下源码:
<?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>";
}
?>
在这些 php
代码中,我们可以看到,处理逻辑没有做任何过滤,只是针对不同的平台,调用了不同的 ping
命令,然后将结果原样返回到前端。
这是非常危险的,如果可以使用 &
、&&
、|
、;
等命令分隔符同事执行多条命令。则可任意执行命令,是有可能可以在系统上创建用户留下后门的。
比如我们执行 | net user add hello 1234
如果系统有安全软件,可能会有如下提示:
如果没有安全软件,命令执行成功将有可能在系统留下后门。
>>尝试注入
注1:常用 &
、|
、;
作为命令分隔符。
注2:键盘左上角的反引号 ` ,会忽略掉外部的双引号先执行。
- 尝试用分号 ;分隔命令进行注入
注:这里使用的是 Linux 环境下的 IP查看命令。
- 尝试获取主机密码文件内容