DVWA-2.4 Command Injection(命令注入)-Impossible-安全的白名单

 
更多

Impossible Level

查看源码

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
    // Check Anti-CSRF token
    checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );

    // Get input
    $target = $_REQUEST[ 'ip' ];
    $target = stripslashes( $target );  //stripslashes()删除反斜杠

    // Split the IP into 4 octects
    $octet = explode( ".", $target );   //explode() 函数把字符串打散为数组

    // 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.---如果都为整数,则将其重新组合为ip
        $target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];

        // 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>";
    }
    else {
        // Ops. Let the user name theres a mistake
        $html .= '<pre>ERROR: You have entered an invalid IP.</pre>';
    }
}

// Generate Anti-CSRF token
generateSessionToken();

?>

可以看到,本等级的服务器源代码已被重写,只允许非常严格的输入。 如果不匹配并且没有产生特定结果,则将不允许执行它。 相比于前面2个等级的“黑名单”过滤(允许任何输入并删除不需要的内容),使用“白名单”(仅允许输入ip地址)更加安全。

打赏

本文固定链接: https://www.cxy163.net/archives/4918 | 绝缘体

该日志由 绝缘体.. 于 2020年05月06日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: DVWA-2.4 Command Injection(命令注入)-Impossible-安全的白名单 | 绝缘体
关键字: , , , ,

DVWA-2.4 Command Injection(命令注入)-Impossible-安全的白名单:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter