首页 > 其他分享 >DVWA-Insecure CAPTCHA(不安全的验证码)

DVWA-Insecure CAPTCHA(不安全的验证码)

时间:2024-02-17 13:00:19浏览次数:23  
标签:captcha Insecure DVWA CAPTCHA GLOBALS pass mysqli ___ new

Insecure CAPTCHA 意思是不安全的验证码,指验证在验证过程中,存在逻辑漏洞,导致可以绕过验证。CAPTCHA全称为:Completely Automated Public Turing Test to Tell Computers and Humans Apart (全自动区分计算机和人类的图灵测试)。

DVWA-Insecure CAPTCHA级别:

  --low

  --medium

  --high

  --impossible

在dvwa中config.inc.php默认没有配置recaptcha_public_key和recaptche_private_key 的值。导致该页面无法全部显示完全部内容。

 可以通过MD5生成随机加密串:

将MD5加密的内容放到/var/www/html/config/config.inc.php 配置文件recaptcha_public_key 和recaptcha_private_key中

刷新页面:

 

--low级别:

服务器端代码:

<?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
            echo "
                <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=\"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 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
        echo "<pre>Password Changed.</pre>";
    }
    else {
        // Issue with the passwords matching
        echo "<pre>Passwords did not match.</pre>";
        $hide_form = false;
    }

    ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}

?>

可以看到这里将验证流程分为两个步骤,而且这两个步骤的验证过程是独立的(两个if没有包含在一起)。第1步step==1时,验证秘钥是否正确,如果秘钥正确的话,又自动发起一次请求并将参数step设置为2。第2步step==2时,验证新密码和确认密码一致时,就可以修改密码成功。

通过burp suite拦截接口,然后篡改step参数为2,看看是不是能修改密码成功

 

--medium级别:

服务器端代码:

<?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
            echo "
                <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
    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
        echo "<pre>Password Changed.</pre>";
    }
    else {
        // Issue with the passwords matching
        echo "<pre>Passwords did not match.</pre>";
        $hide_form = false;
    }

    ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}

?>

可以看到在medium中,在第1步(step==1)时,校验密码成功后,再请求第2步(step==2)时,加入了passed_captcha参数带入值为true,代表在第1步的密码已经验证通过,再验证新密码和确认密码通过后,就可以修改密码了。

那么通过burp suite拦截接口后,将step=1,改为step=2,同时增加参数passed_captcha=true,就可以进行密码修改。

修改好参数后,在放开拦截。密码修改成功了。

因为,在修改密码的第2步时服务器端调用的,在前端抓包根本就不知道有passed_captcha这个参数和值。那要怎么办?其他结合File Upload的包含漏洞,写一个php文件去读取服务器上源文件的信息就可以了。

写一个captcha_info.php 文件,如下:

<?php
    echo "<br/>captcha目录的位置:<br/>"; 
    $find_captcha = shell_exec("find / -name captcha");
    echo $find_captcha;
    
    echo "<br/>captcha目录信息:<br/>";
    $captcha_file = shell_exec("ls $find_captcha");
    echo $captcha_file;
    
    echo "<br/>captcha/source目录信息:<br/>";
    $captcha_source = shell_exec("ls $find_captcha/source");
    echo $captcha_source;
    
    
    echo "<br/>打印captcha/source/medium.php的信息:<br/>";
    $captcha_content = shell_exec("cat /var/www/html/vulnerabilities/captcha/source/medium.php");
    echo "$captcha_content";
 
?>

将文件上传到服务器上

在浏览器中调用../../hackable/uploads/captcha_info.php,执行结果如下:

所以说漏洞要相互利用,才能起到最大的作用。同时不要因为一个小小的漏洞而忽略掉修复,最终造成不必要的损失,老话说得好:千里之堤毁于蚁穴,就是这个道理。

--high级别:

服务器端代码:

<?php

if( isset( $_POST[ 'Change' ] ) ) {
    // 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']
    );

    if (
        $resp || 
        (
            $_POST[ 'g-recaptcha-response' ] == 'hidd3n_valu3'
            && $_SERVER[ 'HTTP_USER_AGENT' ] == 'reCAPTCHA'
        )
    ){
        // CAPTCHA was correct. Do both new passwords match?
        if ($pass_new == $pass_conf) {
            $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() . "' LIMIT 1;";
            $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 user
            echo "<pre>Password Changed.</pre>";

        } else {
            // Ops. Password mismatch
            $html     .= "<pre>Both passwords must match.</pre>";
            $hide_form = false;
        }

    } else {
        // What happens when the CAPTCHA was entered incorrectly
        $html     .= "<pre><br />The CAPTCHA was incorrect. Please try again.</pre>";
        $hide_form = false;
        return;
    }

    ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}

// Generate Anti-CSRF token
generateSessionToken();

