我正在嘗試按照某些 xp_cmdshell 代碼執行:
declare @url varchar(250) = 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=439d4b804bc8187953eb36d2a8c26a02'
declare @c varchar(1000) = N'powershell.exe -noprofile -executionpolicy bypass '
+ N'-command (Invoke-WebRequest -Uri '''+@url+'''-UseBasicParsing).content'
print @c
exec xp_cmdshell @c
但這是我得到的錯誤:
The string is missing the terminator: '.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
'appid' is not recognized as an internal or external command,
operable program or batch file
當我嘗試在 powershell 中執行相同的操作時,我得到了預期的響應(見圖)
(Invoke-WebRequest -Uri 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=439d4b804bc8187953eb36d2a8c26a02'-UseBasicParsing).content
xp_cmdshell 的預期輸出應該是一個 json
該錯誤消息暗示您的命令行是通過 執行的cmd.exe
,其中&
是一個元字符。
要使用&
逐字-這是你的意圖-無論它的網址&
是部分必須在封閉"..."
(cmd.exe
只識別雙引號),或者你必須^
-escape的&
:
declare @url varchar(250) = 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk^&appid=439d4b804bc8187953eb36d2a8c26a02'
-- ...
當cmd.exe
解析命令行,它識別^&
作為逃脫 &
被逐字使用和刪除^
,轉義字符,傳遞參數上之前。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句