Circumventing CAPTCHA
In this step, we will learn how to circumvent CAPTCHA validation by exploiting vulnerabilities in the application's code or logic.
Consider a web application that implements a two-step process for changing a user's password:
- Step 1: The user enters the new password, confirms it, and solves the CAPTCHA challenge.
- Step 2: The user confirms the password change.
The application's code might look like this:
<?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
// ... (code omitted for brevity)
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>";
}
}
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 if passwords match
if ($pass_new == $pass_conf) {
// Update database
// ... (code omitted for brevity)
}
}
?>
In this code, we can observe that in step 2, the application does not validate the CAPTCHA again. This allows an attacker to bypass the CAPTCHA validation by directly submitting the request with step=2
.
To demonstrate this, follow these steps:
- Open your web browser and navigate to the application's "Change Password" page.
- Enter the new password you want to set in the "New Password" and "Confirm Password" fields.
- Right-click on the page and select "Inspect Element" or "Inspect" to open the browser's developer tools.
- Go to the "Network" tab and filter for the POST request made when you click the "Change" button.
- Right-click on the POST request and select "Edit and Resend" or a similar option (depending on your browser).
- In the request body, change the
step
parameter from 1
to 2
.
- Click the "Send" button to submit the modified request.
You should now see a message indicating that the password has been successfully changed, even though you did not solve the CAPTCHA challenge.
## No code or commands are required for this step.