DVWA-2.2 Command Injection(命令注入)-Medium-绕过弱的黑名单

Medium Level

查看源码

<?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
    $html .= "<pre>{$cmd}</pre>";
}

?>

相关函数介绍

str_replace(find,replace,string)

把字符串 string 中的字符 find 替换为 replace

漏洞利用

方法一 127.0.0.1&net user

因为被过滤的只有”&&”与” ;”,所以”&”不会受影响。

这里需要注意的是”&&”与” &”的区别

Command 1&&Command 2
先执行Command 1,执行成功后执行Command 2,否则不执行Command 2

Command 1&Command 2
先执行Command 1,不管是否成功,都会执行Command 2

方法二 127.0.0.1&;&ipconfig

由于使用的是str_replace”&&” 、”;”替换为空字符,因此可以采用这种方式绕过。

这是因为”127.0.0.1&;&ipconfig”中的” ;”会被替换为空字符,这样一来就变成了”127.0.0.1&& ipconfig” ,会成功执行。

 

参考:https://www.freebuf.com/articles/web/116714.html

posted @ 2020-05-06 16:28  zhengna  阅读(543)  评论(0编辑  收藏  举报