zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Maven2-profile多环境配置
    Maven-setting.xml详解
    Maven-通过命令操作maven项目
    Maven-eclipse运行maven命令
    Eclipse-导入maven项目
    Maven-搭建maven web项目
    Maven-搭建普通maven项目
    Maven-pom.xml详解
    Maven-生命周期
    Maven-常用命令
  • 原文地址:https://www.cnblogs.com/zhengna/p/12722555.html
Copyright © 2011-2022 走看看