HTTP Headers Redirect
This lab demonstrates open redirect vulnerabilities that occur when applications trust HTTP headers like Referer, X-Forwarded-For, or custom headers for redirect functionality.
Objective: Test header-based redirects and understand how HTTP headers can be exploited for open redirect attacks.
// Check various headers that might contain redirect URLs
if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
$redirect_url = $_SERVER['HTTP_REFERER'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$redirect_url = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_GET['return_url'])) {
$redirect_url = $_GET['return_url'];
}
if (!empty($redirect_url)) {
// Vulnerable: Using header values without validation
header("Location: " . $redirect_url);
exit();
}
This form uses the return_url parameter. To test header-based redirects, use tools like curl or browser developer tools to modify headers.
HTTP_REFERER:
Not set
X-Forwarded-For:
Not set
User-Agent:
Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko;...
Use these methods to test the vulnerability:
curl -H "Referer: https://evil.com" "http://localhost/redirect/2.php"
curl -H "X-Forwarded-For: https://evil.com" "http://localhost/redirect/2.php"
?return_url=https://evil.com