Detect Non-Standard Encoding in Elastic Security
Adversaries may encode data with a non-standard data encoding system to make the content of command and control traffic more difficult to detect. Non-standard encoding schemes diverge from existing protocol specifications — for example, modified Base64 using a custom alphabet, XOR encoding with a static or rolling key, character substitution (replacing '/' with '-s', '+' with '-p'), or custom binary serialization. Real-world examples include OceanSalt (NOT operation on bytes), Small Sieve (hex byte swapping), TONESHELL (XOR with 32/256-byte key), NightClub (modified Base64 in DNS subdomains), RDAT (Base64 with character substitutions in DNS), InvisiMole (modified Base32 in DNS subdomains), and Uroburos (custom Base62/Base32). Detection focuses on anomalous DNS subdomain lengths and entropy, unusual encoded patterns in network traffic, and scripting processes generating high-entropy outbound data.
MITRE ATT&CK
- Tactic
- Command and Control
- Technique
- T1132 Data Encoding
- Sub-technique
- T1132.002 Non-Standard Encoding
- Canonical reference
- https://attack.mitre.org/techniques/T1132/002/
Elastic Detection Query
any where event.category == "network" and
(
/* Branch 1: DNS — first subdomain label matches Base64, URL-safe Base64, or hex encoding (> 50 chars) */
(
network.protocol == "dns" and
dns.question.name != null and
(
dns.question.name regex "^[A-Za-z0-9+/=]{50,}\\." or
dns.question.name regex "^[A-Za-z0-9_\\-]{50,}\\." or
dns.question.name regex "^[0-9a-fA-F]{50,}\\."
)
) or
/* Branch 2: HTTP/S — anomalously long encoded path segment or query parameter */
(
network.protocol in ("http", "https") and
url.path != null and
(
url.path regex "/[A-Za-z0-9_\\-]{60,}(/|\\?|$)" or
url.query regex "[a-z]{1,4}=[A-Za-z0-9+/_%\\-]{60,}"
)
) or
/* Branch 3: Scripting engine making outbound public-IP connections (beaconing) */
(
process.name in~ ("python.exe", "python3", "python3.exe", "perl.exe", "ruby.exe",
"wscript.exe", "cscript.exe", "mshta.exe", "powershell.exe", "pwsh.exe") and
not cidrMatch(destination.ip, "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16",
"127.0.0.0/8", "169.254.0.0/16", "::1/128")
)
) Detects T1132.002 non-standard encoding across three branches: (1) DNS subdomains whose first label matches Base64, URL-safe Base64, or hex patterns exceeding 50 characters — matching TONESHELL, NightClub, RDAT, and InvisiMole DNS tunneling; (2) HTTP/S requests with path segments or query parameters exceeding 60 characters of encoded content; (3) scripting engines (Python, PowerShell, WScript, etc.) making persistent outbound connections to public IPs consistent with custom-encoded beaconing.
Data Sources
Required Tables
False Positives & Tuning
- CDN edge nodes and load balancers using long hash-based subdomain labels for health checks or anycast routing (e.g., AWS ELB, Fastly, Akamai long-token subdomains)
- Legitimate software update and package management services encoding content hashes or version manifests as long Base64 query parameters (e.g., npm, pip, Homebrew with integrity verification)
- Developer tunneling tools such as ngrok, localtunnel, or Cloudflare Tunnel that generate long random Base64-like subdomains to proxy locally running services
Other platforms for T1132.002
Testing Methodology
Validate this detection against 4 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1Simulate DNS Tunneling with Modified Base64 Subdomain Encoding
Expected signal: Sysmon Event ID 22 (DNS Query): QueryName will contain a long alphanumeric subdomain label (length > 30 characters) matching the pattern [a-z0-9ps]{30,}\.df00tech-test\.local. Sysmon Event ID 1 (Process Create): powershell.exe with command line containing Base64, Replace, and Resolve-DnsName. PowerShell ScriptBlock Log Event ID 4104 capturing the encoding logic.
- Test 2XOR-Encoded C2 Data Transmission Simulation (TONESHELL Pattern)
Expected signal: Sysmon Event ID 1: powershell.exe with CommandLine containing -bxor, New-Object System.Net.WebClient, and UploadString. Sysmon Event ID 3: Network connection attempt to 127.0.0.1:8080 (connection will be refused but event fires). PowerShell ScriptBlock Log Event ID 4104 capturing the full XOR encoding loop and WebClient upload code.
- Test 3High-Volume DNS Query Burst Simulating DNS Tunneling Data Transfer
Expected signal: 25x Sysmon Event ID 22 (DNS Query) events within ~5 seconds, each with a unique QueryName containing a long base64-like subdomain label (length 40-70 characters) under df00tech-dnstest.local. All queries initiated by powershell.exe. The burst pattern with unique subdomains matches DNS tunneling telemetry.
- Test 4HTTP C2 with Custom Base64 Alphabet Encoding (Neo-reGeorg Pattern)
Expected signal: Sysmon Event ID 1: powershell.exe with CommandLine containing IndexOf, ToCharArray, WebClient, and UploadString — all indicators of custom encoding implementation. Sysmon Event ID 3: Network connection to 127.0.0.1:8080. PowerShell ScriptBlock Log Event ID 4104 capturing the full custom alphabet encoding logic. If stream:http is available, the POST body will contain d=<60+ char custom-alphabet string>.
References (11)
- https://attack.mitre.org/techniques/T1132/002/
- https://en.wikipedia.org/wiki/Binary-to-text_encoding
- https://en.wikipedia.org/wiki/Character_encoding
- https://www.welivesecurity.com/2023/08/10/moustachedbouncer-espionage-targeted-isp-level-adversary-in-the-middle-attacks-against-belarus/
- https://unit42.paloaltonetworks.com/rdat-used-to-target-middle-eastern-energy-company/
- https://www.welivesecurity.com/2020/06/18/digging-up-invismole-hidden-arsenal/
- https://media.kasperskycontenthub.com/wp-content/uploads/sites/43/2017/08/07172148/ShadowPad_technical_description_PDF.pdf
- https://www.mandiant.com/sites/default/files/2022-02/rt-apt41-dual-operation.pdf
- https://github.com/L-codes/Neo-reGeorg
- https://www.ncsc.gov.uk/files/NCSC-GCHQ-Small-Sieve-Malware-Analysis-Report.pdf
- https://www.cisa.gov/sites/default/files/2022-02/aa22-055a-iranian-government-sponsored-actors-conduct-cyber-operations.pdf
Unlock Pro Content
Get the full detection package for T1132.002 including response playbook, investigation guide, and atomic red team tests.