zoukankan      html  css  js  c++  java
  • DVWA-2.2 Command Injection(命令注入)-Medium-绕过弱的黑名单

    Medium Level

    查看源码

    <?php
    
    if( isset( $_POST[ 'Submit' ]  ) ) {
        // Get input
        $target = $_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>";
    }
    
    ?>

    相关函数介绍

    str_replace(find,replace,string)

    把字符串 string 中的字符 find 替换为 replace

    漏洞利用

    方法一 127.0.0.1&net user

    因为被过滤的只有”&&”与” ;”,所以”&”不会受影响。

    这里需要注意的是”&&”与” &”的区别

    Command 1&&Command 2
    先执行Command 1,执行成功后执行Command 2,否则不执行Command 2

    Command 1&Command 2
    先执行Command 1,不管是否成功,都会执行Command 2

    方法二 127.0.0.1&;&ipconfig

    由于使用的是str_replace”&&” 、”;”替换为空字符,因此可以采用这种方式绕过。

    这是因为”127.0.0.1&;&ipconfig”中的” ;”会被替换为空字符,这样一来就变成了”127.0.0.1&& ipconfig” ,会成功执行。

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

  • 相关阅读:
    Oracle 数据库 用脚本建表空间
    C++ 类中封装Win32API的回调函数
    在MVC 4 中使用自定义Membership
    机试题目
    sscanf()
    字符串转化为整数
    有序数组中一对数的和为特定数
    把一个数组划分成左边奇数右边偶数
    cocos2dx将背景色改为白色
    字符串单词翻转
  • 原文地址:https://www.cnblogs.com/zhengna/p/12722465.html
Copyright © 2011-2022 走看看