简体   繁体   中英

How to run a large base64 encoded file via powershell

I have a powershell.ps1 script that I performed base64 encoding upon as below

$Base64 = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes('c:\path\to\powershell.ps1'));

Now I have stored this output to base64.txt file.

I tried to launch this script as below via CMD,

powershell.exe -EncodedCommand (Base64String)

But I ended up in the below error

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

I realized that the CMD is not taking the entire (Base64String). The full length of my (Base64String) is 11,133 characters. But CMD is accepting only 8160 characters.

Is there any way or workaround to run this base64 encoding?

Thanks in advance.

This worked for me ( myscript.ps1 contains the base64 encoded command):

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

Which is very similar to what you would do in Bash:

$ powershell -encodedcommand `cat myscript.ps1`

Obs: Addressing some comments, this is sometimes indeed needed. My particular use case was to do a reverse shell while dodging an AV on a windows machine that was detecting my plaintext shell code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM