• DVWA-2.3 Command Injection(命令注入)-High-绕过强的黑名单


    High Level

    查看源码

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

    相比Medium级别的代码,High级别的代码进一步完善了黑名单,但由于黑名单机制的局限性,我们依然可以绕过。

    漏洞利用

    黑名单看似过滤了所有的非法字符,但仔细观察到是把”| ”(注意这里|后有一个空格)替换为空字符,于是 ”|”成了“漏网之鱼”。

    127.0.0.1|net user

    Command 1 | Command 2

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

    总结

    本等级漏洞的成因是开发人员在写黑名单代码时,由于粗心,在|后面多打了一个空格,致使|成为漏网之鱼。

    可用trim()函数解决这个问题,因为 trim(str) 可以删除字符串左右两边的空格。

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

  • 相关阅读:
    Java异常
    Vector ArrayList LinkedList
    线程池
    Linux alias 或者 unalias 设置别名
    vim 知识点小结
    vim下出现^M怎么解决
    解决pip安装时出现报错TypeError unsupported operand type(s) for -= 'Retry' and 'int'
    MySQL备份与恢复
    mysql 去重的两种方式
    查看python的安装版本,位数及安装路径
  • 原文地址:https://www.cnblogs.com/zhengna/p/12722555.html
Copyright © 2020-2023  润新知