DVWA命令执行漏洞详解

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 参数一起使用。可能的值:
  • 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
<?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可选。规定所返回的数组元素的数目。

可能的值:

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

3. 分析

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

0x04 结语

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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值