This guide walks you through resolving the reCAPTCHA vulnerability in DVWA by properly configuring the reCAPTCHA keys within a Dockerized environment.
DVWA (Damn Vulnerable Web Application) is an intentionally vulnerable PHP/MySQL application for testing web security tools and techniques. By default, the reCAPTCHA fields in the configuration file are left empty, which prevents certain features (e.g., CAPTCHA on login) from functioning correctly. This guide demonstrates how to fix that by integrating Google reCAPTCHA.
To perform this check, your Kali machine must have internet access.
- Visit: https://www.google.com/recaptcha/admin/create
- Label: Choose a descriptive name (e.g.,
DVWA Local Test) - reCAPTCHA Type: Select Challenge v2 β "I'm not a robot" Checkbox
- Domains: Add
localhost - Accept Terms of Service and submit.
- Copy the Site Key (public) and Secret Key (private).
-
Find the running container ID:
docker ps
-
Access the container:
docker exec -it <container_id> /bin/bash
Inside the container, run:
grep 'recaptcha' /var/www/html/config/config.inc.phpYou will likely see:
$_DVWA[ 'recaptcha_public_key' ] = '';
$_DVWA[ 'recaptcha_private_key' ] = '';Still inside the container, run:
sed -i "s|\$_DVWA\[ 'recaptcha_public_key' \] = ''|\$_DVWA[ 'recaptcha_public_key' ] = 'YOUR_PUBLIC_KEY'|g" /var/www/html/config/config.inc.php
sed -i "s|\$_DVWA\[ 'recaptcha_private_key' \] = ''|\$_DVWA[ 'recaptcha_private_key' ] = 'YOUR_PRIVATE_KEY'|g" /var/www/html/config/config.inc.php
β οΈ ReplaceYOUR_PUBLIC_KEYandYOUR_PRIVATE_KEYwith the actual values you received from Google.
Re-run the earlier check to confirm the keys are updated:
grep 'recaptcha' /var/www/html/config/config.inc.php
-
Find the container port:
docker port <container_id>
-
Open the browser and navigate to:
http://localhost:<port>
Click to Setup DVWA β Create / Reset Database.
8. Login with Default Credentials - http://localhost:{PORT}/vulnerabilities/captcha/
Username: admin
Password: password
The login or reset DB page will now show the "I'm not a robot" reCAPTCHA checkbox, indicating successful integration.
To bypass SSL verification errors during local testing, replace the default reCAPTCHA library file with a modified one that disables SSL checks.
Create a new file on your Desktop named recaptchalib.php and paste the following code:
<?php
// new php7 captcha v2 implementation with SSL verification disabled for local/test environments.
function recaptcha_check_answer($key, $response){
return CheckCaptcha($key, $response);
}
function CheckCaptcha($key, $response) {
try {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$dat = array(
'secret' => $key,
'response' => urlencode($response),
'remoteip' => urlencode($_SERVER['REMOTE_ADDR'])
);
$opt = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($dat)
),
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false
)
);
$context = stream_context_create($opt);
$result = file_get_contents($url, false, $context);
return json_decode($result)->success;
} catch (Exception $e) {
return null;
}
}
function recaptcha_get_html($pubKey){
return "
<script src='https://www.google.com/recaptcha/api.js'></script>
<br /> <div class='g-recaptcha' data-theme='dark' data-sitekey='" . $pubKey . "'></div>
";
}
?>
Use the following command to copy it to the appropriate location inside your running DVWA container:
docker cp ~/Desktop/recaptchalib.php <container_id>:/var/www/html/external/recaptcha/recaptchalib.phpπ Replace
<container_id>with your actual Docker container ID (e.g.,6b7b450b918e).
To apply the changes, restart the container:
docker restart <container_id>This ensures Apache reloads the updated recaptchalib.php file with SSL verification disabled.
For a full video walkthrough, check out this YouTube tutorial:
π https://www.youtube.com/watch?v=WkyDxNJkgQ4
β Your DVWA now includes working reCAPTCHA validation to simulate modern security features. β Your DVWA instance is now configured with reCAPTCHA and SSL-free validation for development and testing purposes.


