In my day job I most commonly find CobaltStrike Beacon payloads executed via base64-encoded PowerShell following an initial compromise; maybe phishing or a web application vulnerability leading to command execution. Encoding the command means the threat actor doesn’t need to worry about matching quotes, brackets, etc when passing the command over the channel.
This rule uses YARA’s base64 modifier to match encoded variants of the loader command.
rule MAL_CobaltStrike_Powershell_loader_base64 {
meta:
description = "Matches base64-encoded strings found in CobaltStrike PowerShell loader commands."
last_modified = "2024-02-10"
author = "@petermstewart"
DaysofYara = "41/100"
strings:
$a1 = "=New-Object IO.MemoryStream(" base64 wide
$a2 = "[Convert]::FromBase64String(" base64 wide
$a3 = "IEX (New-Object IO.StreamReader(New-Object IO.Compression.GzipStream($s,[IO.Compression.CompressionMode]::Decompress))).ReadToEnd()" base64 wide
condition:
all of them
}
Find the rest of my 100DaysofYARA posts here, and the rules themselves on my Github repository.