powershell -enc参数无法解码base64编码payload的解决方案

powershell的-enc参数允许传入一个base64编码过的powershell脚本字符串作为参数来执行该powershell脚本,该方法常被用于绕过杀毒软件的主动防御机制。

今天下午在做一个后门程序时,通过在线base64编码网站编码的字符串竟然没法被powershell的-enc参数解析,解析时全是乱码,通过查找资料终于解决了这个问题

故将这个问题记录下来以备后续使用

方法引用自:http://www.pstips.net/question/5827.html

可以使用如下脚本,对所需powershell脚本进行编码,所得字符串可以被powershell的-enc参数解析

$fileContent = “所要编码的脚本”
$bytes = [System.Text.Encoding]::Unicode.GetBytes($fileContent)
$encodedCommand = [Convert]::ToBase64String($bytes)
echo $encodedCommand

编码后的脚本可以通过如下命令解析执行

powershell -enc $encodedCommand
原文地址:https://www.cnblogs.com/zlgxzswjy/p/9275818.html