我需要通过一个简单的testing案例来帮助您,通过PowerShell执行CLI命令,这已经在Base64中进行了编码。
假设Get-ChildItem
已经预先转换为Base64stringR2V0LUNoaWxkSXRlbQ==
。
进一步假设我有一个DOS CLI实例打开,我想testing在powershell中执行此string:
C:>\ powershell.exe -enc R2V0LUNoaWxkSXRlbQ==
但是,我收到以下错误:
The term '???????' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:8 *??????? <<<< + CategoryInfo :ObjectNotFound: (???????:String) [], CommandNotFoundException + FullyQualifiedErrorID: CommandNotFoundException
我知道有一种方法可以引入variables的使用,甚至包括编码过程本身。 但是我想知道的是,这种方法是否可以挽救? 我可能会做错什么? 我在Win7中运行PS版本2.0。
如果必须进行编码,请使用以下命令获取Base64string:
[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes('Get-ChildItem'))
尝试这个工作对我来说:
powershell.exe -encodedCommand RwBlAHQALQBDAGgAaQBsAGQASQB0AGUAbQA=
要添加到@ SomethingElse的答案,您的Base64string不起作用,和他们的Base64string,确实工作,之间的区别是原始string的字符编码。
它需要是UTF-16-LE,然后转换为Base64才能使用PowerShell,并将其视为UTF8 /纯ASCII。
# Your version, with 1-byte-per-character encoding: PS> [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('Get-ChildItem')) R2V0LUNoaWxkSXRlbQ== # Working version, with 2-bytes-per-character encoding: PS> [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes('Get-ChildItem')) RwBlAHQALQBDAGgAaQBsAGQASQB0AGUAbQA=