APT34 is Iran's most technically sophisticated cyber espionage unit. While other APTs rely on speed or destructive payloads, OilRig is built around patience. Their operations run for months or years inside target networks, using communication channels specifically designed to be invisible to standard monitoring: DNS queries that carry data in subdomain labels, commands hidden in the pixel values of BMP images, and C2 instructions stored as unsent email drafts in compromised Exchange mailboxes.
In 2023-2024, APT34 launched campaigns against government agencies across the Middle East using a new backdoor called Menorah, and deployed an updated DNS tunneling tool against telecommunications companies. They also targeted Albanian government infrastructure following diplomatic tensions, demonstrating their willingness to conduct destructive operations when politically motivated.
| Tactic | Technique | Simulation Tool |
|---|---|---|
| Command & Control | T1071.004 — DNS Tunneling (RFC 1035 implementation) | dns_c2_server.py |
| Command & Control | T1071.003 — Exchange EWS Dead-Drop C2 | exchange_deadrop.py |
| Exfiltration | T1048.003 — DNS Exfiltration (subdomain encoding) | dns_exfil.cpp |
| Defense Evasion | T1027.003 — Steganography (BMP/PNG LSB encoding) | steganography.py |
| Credential Access | T1558.003 — Kerberoasting (SPN enumeration) | kerberoast.ps1 |
| Discovery | T1087.002 — Domain Account Enumeration via LDAP | kerberoast.ps1 |
Every organization generates thousands of DNS queries per minute. APT34 recognized that DNS is the one protocol you can't block — it's required for literally everything to work. Their DNS C2 channel embeds commands and stolen data inside the queries themselves, using subdomain labels as a data transport.
I built the DNS server from scratch per RFC 1035, constructing packets at the byte level. Each DNS query carries about 30 bytes of hex-encoded data as subdomain labels. The query format maps data into the hierarchical domain structure:
At 30 bytes per query, exfiltrating a 1MB file would take ~35,000 queries. Slow? Absolutely. But distributed over days, at randomized intervals of 30-120 seconds, that's 290-1000 queries per day — which disappears into the noise of normal DNS traffic. Most SIEM rules won't flag this because each individual query looks like a perfectly legitimate DNS resolution.
Detection requires DNS analytics that measure subdomain entropy (random hex strings have much higher Shannon entropy than real hostnames) and query frequency patterns per unique base domain.
APT34 uses steganography to hide C2 commands inside image files that are served from legitimate-looking websites. The implant downloads what appears to be a normal company logo or stock photo, but the least significant bits of the pixel values contain encoded commands.
The simulation implements LSB (Least Significant Bit) encoding for both BMP and PNG formats. For BMP, the encoding is straightforward — modify the LSB of each color channel byte. PNG requires additional handling because of the compression layer, but the principle is identical. A 1920x1080 BMP image can carry approximately 760KB of hidden data.
The brilliance of this approach: network monitoring sees a standard HTTPS GET request for a JPEG/PNG file from a legitimate-looking domain. Content inspection reveals a valid image file. There's no encrypted blob, no suspicious header, nothing to flag. Detection requires comparing downloaded images against known-clean originals (a technique called steganalysis) or statistical analysis of LSB distribution patterns.
This was the most unusual C2 channel to build. APT34 authenticates to a compromised organization's OWA (Outlook Web Access) instance, creates email drafts containing commands, and the implant reads those drafts via EWS (Exchange Web Services) SOAP requests. No email is ever sent — there's no mail flow, no SMTP traffic, no delivery headers to analyze.
The challenge was implementing NTLM authentication from scratch. EWS requires NTLM, which means constructing the Type 1 (Negotiate) message with proper flags, parsing the Type 2 (Challenge) response to extract the server challenge, and building the Type 3 (Authenticate) message with NTLMv2 hash computation using HMAC-MD5:
Once authenticated, the C2 loop is deceptively simple: create a draft email with a base64-encoded command in the subject line, wait for the implant to read it and delete it, then check for a new draft containing the results. All of this happens through standard EWS SOAP over HTTPS — the same protocol that every Outlook client uses.
The C++ exfiltration tool is the high-performance counterpart to the Python DNS server. It reads files from disk, chunks them into segments that fit within DNS label length limits (63 bytes per label, 253 bytes total), hex-encodes each chunk, and constructs UDP DNS packets directly using Winsock. No DNS library dependencies — raw socket operations for minimal footprint.
Once inside a network, APT34 targets Active Directory service accounts via Kerberoasting. The PowerShell module enumerates Service Principal Names (SPNs) via LDAP, requests TGS tickets for each discovered service account, and extracts the encrypted ticket portion for offline cracking with Hashcat.
The key detail: any authenticated domain user can request a TGS ticket for any SPN — it's by design in Kerberos. The tickets are encrypted with the service account's password hash, so weak passwords can be cracked offline without generating any failed login events. It's one of the most effective privilege escalation paths in Active Directory environments.
Key Challenge: APT34's channels are designed to be invisible to standard monitoring. DNS queries look normal individually, steganographic images pass content inspection, and Exchange draft operations generate minimal logging by default.
What to hunt for:
1. DNS queries with high subdomain entropy (Shannon entropy > 3.5 for the leftmost
label)
2. Unusually high volume of TXT record queries to a single base domain
3. Exchange EWS operations creating and deleting drafts at regular intervals (enable
mailbox audit logging)
4. Image downloads followed by unusual process behavior (steganographic payload
extraction)
5. Kerberos TGS requests (Event ID 4769) for multiple SPNs from a single workstation in
a short window
6. LDAP queries enumerating servicePrincipalName attributes across all user
objects
Full simulation code available on GitHub.