【DVWA】19. Insecure CAPTCHA 不安全的验证码(全等级)

2024-03-14 05:12

本文主要是介绍【DVWA】19. Insecure CAPTCHA 不安全的验证码(全等级),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 1. Low
    • 1) 源码分析
    • 2)实操
  • 2. Medium
    • 1) 源码分析
    • 2)实操
  • 3. High
    • 1) 源码分析
    • 2)实操
  • 4. Impossible
    • 1) 源码分析

1. Low

1) 源码分析

<?phpif( 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 userecho "<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 matchif( $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 userecho "<pre>Password Changed.</pre>";}else {// Issue with the passwords matchingecho "<pre>Passwords did not match.</pre>";$hide_form = false;}((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}?>
  1. 首先,代码检查是否有名为"Change"的POST参数,并且"step"参数的值为1。这意味着该代码是用于处理提交更改密码表单的第一步请求。

  2. 代码将变量$hide_form设置为true。这个变量用于控制是否隐藏验证码表单。

  3. 代码获取输入的新密码和确认密码,并进行比较。如果两个密码不匹配,代码将输出一条错误消息,并将$hide_form设置为false,以便显示密码更改表单供用户重新尝试。

  4. 如果两个密码匹配,代码将调用recaptcha_check_answer函数来验证第三方提供的验证码。这里假设存在一个名为$_DVWA[‘recaptcha_private_key’]的变量用于存储私钥,并且用户在表单中提供了名为g-recaptcha-response的验证码响应。

  5. 如果验证码验证失败(即! r e s p ),代码会输出一条错误消息,并将 resp),代码会输出一条错误消息,并将 resp),代码会输出一条错误消息,并将hide_form设置为false,以便显示验证码表单供用户重新尝试。

  6. 如果验证码验证成功,代码将显示下一步的表单给用户确认密码更改。这个表单包含了一个隐藏的step字段,值为2,以及新密码和确认密码的隐藏字段。

  7. 如果用户点击了确认更改的按钮,代码将进行第二步的处理。

  8. 在第二步中,代码再次将变量$hide_form设置为true。

  9. 代码获取输入的新密码和确认密码,并进行比较。如果两个密码不匹配,代码将输出一条错误消息,并将$hide_form设置为false,以便显示密码更改表单供用户重新尝试。

  10. 如果两个密码匹配,代码将对新密码进行MySQL转义和md5哈希处理,并将密码更新到数据库中。

  11. 如果密码更改成功,代码将输出一条成功的消息。

  12. 如果两个密码不匹配,代码将输出一条失败的消息,并将$hide_form设置为false,以便显示密码更改表单供用户重新尝试。

可以在代码中看出,修改密码时对验证码的验证仅仅是验证了step的值是否为2
在这里插入图片描述

2)实操

由于本地环境配置的原因,此处验证码没有显示,但是我们本来就是要绕过验证码,因此不用管这里
在这里插入图片描述
若不做任何操作,会显示验证码错误
在这里插入图片描述
随后我们重新输入密码并进行抓包,得到的数据包如下

在这里插入图片描述
可以看到最后一行step=1,那这样的话肯定过不了验证码验证
于是我们发送到repeater中将step修改为2重新发包
在这里插入图片描述
可以看到密码修改成功
在这里插入图片描述

2. Medium

1) 源码分析

<?phpif( 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 userecho "<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 1if( !$_POST[ 'passed_captcha' ] ) {$html     .= "<pre><br />You have not passed the CAPTCHA.</pre>";$hide_form = false;return;}// Check to see if both password matchif( $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 userecho "<pre>Password Changed.</pre>";}else {// Issue with the passwords matchingecho "<pre>Passwords did not match.</pre>";$hide_form = false;}((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}?>

与Low相比多了一步验证,加了对参数passed_captcha的检查,如果为true,则认为已经通过了验证码检查

在这里插入图片描述

2)实操

可以尝试加上这个字段passed_captcha=true绕过,成功在这里插入图片描述

3. High

1) 源码分析

<?phpif( 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 userecho "<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();?>

只要g-recaptcha-response和请求头的HTTP_USER_AGENT是符合约定的就行
在这里插入图片描述

2)实操

抓包直接改成这两个值就行g-recaptcha-response=hidd3n_valu3,HTTP_USER_AGENT=reCAPTCHA
修改g-recaptcha-response参数以及User-Agent
在这里插入图片描述

4. Impossible

1) 源码分析

