Move Aside Script Kiddies: Malware Execution in The Age of Advanced Defenses
Move Aside Script Kiddies: Malware Execution in The Age of Advanced Defenses
Kiddies
Malware Execution in the
Age of Advanced Defenses
Author: Joff Thyer © 2020
Black Hills Information Security
Who am I?
● Joff Thyer
○ Malware Developer, Researcher, and Pen Tester
○ Black Hills Information Security
○ SANS Certified Instructor of SEC573
○ Co-Host of Security Weekly Podcast
○ Musician, and lover of geeky things
Attacker / Threat Actor Emulation
● Stage 1:
○ If you use a Metasploit reverse_https for example, then the initial
certificate exchange will be stopped.
○ Unless… you use your own domain and your own legit signed certificate
○ Let’s say thanks to LetsEncrypt one more time here….
● Stage 2:
○ Unless you encode it AND you are using a server side certificate with
domain, then second stage will ALWAYS be busted.
○ Multi/handler:
■ set StageEncoder x64/zutto_dekiro
■ set EnableStageEncoding true
Metasploit encode/encrypt
● Encoders are not bad with msfvenom.
○ Encoders have specific machine code routines that still have to run to
“decode” and write results back to memory segment when code resides.
○ Memory segment must be RWX permissions to allow decode to occur.
● Encryption algorithms are available in msfvenom also.
● My personal rules
○ Leverage the msfvenom “transform” formats and do your own custom
encoding of the shellcode in another language.
○ Do NOT use second stage payloads but rather “single” stage.
○ Stick with 64-bit these days.
○ Customize to live off the land.
C2 - Customize and LOL
● You can execute shellcode from many different programming or
scripting languages.
● The outline/sequence for execution is universally the same whether
in a local process or targeting a remote process
○ Create a memory buffer
○ Copy shellcode to that buffer
○ Create a thread or a process that points to that buffer.
● Living off the land binaries and scripts (LOLBAS) directly help with
app whitelisting
● But can also help with A/V and EDR evasion.
C2 - Shellcode Obfuscation
● The goal here is to ensure that the shellcode does not exist in the
delivery cradle (program) in its original form
○ Why? Because A/V solutions will immediately trigger
● There are MANY possibilities here to customize/obfuscate
○ Encrypt / Decrypt (simple XOR is ok!)
○ Encode (base64 or other base-N) / Decode
○ Compress / Uncompress
● For symmetric encryption/decryption we require a key.
○ Fixed value in source code
○ Other easy to retrieve value across Internet. (unlimited possibilities)
C2 - Defense Evasion
No Second
Stage!
Example: C# Shellcode Exec
Assumes shellcode
is base64 encoded.
● Decompilers include
○ Jetbrains DotPeek
○ Telerik JustDecompile
● Use a source protector to avoid reversing. (ConfuserEX)
Recon/Discovery Artifacts
“E” means
encrypted
AntiMalware Scan Interface
● AMSI can be annoying
● .NET 4.8 has AMSI when loading Assemblies.
● PowerShell Version 2.0 does not have AMSI (Downgrade)
AMSI is a response to “fileless” threats
● https://github.com/yoda66/PowerStrip
○ All it does is remove comments from scripts.
AMSI Bypass
● https://wildwesthackinfest.com/training/enterprise-attacker-emula
tion-and-c2-implant-development-w-joff-thyer/
Questions / Comments?