?>
在high中已经将步骤2去掉将整个验证过程合在一起,所以不能直接跳过验证步骤1的方式了。但是在修改密码有一个判断
if (
        $resp || 
        (
            $_POST[ 'g-recaptcha-response' ] == 'hidd3n_valu3'
            && $_SERVER[ 'HTTP_USER_AGENT' ] == 'reCAPTCHA'
        )
    )
如果这个成立后,才会修改密码。$resp 是通过recaptcha_check_answe()将用户提交的验证信息提交由reCAPTCHA进行验证,
并返回结果信息,没法绕过。但是,$resp后面判断逻辑竟然是或”||”符号,那也就是说括号里面的结果为True时,就可以执行if里面的修改密码功能。

通过burp suite拦截接口,并将请求头中的信息User-Agent改为reCAPTCHA,并将新增参数g-recaptcha-response=hidd3n_valu3。

 

标签:captcha,Insecure,DVWA,CAPTCHA,GLOBALS,pass,mysqli,___,new
From: https://www.cnblogs.com/JcHome/p/18017896

相关文章

  • DVWA-File Upload(文件上传漏洞)
    FileUpload文件上传漏洞是通过上传文件功能,上传一些可执行的脚本文件,且服务器端没有对上传的文件进行严格的校验或者在服务器端没有对上传的文件进行安全策略的配置,导致文件能成功上传到服务器上,且能够解析执行。DVWA-FileUpload的级别:--low--medium--high......
  • DVWA-File inclusion(文件包含漏洞)
    FileInclusion,文件包含(漏洞),是指当服务器开启allow_url_include选项时,就可以通过php的某些特性函数(include(),require()和include_once(),require_once())利用url去动态包含文件,此时如果没有对文件来源进行严格审查,就会导致任意文件读取或者任意命令执行。PHP中包含文件函数介绍:Inc......
  • DVWA-Command Injection(命令注入)
    命令注入是通过提交含有恶意的服务器端可以执行命令,且这些命令能被服务器执行,从而能间接操作服务器。DVWA的CommandInjection级别分为:--low--medium--high--impossible--low级别看以下,正常的操作是输入IP地址,交由服务器进行ping操作,然后再将结果返回给......
  • kali学习笔记-05-DVWA XSS跨站脚本攻击
    kali学习笔记-05-DVWA XSS跨站脚本攻击KaliLinux网络安防一、反射型XSS攻击在OWASP的DVWA上,选中XSSreflected页面,在输入框内输入张三,页面反应正常。尝试输入一句script脚本。<script>alert('xss')</script>出现了如下的系统弹框,也就意味着后端服务器没有对特殊字符做......
  • centos搭建dvwa
    一、环境部署1、下载dvwa安装包文件备用2、安装apacheaptinstallapache2-y3、安装mysqlaptinstlallmariadbmariadb-server-y4、安装phpapt-yinstallphp7.0php-pearlibapache2-mod-php7.0php7.0-mysqlphp7.0-curlphp7.0-jsonphp7.0-cgiphp7.0-gd注意:安装......
  • Java21 + SpringBoot3集成easy-captcha实现验证码显示和登录校验
    目录前言相关技术简介easy-captcha实现步骤引入maven依赖定义实体类定义登录服务类定义登录控制器前端登录页面实现测试和验证总结附录使用Session缓存验证码前端登录页面实现代码前言近日心血来潮想做一个开源项目,目标是做一款可以适配多端、功能完备的模板工程,包含后台管理系......
  • podman configure insecure certificate registry【podman 设置非安全镜像仓库】
    预备条件dockerregistry仓库私搭并配置证书centos7.9部署harbor镜像仓库实践harbor部署入门指南Podman部署私有镜像仓库设置$vim/etc/hosts192.168.23.47registry.ghostwritten.com$vim/etc/containers/registries.conf...[[registry]]location="registry.ghos......
  • Base64Captcha 登录验证码
    CaptchaGitHub地址:github.com/dchest/captcha简介:Captcha是一个功能强大的验证码生成库,支持生成图片和音频验证码。它能够生成数字、字母、数字字母组合等各种类型的验证码,并且使用简单方便。Gin-UtilsGitHub地址:github.com/gin-contrib/gin-utils简介:Gin-Utils是一个针......
  • DVWA靶场之命令注入
    命令注入简介命令注入(CommandInjection,又叫操作系统命令注入为shell注入):指在开发需求中,需要引入对系统本地命令的支持来完成某些特定的功能。当未对输入参数进行严格过滤时,则有可能发生命令注入。原因:程序对输入与输出的控制不够严格,导致精心构造的命令输入在后台执行后产生......
  • django验证码插件 --- django-simple-captcha
    使用django-simple-captcha实现登录验证码: 第一步:安装pillow依赖pipinstallpillow  -ihttps://pypi.tuna.tsinghua.edu.cn/simple/ 第二步:安装django-simple-captchapipinstalldjango-simple-captcha -ihttps://pypi.tuna.tsinghua.edu.cn/simple/ 第三步:注......