<?phpif( isset( $_POST[ 'Change' ] ) ) {// Check Anti-CSRF tokencheckToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );// Hide the CAPTCHA form$hide_form = true;// Get input$pass_new  = $_POST[ 'password_new' ];$pass_new  = stripslashes( $pass_new );$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 );$pass_conf = $_POST[ 'password_conf' ];$pass_conf = stripslashes( $pass_conf );$pass_conf = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $pass_conf ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));$pass_conf = md5( $pass_conf );$pass_curr = $_POST[ 'password_current' ];$pass_curr = stripslashes( $pass_curr );$pass_curr = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $pass_curr ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));$pass_curr = md5( $pass_curr );// 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 incorrectlyecho "<pre><br />The CAPTCHA was incorrect. Please try again.</pre>";$hide_form = false;}else {// Check that the current password is correct$data = $db->prepare( 'SELECT password FROM users WHERE user = (:user) AND password = (:password) LIMIT 1;' );$data->bindParam( ':user', dvwaCurrentUser(), PDO::PARAM_STR );$data->bindParam( ':password', $pass_curr, PDO::PARAM_STR );$data->execute();// Do both new password match and was the current password correct?if( ( $pass_new == $pass_conf) && ( $data->rowCount() == 1 ) ) {// Update the database$data = $db->prepare( 'UPDATE users SET password = (:password) WHERE user = (:user);' );$data->bindParam( ':password', $pass_new, PDO::PARAM_STR );$data->bindParam( ':user', dvwaCurrentUser(), PDO::PARAM_STR );$data->execute();// Feedback for the end user - success!echo "<pre>Password Changed.</pre>";}else {// Feedback for the end user - failed!echo "<pre>Either your current password is incorrect or the new passwords did not match.<br />Please try again.</pre>";$hide_form = false;}}
}// Generate Anti-CSRF token
generateSessionToken();?>

首先,代码检查是否有名为"Change"的POST参数。这意味着该代码是用于处理提交更改密码表单的请求。

然后,代码调用checkToken函数来验证防跨站请求伪造(Anti-CSRF)令牌。checkToken函数接受三个参数: R E Q U E S T [ ′ u s e r t o k e n ′ ] , _REQUEST['user_token'], REQUEST[usertoken]_SESSION[‘session_token’]和’index.php’。这里的目的是确保提交的请求是合法的,并且用户已经通过先前的身份验证。

代码将变量$hide_form设置为true。这个变量用于控制是否隐藏验证码表单。

代码获取输入的新密码,并对其进行处理。它首先从$_POST[‘password_new’]获取密码,然后使用stripslashes函数去除可能的反斜杠转义,接着使用mysqli_real_escape_string函数对密码进行MySQL转义,最后使用md5函数进行哈希处理。

代码获取确认密码,并对其进行与新密码相同的处理过程。

代码获取当前密码,并对其进行与新密码相同的处理过程。

代码调用recaptcha_check_answer函数来验证第三方提供的验证码。这里假设存在一个名为$_DVWA[‘recaptcha_private_key’]的变量用于存储私钥,并且用户在表单中提供了名为g-recaptcha-response的验证码响应。

如果验证码验证失败(即! r e s p ),代码会输出一条错误消息,并将 resp),代码会输出一条错误消息,并将 resp),代码会输出一条错误消息,并将hide_form设置为false,以便显示验证码表单供用户重新尝试。

如果验证码验证成功,代码将查询数据库以验证当前密码是否正确。它使用准备好的语句来选择users表中与当前用户和当前密码匹配的记录。如果查询返回一行结果(即$data->rowCount() == 1),则表示当前密码正确。

如果新密码与确认密码匹配并且当前密码正确,代码将更新数据库中的密码。它使用准备好的语句将新密码更新到与当前用户匹配的记录中。

如果密码更改成功,代码将输出一条成功的消息。

如果新密码与确认密码不匹配或当前密码不正确,代码将输出一条失败的消息,并将$hide_form设置为false,以便显示密码更改表单供用户重新尝试。

最后,代码调用generateSessionToken函数生成一个新的防跨站请求伪造(Anti-CSRF)令牌,以便在下一次请求中使用。

这篇关于【DVWA】19. Insecure CAPTCHA 不安全的验证码(全等级)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/807294

相关文章

19.手写Spring AOP

1.Spring AOP顶层设计 2.Spring AOP执行流程 下面是代码实现 3.在 application.properties中增加如下自定义配置: #托管的类扫描包路径#scanPackage=com.gupaoedu.vip.demotemplateRoot=layouts#切面表达式expression#pointCut=public .* com.gupaoedu

9 个 GraphQL 安全最佳实践

