DVWA (命令行执行)
命令行执行(Command Injection)
命令连接符:
command1 & command2 :不管command1执行成功与否,都会执行command2(将上一个命令的输出作为下一个命令的输入);
command1 && command2 :先执行command1执行成功后才会执行command2;
command1 | command2 :只执行command2;
command1 || command2 :command1执行失败,再执行command2(若command1执行成功,就不再执行command2);
command 1;command2:只在Linux里适用,command1和command2独立执行, 不管command1执行成功没有,command2继续执行 。
Low
在输入框输入ip,用burp抓包,把数据发送给intruder;
把提交数据设置成变量,把可能构造成功的命令行执行语句都写进字典里,进行暴破;
暴破后发现返回数据包长度不同,这里是数据越长,表示被执行的命令越多,接下来我把这5个语句返回的结果都列举下面,我们可以做个比较;
1构造命令行执行成功;
2构造命令行执行成功;
3构造命令行执行失败;
4构造命令行执行成功;
5构造命令行执行失败;
以上结果显示,这124构造的语句都能利用该漏洞,这里ipconfig是显示或配置网络设备的命令,这里可以结合用途,构造自己需要的命令行。
Medium
源码
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Set blacklist
$substitutions = array(
'&&' => '',
';' => '',
);
// 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 "<pre>{$cmd}</pre>";
}
?>
发现下面这块给输入框做了限制,含有&&和;的都会被过滤,但是这可以用&或者|之类的连接符绕过。
$substitutions = array(
'&&' => '',
';' => '',
);
High
源码:
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]);
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
// 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 "<pre>{$cmd}</pre>";
}
?>
这里可以看到high级别只是比medium级别的过滤条件更多了,这里我们还是相应的绕过就好了,通过观察这里对|的限制是 |空格,所以并不是对|做了过滤,所以我们可以采取|来执行该漏洞。