DVWA——Command Injection

Command Injection

Low

{$cmd}
"; }

使用&&连接多条命令

127.0.0.1&&net user

Linux下输入127.0.0.1&&cat /something/甚至可以读取文件

Medium

 '', 

        ';'  => '', 

    ); 

    // Remove any of the charactars in the array (blacklist). 

    $target = str_replace( array_keys( $substitutions ), $substitutions, $target );     //str_replace(find,replace,string,count) 把$target中的字符array_keys($substitutions)替换为$substitutions;array_keys() 函数返回包含数组中所有键名的一个新数组

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

Medium对输入的参数进行了一定的过滤

所以可以使用:127.0.0.1&net user 

&是不管前面的有没有执行成功都执行后面的,&&是前面的执行成功了才会执行后面的语句

127.0.0.1&;&ipconfig 由于会删除;,就变成了正常的语句执行

High

 '', 
        ';'  => '', 
        '| ' => '', 
        '-'  => '', 
        '$'  => '', 
        '('  => '', 
        ')'  => '', 
        '`'  => '', 
        '||' => '', 
    ); 

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

看似过滤了所有的非法字符,但注意'| ' => ''中右侧有一个空格,所以可以使用"|"

127.0.0.1|net user

“|”是管道符,表示将1的输出作为2的输入,并且只打印2执行的结果

Impossible

{$cmd}
"; } else { // Ops. Let the user name theres a mistake echo '
ERROR: You have entered an invalid IP.
'; } } // Generate Anti-CSRF token generateSessionToken(); ?>
Impossible加入了Anti-CSRF token,同时对输入的参数进行了控制,只有为数字才可以被接受执行命令

你可能感兴趣的:(DVWA)