0x01 级别low
1.源码
Command Execution Source
<?php
if( isset( $_POST[ 'submit' ] ) ) {
$target = $_REQUEST[ 'ip' ];
// Determine OS and execute the ping command.
if (stristr(php_uname('s'), 'Windows NT')) {
$cmd = shell_exec( 'ping ' . $target );
echo '<pre>'.$cmd.'</pre>';
} else {
$cmd = shell_exec( 'ping -c 3 ' . $target );
echo '<pre>'.$cmd.'</pre>';
}
}
?>
2.说明:
stristr函数
stristr(string,search,before_search)
参数 | 描述 |
---|---|
string | 必需。规定被搜索的字符串。 |
search | 必需。规定要搜索的字符串。 如果该参数是数字,则搜索匹配该数字对应的 ASCII 值的字符。 |
before_search | 可选。默认值为 "false" 的布尔值。 如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分。 |
php_uname函数 是返回有关系统信息
3.分析
基本上没有什么防护机制 可轻松使用 "&&"或者";"字符进行连接命令
如:在输入框输入 127.0.0.1 && net user 、127.0.0.1 ; cd help && dir
0x02 级别medium
1.源码
Command Execution Source
<?php
if( isset( $_POST[ 'submit'] ) ) {
$target = $_REQUEST[ 'ip' ];
// Remove any of the charactars in the array (blacklist).
$substitutions = array(
'&&' => '',
';' => '',
);
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if (stristr(php_uname('s'), 'Windows NT')) {
$cmd = shell_exec( 'ping ' . $target );
echo '<pre>'.$cmd.'</pre>';
} else {
$cmd = shell_exec( 'ping -c 3 ' . $target );
echo '<pre>'.$cmd.'</pre>';
}
}
?>
2.说明
array_keys(array,value,strict)
参数 | 描述 |
---|---|
array | 必需。规定数组。 |
value | 可选。您可以指定键值,然后只有该键值对应的键名会被返回。 |
strict | 可选。与 value 参数一起使用。可能的值:
|
str_replace(find,replace,string,count)
参数 | 描述 |
---|---|
find | 必需。规定要查找的值。 |
replace | 必需。规定替换 find 中的值的值。 |
string | 必需。规定被搜索的字符串。 |
count | 可选。一个变量,对替换数进行计数。 |
3.分析
$substitutions = array(
'&&' => '',
';' => '',
);
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
加入了黑名单机制 替换了"&&" ";" 这样的连接字符
绕过方法
如:127.0.0.1 | dir、127.0.0.1 & dir 、 127.0.0.1 &; dir
0x03 级别high
1.源代码
Command Execution Source
<?php
if( isset( $_POST[ 'submit' ] ) ) {
$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')) {
$cmd = shell_exec( 'ping ' . $target );
echo '<pre>'.$cmd.'</pre>';
} else {
$cmd = shell_exec( 'ping -c 3 ' . $target );
echo '<pre>'.$cmd.'</pre>';
}
}
else {
echo '<pre>ERROR: You have entered an invalid IP</pre>';
}
}
?>
2. 说明
stripslashes(string)
参数 | 描述 |
---|---|
string | 必需。规定要检查的字符串。 |
返回值: | 返回剥离了反斜杠的字符串。 |
---|
explode(separator,string,limit)
参数 | 描述 |
---|---|
separator | 必需。规定在哪里分割字符串。 |
string | 必需。要分割的字符串。 |
limit | 可选。规定所返回的数组元素的数目。 可能的值:
|
3. 分析
这个暂时不知道绕过的方法,希望大佬能指出来,谢谢了
0x04 结语
这个DVWA命令执行简单比较简单,难得又很难,所以这篇文章只是作为参考。谢谢