zoukankan      html  css  js  c++  java
  • DVWA-6.2 Insecure CAPTCHA(不安全的验证码)-Medium

    Medium Level

    查看代码

    <?php
    
    if( isset( $_POST[ 'Change' ] ) && ( $_POST[ 'step' ] == '1' ) ) {
        // Hide the CAPTCHA form
        $hide_form = true;
    
        // Get input
        $pass_new  = $_POST[ 'password_new' ];
        $pass_conf = $_POST[ 'password_conf' ];
    
        // Check CAPTCHA from 3rd party
        $resp = recaptcha_check_answer(
            $_DVWA[ 'recaptcha_private_key' ],
            $_POST['g-recaptcha-response']
        );
    
        // Did the CAPTCHA fail?
        if( !$resp ) {
            // What happens when the CAPTCHA was entered incorrectly
            $html     .= "<pre><br />The CAPTCHA was incorrect. Please try again.</pre>";
            $hide_form = false;
            return;
        }
        else {
            // CAPTCHA was correct. Do both new passwords match?
            if( $pass_new == $pass_conf ) {
                // Show next stage for the user
                $html .= "
                    <pre><br />You passed the CAPTCHA! Click the button to confirm your changes.<br /></pre>
                    <form action="#" method="POST">
                        <input type="hidden" name="step" value="2" />
                        <input type="hidden" name="password_new" value="{$pass_new}" />
                        <input type="hidden" name="password_conf" value="{$pass_conf}" />
                        <input type="hidden" name="passed_captcha" value="true" />
                        <input type="submit" name="Change" value="Change" />
                    </form>";
            }
            else {
                // Both new passwords do not match.
                $html     .= "<pre>Both passwords must match.</pre>";
                $hide_form = false;
            }
        }
    }
    
    if( isset( $_POST[ 'Change' ] ) && ( $_POST[ 'step' ] == '2' ) ) {
        // Hide the CAPTCHA form
        $hide_form = true;
    
        // Get input
        $pass_new  = $_POST[ 'password_new' ];
        $pass_conf = $_POST[ 'password_conf' ];
    
        // Check to see if they did stage 1----检查passed_captcha参数值
        if( !$_POST[ 'passed_captcha' ] ) {
            $html     .= "<pre><br />You have not passed the CAPTCHA.</pre>";
            $hide_form = false;
            return;
        }
    
        // Check to see if both password match
        if( $pass_new == $pass_conf ) {
            // They do!
            $pass_new = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $pass_new ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
            $pass_new = md5( $pass_new );
    
            // Update database
            $insert = "UPDATE `users` SET password = '$pass_new' WHERE user = '" . dvwaCurrentUser() . "';";
            $result = mysqli_query($GLOBALS["___mysqli_ston"],  $insert ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );
    
            // Feedback for the end user
            $html .= "<pre>Password Changed.</pre>";
        }
        else {
            // Issue with the passwords matching
            $html .= "<pre>Passwords did not match.</pre>";
            $hide_form = false;
        }
    
        ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
    }
    
    ?>

    可以看到,Medium级别的代码依然将改密操作分成了两步,第一步检查用户输入的验证码,验证通过后,服务器返回表单,第二步客户端提交post请求,服务器完成更改密码的操作。与Low级别不同的是,在第二步验证时,增加了对参数passed_captcha的检查,如果参数值为true,则认为用户已经通过了验证码检查,然而用户依然可以通过伪造参数绕过验证,本质上来说,这与Low级别的验证没有任何区别。

    漏洞利用

    1.可以通过抓包,更改step参数,增加passed_captcha参数,绕过验证码。

    抓到的包

    更改之后的包

    更改密码成功

    2.依然可以实施CSRF攻击,攻击页面代码如下

    当受害者访问这个页面时,攻击脚本会伪造改密请求发送给服务器。

    不过依然会跳转到更改密码成功的界面。

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

  • 相关阅读:
    Python性能分析指南
    centos加入启动服务
    北京户口
    北京户口
    【汽车进口税】 关于汽车进口税计算你知道多少-汽车保险资讯-阳光车险官方网站
    在北京公司要多长时间才可以申请摇车牌号
    Kivy: Crossplatform Framework for NUI
    说说设计模式~大话目录(Design Pattern)
    说说设计模式~策略模式(Strategy)
    说说设计模式~装饰器模式(Decorator)
  • 原文地址:https://www.cnblogs.com/zhengna/p/12765958.html
Copyright © 2011-2022 走看看