GraphQL 已被最大的平台采用 - Facebook、Twitter、Github、Pinterest、Walmart - 这些大公司不能在安全性上妥协。但是,尽管 GraphQL 可以成为您的 API 的非常安全的选项,但它并不是开箱即用的。事实恰恰相反:即使是最新手的黑客,所有大门都是敞开的。此外,GraphQL 有自己的一套注意事项,因此如果您来自 REST,您可能会错过一些重要步骤!

【网络安全的神秘世界】搭建dvwa靶场

🌝博客主页:泥菩萨 💖专栏:Linux探索之旅 | 网络安全的神秘世界 | 专接本 | 每天学会一个渗透测试工具 下载DVWA https://github.com/digininja/DVWA/blob/master/README.zh.md 安装DVWA 安装phpstudy https://editor.csdn.net/md/?articleId=1399043

数据库原理与安全复习笔记(未完待续)

1 概念 产生与发展:人工管理阶段 → \to → 文件系统阶段 → \to → 数据库系统阶段。 数据库系统特点:数据的管理者(DBMS);数据结构化;数据共享性高,冗余度低,易于扩充;数据独立性高。DBMS 对数据的控制功能:数据的安全性保护;数据的完整性检查;并发控制;数据库恢复。 数据库技术研究领域:数据库管理系统软件的研发;数据库设计;数据库理论。数据模型要素 数据结构:描述数据库

使用JWT进行安全通信

在现代Web应用中,安全通信是至关重要的。JSON Web Token(JWT)是一种流行的安全通信方式,它允许用户和服务器之间安全地传输信息。JWT是一种紧凑的、URL安全的表示方法,用于在两方之间传输信息。本文将详细介绍JWT的工作原理,并提供代码示例帮助新人理解和实现JWT。 什么是JWT? JWT是一种开放标准(RFC 7519),它定义了一种紧凑且自包含的方式,用于在各方之间以JSO

如何给文档设置密码?电脑文件安全加密的详细操作步骤(10种方法)

在数字化时代,电脑文件的安全和隐私至关重要。通过给电脑的文件或者文件夹设置密码和加密,可以有效保护你的重要文件不被未经授权的人员访问,特别是公司的重要岗位,一些特殊的机密文件,投标文件,资金文件等等,更应该注重文件日常使用安全性。下面将为你介绍10种电脑文件,文件夹加密的详细操作步骤,帮助你更好地保护你的电脑文件安全。 加密方式一、Windows系统内置加密(电脑自带的文件加密) 选中需要

安全科普:理解SSL(https)中的对称加密与非对称加密

今天刚好为站点的后台弄了下https,就来分享我了解的吧。 密码学最早可以追溯到古希腊罗马时代,那时的加密方法很简单:替换字母。 早期的密码学:   古希腊人用一种叫 Scytale 的工具加密。更快的工具是 transposition cipher—:只是把羊皮纸卷在一根圆木上,写下信息,羊皮纸展开后,这些信息就加密完成了。 虽然很容易被解密,但它确实是第一个在现实中应用加密的

为什么 C++ 允许不安全的代码(Bjarne Stroustrup)

为什么 C++ 允许不安全的代码? 也就是说,为什么 C++ 支持可以用来违反静态(编译时)类型安全规则的操作? 为了直接访问硬件(例如,把整数当作指向设备寄存器的指针)为了获取最佳的运行时效率和空间效率(例如,不检测访问数组元素的操作(是否越界),不检测访问对象的指针(是否有效))为了和 C 兼容 所以,当你并不需要以上三种特性时,最好避免有如瘟疫般的不安全代码: 不要用类型转换(cas

红队内网攻防渗透:内网渗透之内网对抗:横向移动篇Kerberos委派安全RBCD资源Operators组成员HTLMRelay结合

基于资源的约束委派(RBCD)是在Windows Server 2012中新加入的功能,与传统的约束委派相比,它不再需要域管理员权限去设置相关属性。RBCD把设置委派的权限赋予了机器自身,既机器自己可以决定谁可以被委派来控制我。也就是说机器自身可以直接在自己账户上配置msDS-AllowedToActOnBehalfOfOtherIdentity属性来设置RBCD。 所以核心就是谁或什么权限能修改

等保测评:全面保障信息系统安全的必要举措

等保测评(信息安全等级保护测评)是评估信息系统安全等级的重要过程,旨在确保信息系统能够抵御各种安全威胁,保障信息的机密性、完整性和可用性。以下是一篇关于等保测评的文章,内容清晰、分点表示,并参考了相关数字和信息。 一、引言 随着信息技术的快速发展,信息系统在各行各业中的应用越来越广泛,但同时也面临着日益严峻的安全威胁。为了保障信息系统的安全,我国实施了信息安全等级保护制度,要求对信息系统进行等