DVWA之命令注入(command injection)

Command injection就是指通过提交恶意构造的参数破坏命令语句结构,从而达到执行恶意命令的目的

LOW

无论是Windows还是Linux,都可以使用&&连接多个命令

执行命令10.10.10.137&&net user

如果是Linux的话,我们还可以直接执行10.10.10.137&&cat /etc/shadow文件

 

Medium

 Medium过滤掉了命令连接符&&,;,但是没有过滤&,采用了黑名单机制

&&   和 &  连接的区别

&&连接的俩个命令,先执行第一个,执行成功后才执行第二个,否则不执行。

&连接的俩个命令,无论第一个是否执行成功,都会执行第二个

看过源码,此级别只对&&和;转为空格,所以

10.10.10.137&;&net user

 

High

 High级别完善了黑名单机制,附源码

 

<?php 

if( isset( $_POST[ 'Submit' ]  ) ) { 

    // Get input 

    $target = trim($_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 

    echo "<pre>{$cmd}</pre>"; 

} 

?> 

 

黑名单过滤了所有的非法输入,过滤了“|”,但是没有过滤“ |”

ping 10.10.10.137 |net user

 

impossiable

 暂时无解

posted @ 2018-04-11 16:12  山可填海,亦可逐月  阅读(369)  评论(0编辑  收藏  举报