This detection rule identifies adversaries employing double encoding (hex within Base64) to obfuscate malicious payloads and evade signature-based security controls. Proactively hunting for this behavior in Azure Sentinel is critical because such complex encoding often signals advanced command-and-control traffic or staged execution attempts that standard rules may miss due to their nested structure.
rule SUSP_Base64_Encoded_Hex_Encoded_Code {
meta:
author = "Florian Roth (Nextron Systems)"
description = "Detects hex encoded code that has been base64 encoded"
date = "2019-04-29"
score = 65
reference = "https://www.nextron-systems.com/2019/04/29/spotlight-threat-hunting-yara-rule-example/"
id = "2cfd278f-ff45-5e23-b552-dad688ab303b"
strings:
$x1 = { 78 34 4e ?? ?? 63 65 44 ?? ?? 58 48 67 }
$x2 = { 63 45 44 ?? ?? 58 48 67 ?? ?? ?? 78 34 4e }
$fp1 = "Microsoft Azure Code Signp$"
condition:
1 of ($x*) and not 1 of ($fp*)
}
This YARA rule can be deployed in the following contexts:
This rule contains 3 string patterns in its detection logic.
Here are 5 specific false positive scenarios for the rule “Detects hex encoded code that has been base64 encoded,” along with suggested filters or exclusions:
Scenario: Microsoft Defender for Endpoint (MDE) or CrowdStrike Falcon agents performing scheduled binary signature updates.
C:\Program Files\Microsoft Defender\MsMpEng.exe (or the specific CrowdStrike service executable) where the command line contains keywords like “update,” “signature,” or “sync.”Scenario: PowerShell scripts utilizing ConvertTo-Base64String on binary files for configuration management.
powershell.exe and the command line contains parameters such as -Command, -File, or specific script paths ending in .ps1 located within a known “Automation” or “Scripts” directory.Scenario: Docker container orchestration (Kubernetes/Docker Engine) pulling image layers.
dockerd or kubelet communication logs to ensure safe transmission over HTTP/HTTPS.