DVWA靶场之十六:未验证的重定向漏洞(Open HTTP Redirect)
DVWA靶场之十六:未验证的重定向漏洞(Open HTTP Redirect)
当 Web 应用程序接受不受信任的输入时,可能会发生未经验证的重定向和转发,这可能导致 Web 应用程序将请求重定向到包含在不受信任输入中的 URL。通过将不受信任的 URL 输入修改为恶意网站,攻击者可以成功发起网络钓鱼诈骗并窃取用户凭据。
如上所述,这种攻击的常见用途是创建一个 URL,该 URL 最初指向真实网站,然后重定向受害者到攻击者控制的网站。该网站可能是目标登录页面的克隆版本以窃取凭据,也可能是请求信用卡信息以支付目标网站上的服务费用,或者只是一个充满广告的垃圾页面。
目标:
重定向页面,将用户从 DVWA 网站移出或移至网站上与预期不同的页面。
1. Low:直接重定向
<?phpif (array_key_exists ("redirect", $_GET) && $_GET['redirect'] != "") {header ("location: " . $_GET['redirect']);exit;
}http_response_code (500);
?>
<p>Missing redirect target.</p>
<?php
exit;
?>
将 redirect
参数作为 location的值。可以重定向到任何网站:
比如127.0.0.1/vulnerabilities/open_redirect/source/low.php?redirect=https://www.baidu.com
就可以重定向到百度
2. Medium:过滤了协议名
<?phpif (array_key_exists ("redirect", $_GET) && $_GET['redirect'] != "") {if (preg_match ("/http:\/\/|https:\/\//i", $_GET['redirect'])) {http_response_code (500);?><p>Absolute URLs not allowed.</p><?phpexit;} else {header ("location: " . $_GET['redirect']);exit;}
}http_response_code (500);
?>
<p>Missing redirect target.</p>
<?php
exit;
?>
意义不大,去掉协议名字即可。
比如127.0.0.1/vulnerabilities/open_redirect/source/medium.php?redirect=//www.baidu.com
3. High:必须包含子串
<?phpif (array_key_exists ("redirect", $_GET) && $_GET['redirect'] != "") {if (strpos($_GET['redirect'], "info.php") !== false) {header ("location: " . $_GET['redirect']);exit;} else {http_response_code (500);?><p>You can only redirect to the info page.</p><?phpexit;}
}http_response_code (500);
?>
<p>Missing redirect target.</p>
<?php
exit;
?>
只允许重定向到包含 “info.php
” 的路径
要简洁地绕过此限制,只需附加一个无效参数即可。原URL中的 info.php 会被新参数截断,从而实现跳转:
http://127.0.0.1/vulnerabilities/open_redirect/source/high.php?redirect=https://www.baidu.com?a=info.php
4. impossible 白名单
<?php$target = "";if (array_key_exists ("redirect", $_GET) && is_numeric($_GET['redirect'])) {switch (intval ($_GET['redirect'])) {case 1:$target = "info.php?id=1";break;case 2:$target = "info.php?id=2";break;case 99:$target = "https://digi.ninja";break;}if ($target != "") {header ("location: " . $target);exit;} else {?>Unknown redirect target.<?phpexit;}
}?>
Missing redirect target.
只接受数字参数,完全避免字符串注入。这一等级直接判断目标是 info.php?id=1
或者 info.php?id=2
或者 info.php?id=99
,其他一概拒绝。