暴力破解
一、前言
暴力破解:攻擊者可以利用字典不斷進行列舉,破解使用者的賬號名和密碼。
常用的暴力破解工具:burpsuite、hydra等。
二、DVWA-暴力破解
以DVWA的brute force為例**
1、Low
程式碼如下:
<?php
if( isset( $_GET[ 'Login' ] ) ) {
// Get username
$user = $_GET[ 'username' ];
// Get password
$pass = $_GET[ 'password' ];
$pass = md5( $pass );
// Check the 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
echo "<pre><br />Username and/or password incorrect.</pre>";
}
((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
?>
檢視原始碼,只是驗證了引數Login是否被設定,並沒有任何的防爆破機制,而且username和password以get方式傳遞,然後傳入資料庫中進行比較,沒有做任何過濾,存在sql注入,並且可以直接進行爆破。
萬能密碼:
admin'or '1'='1
admin' -- -
admin' #
2、Medium
<?php
if( isset( $_GET[ 'Login' ] ) ) {
// Sanitise username input
$user = $_GET[ 'username' ];
$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 = ((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 the 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( 2 );
echo "<pre><br />Username and/or password incorrect.</pre>";
}
((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
?>
mysqli_real_escape_string()
:函式轉義在 SQL 語句中使用的字串中的特殊字元。Medium級別的程式碼使用了這個函式去防止sql注入時候SQL語句中的特殊字元,但是依然沒有對暴力破解進行限制。
3、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();
?>
首先使用了mysqli_real_escape_string()函式對sql注入進行防禦;而且,每次我們傳送登入請求時,都會在請求中加入一個user_token,並且登入一次,user_token更換一次。
爆破過程如下:
①將登入頁面請求包傳送到Intruder模組,按如下配置
②設定跟隨重定向
③爆破,我們把密碼設定為引數一,user_token設定為引數二,就可以進行爆破了。
4、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級別的程式碼加入了可靠的防爆破機制,當檢測到頻繁的錯誤登入後,系統會將賬戶鎖定,爆破也就無法繼續;
同時採用了更為安全的PDO(PHP Data Object)機制防禦sql注入,這是因為不能使用PDO擴充套件本身執行任何資料庫操作,而sql注入的關鍵就是通過破壞sql語句結構執行惡意的sql命令。
三、驗證碼暴力破解
關於驗證碼問題,可以先看另外一篇靶機練習的部落格驗證碼暴力破解
改天會專門寫一篇關於驗證碼的文章。
相關文章
- 什麼是暴力破解?暴力破解的方法有哪些?
- 暴力破解測試
- Linux防止SSH暴力破解Linux
- 迭代暴力破解域名工具
- 暴力破解zip加密檔案加密
- web類靶機暴力破解Web
- DVWA-Brute Force暴力破解
- dvwa-暴力破解(low-high)
- burpsuite暴力破解之四種方式UI
- 暴力破解-基於Pikachu的學習
- Spring Boot如何防暴力破解攻擊?Spring Boot
- 使用python暴力破解mysql資料庫PythonMySql資料庫
- pikachu 基於表單的暴力破解(一)
- burpsuite暴力破解的四種攻擊方式UI
- Centos7使用DenyHosts防止ssh暴力破解CentOS
- Wireshark駭客發現之旅(4)——暴力破解
- DNS暴力破解工具Fierce常用命令DNS
- Linux應急響應(一):SSH暴力破解Linux
- fail2ban防暴力破解介紹使用AI
- 普通網站防暴力破解的新設計網站
- Python攻防-暴力破解附近區域網WIFI密碼PythonWiFi密碼
- Linux裝置淪為礦機,黑客暴力破解SSHLinux黑客
- 使用 fail2ban 防 linux ssh 被暴力破解AILinux
- 某學院存在資訊洩露及暴力破解漏洞
- 用生成模型為自己生成密碼,無懼暴力破解模型密碼
- 用python暴力破解rar加密檔案(經過測試)Python加密
- 如何通過Python暴力破解網站登陸密碼Python網站密碼
- Python暴力破解網站登入密碼(帶token驗證)Python網站密碼
- 小白學習CTF第十二天-web安全暴力破解Web
- 安全乾貨,使用fail2ban避免ssh被暴力破解AI
- Linux 修改預設SSH埠 22,避免被暴力破解密碼Linux解密密碼
- 【安全】【測試思路】基於Burpsuite工具中的intruder執行暴力破解UI
- Linux挖礦木馬WorkMiner集中爆發,利用SSH暴力破解傳播Linux
- 【超硬核】- python 3分鐘實現暴力破解wifi密碼EXE應用PythonWiFi密碼
- DVWA靶機通關係列--1.Brute Force(暴力破解)(解題思路+審計分析)
- Emlog漏洞————Emlog部落格系統後臺無視驗證碼暴力破解實現登入
- Coremail2022Q4郵件安全報告:暴力破解驟降,盜號問題有所緩解?REMAI
- 因未啟用2FA被暴力破解,駭客接管谷歌子公司Mandiant的X賬戶谷歌