DVWA 暴力破解-High

地球胖头鱼 2020-10-12
Web安全 发布于 2020-10-12 14:37:46 阅读 34 评论 0

DVWA 暴力破解-High

提交登录请求,抓包

还是先测试能否登陆、然后抓包。

发给Intruder模块进行处理

把数据包发送给 发给Intruder模块进行处理

填写payload进行爆破

爆破失败,状态码全是302,长度都一致,说明之前单纯的思路已经不能解决问题了。仔细观察,可以发现多了一个字段,就是user_token。

user_token主要有两个作用:

  • 防止表单重复提交
  • 用来作身份验证,每次的请求中的user_token都不一样,会发生变化。强行解释一波就是因为有uesr_token的限制,故每次爆破就不只是那用户名和密码进行枚举就行了,一旦你的身份没有通过验证,就算给你正确的密码一样也会登录失败。

返回Intruder模块,选择新的攻击模式

攻击模式换成pitchfork,并且将user_token的值加上$标签

Payload1和payload2可以不动,将payload3的模式修改成“Recursive grep”即可

在Options里,找到Grep-Extract,添加user_token

还要记住此user_token的值:90c9a29a5f9d6e449e902914acae3ab9 这个token值需要根据自己搭建DVWA环境的访问页面来查看。

回到payloads下,给payload3添加初始值

开始爆破,找长度特殊的,得到用户名和密码,然后手工登录验证

总结一下

上次发的Low基本和Medium级别这俩个相对来说都很简单,但是High模式这个就比较困难了,具体还是要看代码:

<?php 

if( isset( $_GET[ 'Login' ] ) ) { 
// Check Anti-CSRF token 
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' ); 

// Sanitise username input 
$user = $_GET[ 'username' ]; 
$user = stripslashes( $user ); 
$user = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $user ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : "")); 

// Sanitise password input 
$pass = $_GET[ 'password' ]; 
$pass = stripslashes( $pass ); 
$pass = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $pass ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : "")); 
$pass = md5( $pass ); 

// Check database 
$query  = "SELECT * FROM `users` WHERE user = '$user' AND password = '$pass';"; 
$result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' ); 

if( $result && mysqli_num_rows( $result ) == 1 ) { 
// Get users details 
$row    = mysqli_fetch_assoc( $result ); 
$avatar = $row["avatar"]; 

// Login successful 
echo "<p>Welcome to the password protected area {$user}</p>"; 
echo "<img src=\"{$avatar}\" />"; 
} 
else { 
// Login failed 
sleep( rand( 0, 3 ) ); 
echo "<pre><br />Username and/or password incorrect.</pre>"; 
} 

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

// Generate Anti-CSRF token 
generateSessionToken(); 

?>

High级别的代码使用了Anti-CSRF token来抵御CSRF的攻击,使用了stripslashes函数和mysqli_real_esacpe_string来抵御SQL注入和XSS的攻击。
由于使用了Anti-CSRF token,每次服务器返回的登陆页面中都会包含一个随机的user_token的值,用户每次登录时都要将user_token一起提交。服务器收到请求后,会优先做token的检查,就算用户名密码正确,一样会登录失败。所以我们在暴力破解的时候就需要加上这个token这个选项一次性爆破三个字段
这样我们才会有机会把真正的密码破解出来。

最后来看看impossible级别的源代码

<?php
if( isset( $_POST[ 'Login' ] ) && isset ($_POST['username']) && isset ($_POST['password']) ) {
// Check Anti-CSRF token   checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
// Sanitise username input
$user = $_POST[ 'username' ];
$user = stripslashes( $user );
$user = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $user ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
// Sanitise password input
$pass = $_POST[ 'password' ];
$pass = stripslashes( $pass );
$pass = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $pass ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
$pass = md5( $pass );
// Default values
$total_failed_login = 3;
$lockout_time       = 15;
$account_locked     = false;
// Check the database (Check user information)
$data = $db->prepare( 'SELECT failed_login, last_login FROM users WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
$row = $data->fetch();
// Check to see if the user has been locked out.
if( ( $data->rowCount() == 1 ) && ( $row[ 'failed_login' ] >= $total_failed_login ) )  {
// User locked out.  Note, using this method would allow for user enumeration!
//echo "<pre><br />This account has been locked due to too many incorrect logins.</pre>";
// Calculate when the user would be allowed to login again
$last_login = strtotime( $row[ 'last_login' ] );
$timeout    = $last_login + ($lockout_time * 60);
$timenow    = time();
/*
print "The last login was: " . date ("h:i:s", $last_login) . "<br />";
print "The timenow is: " . date ("h:i:s", $timenow) . "<br />";
print "The timeout is: " . date ("h:i:s", $timeout) . "<br />";
*/
// Check to see if enough time has passed, if it hasn't locked the account
if( $timenow < $timeout ) {
$account_locked = true;
// print "The account is locked<br />";
}
}
// Check the database (if username matches the password)
$data = $db->prepare( 'SELECT * FROM users WHERE user = (:user) AND password = (:password) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR);
$data->bindParam( ':password', $pass, PDO::PARAM_STR );
$data->execute();
$row = $data->fetch();
// If its a valid login...
if( ( $data->rowCount() == 1 ) && ( $account_locked == false ) ) {
// Get users details
$avatar       = $row[ 'avatar' ];
$failed_login = $row[ 'failed_login' ];
$last_login   = $row[ 'last_login' ];
// Login successful
echo "<p>Welcome to the password protected area <em>{$user}</em></p>";
echo "<img src=\"{$avatar}\" />";
// Had the account been locked out since last login?
if( $failed_login >= $total_failed_login ) {
echo "<p><em>Warning</em>: Someone might of been brute forcing your account.</p>";
echo "<p>Number of login attempts: <em>{$failed_login}</em>.<br />Last login attempt was at: <em>${last_login}</em>.</p>";
}
// Reset bad login count
$data = $db->prepare( 'UPDATE users SET failed_login = "0" WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
} else {
// Login failed
sleep( rand( 2, 4 ) );
// Give the user some feedback
echo "<pre><br />Username and/or password incorrect.<br /><br/>Alternative, the account has been locked because of too many failed logins.<br />If this is the case, <em>please try again in {$lockout_time} minutes</em>.</pre>";
// Update bad login count
$data = $db->prepare( 'UPDATE users SET failed_login = (failed_login + 1) WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
}
// Set the last login time
$data = $db->prepare( 'UPDATE users SET last_login = now() WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
}
// Generate Anti-CSRF token
generateSessionToken();
?>

这个级别如果想要暴力破解基本是不可能了,在impossible级别中调用大量函数对安全性进行加固。在High级别和Impossible级别上对用户的登录次数都添加了限制,当用户登录失败达到三次的时候,他会自动锁定账号15秒,这就是为什么级别约高的时候暴力破解使用时间越长的原因。除了限制登录失败错误时间限制,同时采用了更为安全的PDO(PHP Data Object)机制防御sql注入,所以才更安全,我没有尝试对impossible级别进行爆破的原因是我知道肯定没戏,不浪费时间了。还有一种比这个级别更高就是添加验证码虽然现在验证码有的也可以破解,但是随着技术的发展没有绝对的安全,但安全级别正在一步步增强。

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
地球胖头鱼
未填写
  • 作者发布文章65
  • 作者收获粉丝1
  • 作者收到点赞0
  • 所有文章被收藏了0
  • 博客总访问量排行第7
  • 博客总访问量3495(每日更新)
查看所有博文