• 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地址)更加安全。

  • 相关阅读:
    在国外搭建 Web 服务器
    双向循环链表的实现
    使用C/C++扩展Python
    用C语音编写python的扩展模块,也就是python调c库
    《扩展和嵌入python解释器》1.4 模块方法表和初始化函数
    linux如何使用NFS挂载文件系统
    linux用户管理
    eims系统新增一级目录菜单流程
    Hadoop参考学习
    Got error: 1045:
  • 原文地址:https://www.cnblogs.com/zhengna/p/12722564.html
Copyright © 2020-2023  润新知