Malicious Steganography

Stux
5 min readJul 15, 2022

--

[!] English — First block in English.

[!] Português — Segundo bloco em português.

[English]

Hello Hackers! I’m Stux and today we’re going to talk about Malicious Steganography! Have you ever imagined how awesome it would be if we could store a malicious payload or a script in an image?

And besides storing the malicious payload/script inside that image, we could consume the payload/script directly in the image…

Yes, my friend, that’s exactly what I’m going to teach you today!

It is important to know that we will be able to inject any PowerShell script into an image. To inject a malicious powershell script into an image, we will use the script called Invoke-PSImage.

Invoke-PSImage encodes a PowerShell script into a PNG image and generates a single line of code to run the script. The original image is almost perfect and it is almost impossible to detect the script embedded in the image.

Once the charge is built into the image, 4 bits of 2 color values ​​in each pixel are used to hold the charge. Image quality will be lower, but decent. Each pixel in the image is used to contain one byte of script, so the image would need to have at least as many pixels as bytes in the script. For example, Invoke-Mimikatz fits a 1920×1200 image.

Come on!

For this example, I will use a simple Script that will print in the console “Stux Steganography Malicious”, but you, for a pentest for example, can use Invoke-Mimikatz.ps1.

I’ll use this image as an example:

Open the powershell in the directory where you have the PSImage script, let’s inject our Script in the image!

-Script: PowerShell script that we want to inject into the image.

-Out: Output of the process, image with the injected script.

Right after the command, PSImage will generate a oneliner to run on the victim, this oneliner will consume the Script inside the image.

Let’s compare the images:

Green — Original Image;
Red — Image with Script;

In the victim, after transferring the image to the machine, we will use the generated oneliner.

Success! Script successfully loaded via malicious image.

Remembering that, you can inject other scripts: Mimikatz, PowerView, PowerUp

Thank you very much for following me here, my contacts are at the end of the article.

[Português]

Olá Hackers!

Eu sou o Stux e hoje vamos falar sobre Esteganografia Maliciosa!

Você já imaginou como seria incrível se pudéssemos armazenar uma carga maliciosa ou um script em uma imagem? E além de armazenar o payload/script malicioso dentro dessa imagem, poderíamos consumir o payload/script diretamente na imagem…

Sim meu hacker, é exatamente isso que vou te ensinar hoje!

É importante saber que poderemos injetar qualquer script PowerShell em uma imagem. Para injetar um script Powershell malicioso em uma imagem, usaremos o script chamado Invoke-PSImage.

O Invoke-PSImage codifica um script do PowerShell em uma imagem PNG e gera uma única linha de código para executar o script. A imagem original é quase perfeita e é quase impossível detectar o script embutido na imagem.

Uma vez que a carga é embutida na imagem, 4 bits de 2 valores de cor em cada pixel são usados ​​para manter a carga. A qualidade da imagem será menor, mas decente. Cada pixel na imagem é usado para conter um byte de script, portanto, a imagem precisaria ter pelo menos tantos pixels quanto bytes no script. Por exemplo, Invoke-Mimikatz necessita uma imagem de 1920×1200.

Vamos lá!

Para este exemplo, usarei um Script simples que imprimirá no console “Stux Esteganografia Maliciosa”.

Usarei a seguinte imagem para injetar o Script:

Abra o powershell no diretório onde está o script PSImage, vamos injetar nosso Script na imagem!

-Script: Script do PowerShell que queremos injetar na imagem.

-Out: Saída para a imagem com o script injetado.

Logo após o comando, o PSImage irá gerar um oneliner para rodar na vítima, este oneliner consumirá o Script dentro da imagem.

Vamos comparar as imagens:

Verde — Imagem Original;
Vermelho — Imagem com o Script injetado;

Na vítima, após transferir a imagem para a máquina, utilizaremos o oneliner gerado.

Sucesso! Script carregado com sucesso através da imagem maliciosa.

Lembrando que, você pode injetar outros scripts como: Mimikatz, PowerView, PowerUp…

Muito obrigado por ter acompanhado até aqui! Sinta-se a vontade para entrar em contato comigo através das minhas redes sociais ou para conectar-se comigo no LinkedIn!

--

--