• XSS.stack #1 – первый литературный журнал от юзеров форума

The power of PowerShell: Transform a binary to base64

MoreTrust

HDD-drive
Пользователь
Регистрация
26.12.2019
Сообщения
20
Реакции
12
Several times there is a need to "carry" an executable inside out code.
There several methods to do this.
One of them is to transform the binary code into a base64 encoding.
I provide this action in the following PowerShell script, and for the competence, I also presents the way to get the base64 string and put it in back in a file in a binary format
Код:
# From EXE To Base64
$EXE_Path = "c:\windows\system32\cmd.exe";
$Base64_Code = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes($EXE_Path));
 
# now $Base64_Code is something like this: "...AMAAAAEAAA...";
 
# From Base64 to EXE
$EXE_Path2 = "c:\mypath\MyCmd.exe";
[byte[]]$Bytes = [convert]::FromBase64String($Base64_Code);
[System.IO.File]::WriteAllBytes($EXE_Path2,$Bytes);
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх