DVWA命令执行漏洞详解

0x01 级别low

1.源码

Command Execution Source
'.$cmd.'
'; } else { $cmd = shell_exec( 'ping -c 3 ' . $target ); echo '
'.$cmd.'
'; } } ?>

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
 '', 
        ';' => '', 
    ); 

    $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 '
'.$cmd.'
'; } else { $cmd = shell_exec( 'ping -c 3 ' . $target ); echo '
'.$cmd.'
'; } } ?>

2.说明

array_keys(array,value,strict)

 

参数 描述
array 必需。规定数组。
value 可选。您可以指定键值,然后只有该键值对应的键名会被返回。
strict 可选。与 value 参数一起使用。可能的值:
  • true - 返回带有指定键值的键名。依赖类型,数字 5 与字符串 "5" 是不同的。
  • false - 默认值。不依赖类型,数字 5 与字符串 "5" 是相同的。

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
'.$cmd.'
'; } else { $cmd = shell_exec( 'ping -c 3 ' . $target ); echo '
'.$cmd.'
'; } } else { echo '
ERROR: You have entered an invalid IP
'; } } ?>

 2. 说明

 stripslashes(string)

参数 描述
string 必需。规定要检查的字符串。
返回值: 返回剥离了反斜杠的字符串。

explode(separator,string,limit)

参数 描述
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的数目。

可能的值:

  • 大于 0 - 返回包含最多 limit 个元素的数组
  • 小于 0 - 返回包含除了最后的 -limit 个元素以外的所有元素的数组
  • 0 - 会被当做 1, 返回包含一个元素的数组

3. 分析

这个暂时不知道绕过的方法,希望大佬能指出来,谢谢了

0x04 结语

这个DVWA命令执行简单比较简单,难得又很难,所以这篇文章只是作为参考。谢谢

引用:https://www.runoob.com/

你可能感兴趣的:(DVWA命令执行漏洞详解)