如何通过powershell运行大型base64编码文件



我有一个powershell.ps1脚本,我对它进行了base64编码,如下所示

$Base64 = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes('c:pathtopowershell.ps1'));

现在我已经将这个输出存储到base64.txt文件中。

我尝试通过CMD,启动这个脚本如下

powershell.exe -EncodedCommand (Base64String)

但我最终出现了以下错误

Cannot process the command because the value specified with -EncodedCommand is not properly encoded. The value must be Base64 encoded.

我意识到CMD并没有占用整个(Base64String(。我的(Base64String(的全长为11133个字符。但是CMD只接受8160个字符。

是否有任何方法或解决方法来运行此base64编码?

提前谢谢。

这对我有效(myscript.ps1包含base64编码的命令(:

powershell -encodedcommand (Get-Content 'myscript.ps1' -Raw)

这与你在Bash:中所做的非常相似

$ powershell -encodedcommand `cat myscript.ps1`

观察:针对一些评论,有时确实需要这样做。我的特殊用例是在windows机器上躲避检测到我的纯文本shell代码的AV时进行反向shell。

最新更新