My Authors
Read all threads
THREAD for beginning malware/SOC analysts
When analyzing interpreted languages like PowerShell, JavaScript, VBA/VBS, there are some handy shortcuts to dealing with obfuscated code. (NOTE: Always do this kind of analysis in a sandbox VM off of your corporate network.)
Let's use this PowerShell script as an example (raw code on the right). The code is triggered with an obfuscated 'IEX' command that is reconstructed from a predictable PowerShell environment variable, $PSHome.
To de-obfuscate the rest of of the script, replace 'IEX' with 'Write-Host'. This general approach, replacing an execution command with a print/write command, works in basically all interpreted languages. In this case, the output is more obfuscated PowerShell.
It's the same obfuscation techniques used in the original PowerShell script, but this time 'IEX' is reconstructed from $ShellId instead of $PSHome.
When we replace 'IEX' with 'Write-Host' and run the script this time, we get human-readable code that is the final payload.
Here is the de-obfuscated PowerShell beautified and marked up. It is a simple TCP reverse shell that executes any PowerShell provided by the attacker C2 server, the address and port of which is hardcoded in the Net.Sockets.TCPClient() call in the first line of the script.
And, no, I don’t feel the slightest bit bad about burning this Red Team’s C2 on Twitter.
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Paul Melson

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!