Low等级

命令执行漏洞主要是针对有网络测试的页面,如网络设备的web管理页面等等,利用其执行命令的输入窗口执行其他命令。

简单演示一下正常使用,输入127.0.0.1,执行:
upload successful

在DVWA靶场点击command injection设置等级为low

upload successful

使用命令连接符如&、&&、|、||来执行命令

相当于与或非,判断前面命令是否成功执行之后的自定义命令
upload successful
upload successful

Medium等级

做了一点防护措施,相当于没有。
将这些连接符做了个判断转为空,详情如下:
upload successful

解决方法

测试发现使用命令连接符&&和;都不执行。
upload successful

但是可以使用其他没有被处理的连接符
upload successful

High等级

连接符连接都不执行,已处理所有连接符
upload successful

解决方法

其实|是没处理的,加了空格,所以还是能够执行的
upload successful

执行结果:
upload successful

Impossible等级

是不可能等级,这个采用的是白名单的方式防护,只允许已知的命令执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

if( isset( $_POST[ 'Submit' ] ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );

// Get input
$target = $_REQUEST[ 'ip' ];
$target = stripslashes( $target );

// Split the IP into 4 octects
$octet = explode( ".", $target );

// Check IF each octet is an integer
if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
// If all 4 octets are int's put the IP back together.
$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];

// 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>";
}
else {
// Ops. Let the user name theres a mistake
echo '<pre>ERROR: You have entered an invalid IP.</pre>';
}
}

// Generate Anti-CSRF token
generateSessionToken();

?>