DVWA-Insecure CAPTCHA

admin 2023年1月12日02:06:27评论31 views字数 3842阅读12分48秒阅读模式

6.Insecure CAPTCHA

1.Insecure CAPTCHA(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
$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="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
$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);
}

?>

可以看到,服务器将改密操作分成了两步,第一步检查用户输入的验证码,验证通过后,服务器返回表单,第二步客户端提交post请求,服务器完成更改密码的操作。但是,这其中存在明显的逻辑漏洞,服务器仅仅通过检查Change、step 参数来判断用户是否已经输入了正确的验证码。

通过构造参数绕过验证过程的第一步

首先输入密码,点击Change按钮,抓包:

DVWA-Insecure CAPTCHA

(ps:因为没有翻墙,所以没能成功显示验证码,发送的请求包中也就没有recaptcha_challenge_field、recaptcha_response_field两个参数)

更改step参数为2绕过验证码:

DVWA-Insecure CAPTCHA

修改密码成功:

DVWA-Insecure CAPTCHA

2.Insecure CAPTCHA(Medium)

相关代码分析

DVWA-Insecure CAPTCHA

可以看到,Medium级别的代码在第二步验证时,参加了对参数passed_captcha的检查,如果参数值为true,则认为用户已经通过了验证码检查,然而用户依然可以通过伪造参数绕过验证,本质上来说,这与Low级别的验证没有任何区别。

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

抓到的包:

DVWA-Insecure CAPTCHA

更改之后的包:passed_captcha=true

DVWA-Insecure CAPTCHA

更改密码成功:

DVWA-Insecure CAPTCHA

3.Insecure CAPTCHA(High)

相关代码分析

DVWA-Insecure CAPTCHA

在High级别中, 去掉了逻辑漏洞的成因----step, 而且加入了防CSRF机制。

DVWA-Insecure CAPTCHA

漏洞利用

仔细审查代码, 可以看到服务器的验证逻辑是当参数 resp(这里是指谷歌验证码返回的验证结果)是false,并且参数recaptcha_response_field不等于hidd3n_valu3(或者http包头的User-Agent参数不等于reCAPTCHA)时,就认为验证码输入错误,反之则认为已经通过了验证码的检查。

弄清楚了逻辑, 存在的逻辑漏洞就是 || (异或条件), 只要我们抓包修改一下参数值:

recaptcha_response_field=hidd3n_valu3

User-Agent: reCAPTCHA

再提交就可以绕过了:

先抓包

DVWA-Insecure CAPTCHA

修改后的包

DVWA-Insecure CAPTCHA

由于有墙,未能复现成功

DVWA-Insecure CAPTCHA

4.Insecure CAPTCHA(Impossible)

相关代码分析

DVWA-Insecure CAPTCHA

可以看到,Impossible级别的代码增加了Anti-CSRF token 机制防御CSRF攻击

DVWA-Insecure CAPTCHA

利用PDO技术防护sql注入,验证过程终于不再分成两部分了,验证码无法绕过,同时要求用户输入之前的密码,进一步加强了身份认证。

文笔生疏,措辞浅薄,望各位大佬不吝赐教,万分感谢。

免责声明:由于传播或利用此文所提供的信息、技术或方法而造成的任何直接或间接的后果及损失,均由使用者本人负责, 文章作者不为此承担任何责任。

转载声明:儒道易行 拥有对此文章的修改和解释权,如欲转载或传播此文章,必须保证此文章的完整性,包括版权声明等全部内容。未经作者允许,不得任意修改或者增减此文章的内容,不得以任何方式将其用于商业目的。


博客:

https://rdyx0.github.io/

先知社区:

https://xz.aliyun.com/u/37846

SecIN:

https://www.sec-in.com/author/3097

CSDN:

https://blog.csdn.net/weixin_48899364?type=blog

公众号:

https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg5NTU2NjA1Mw==&action=getalbum&album_id=1696286248027357190&scene=173&from_msgid=2247485408&from_itemidx=1&count=3&nolastread=1#wechat_redirect

FreeBuf:

https://www.freebuf.com/author/%E5%9B%BD%E6%9C%8D%E6%9C%80%E5%BC%BA%E6%B8%97%E9%80%8F%E6%8E%8C%E6%8E%A7%E8%80%85



原文始发于微信公众号(儒道易行):DVWA-Insecure CAPTCHA

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年1月12日02:06:27
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   DVWA-Insecure CAPTCHAhttps://cn-sec.com/archives/1514384.html

发表评论

匿名网友 填写信息