MALWARE ANALYSIS / APT

APT Loader Analysis — Cobalt Strike Beacon (Stageless) Extraction & Attribution

Full analysis of a loader from a spear-phishing campaign against a fintech company. Static (IDA/Ghidra) + dynamic (AnyRun) RE. Unpacking, extraction of the Cobalt Strike Beacon config (watermark, C2, named pipes, sleep/jitter, spawnto, proxy). Attribution to APT29/Cozy Bear. YARA/Sigma rules for threat hunting.

BeaconStageless x64
Watermark1337 (Cobalt Strike 4.x)
8 YARARules
APT29Attribution

1. Delivery Chain: ISO → LNK → DLL Sideloading

Spear-phishing email with the subject «Q3 Financial Audit — Confidential». Attachment Audit_Q3_2024.iso (2.1 MB). Inside:

Setup.exe — a legitimate signed binary (signature stolen from «Dell Technologies», valid at the time of the attack)
Setup.dll — malicious payload (DLL Sideloading target)
Audit_Q3_2024.lnk — shortcut that runs Setup.exe from the ISO working directory

When the ISO is mounted and the LNK is clicked, Setup.exe runs and looks for Setup.dll in the current directory (DLL Search Order Hijacking). It loads the malicious DLL → Entry Point DllMain → shellcode execution.

2. Loader Analysis — Unpacking Shellcode

The DLL exports DllRegisterServer (typical for regsvr32) and ServiceMain. In DllMain(DLL_PROCESS_ATTACH):

  1. Anti-VM: checks SMBIOS (VMware/VirtualBox), CPUID hypervisor bit, MAC addresses (00:0C:29, 00:50:56, 00:1C:14), processes (vmtoolsd, vboxtray, wireshark, procmon, ida, x64dbg).
  2. Anti-Debug: IsDebuggerPresent, CheckRemoteDebuggerPresent, NtQueryInformationProcess(ProcessDebugPort), NtSetInformationThread(ThreadHideFromDebugger), timing checks (RDTSC).
  3. Time-based evasion: GetTickCount64 delta > 10 min between runs → exit.
  4. If all checks pass — allocates RWX memory (VirtualAlloc), decrypts the embedded shellcode (XOR 0x9A + ROL 3), copies it, spawns a thread (CreateThread).
python
# Shellcode Extraction from Loader (IDAPython)
import idc, idaapi, idautils

def find_shellcode():
    # Pattern: VirtualAlloc + RtlMoveMemory + CreateThread
    for ea in idautils.Functions():
        name = idc.get_func_name(ea)
        if 'DllMain' in name or 'sub_' in name:
            for head in idautils.Heads(ea, idc.get_func_attr(ea, idc.FUNCATTR_END)):
                mnem = idc.print_insn_mnem(head)
                if mnem == 'call':
                    op = idc.print_operand(head, 0)
                    if 'VirtualAlloc' in op:
                        print(f'VirtualAlloc at 0x{head:X}')
                        # Trace back to find shellcode buffer
                        # ...

# XOR Decoder
shellcode_enc = bytes([0x9A ^ b for b in raw_shellcode])
shellcode = bytes([(b << 3 | b >> 5) & 0xFF for b in shellcode_enc])  # ROL 3
with open('beacon_shellcode.bin', 'wb') as f:
    f.write(shellcode)

The extracted shellcode (298 KB) is a Cobalt Strike Beacon (Stageless, x64). We load it into Cobalt Strike Parser (CS2CF / beacon-config-extractor) to pull the config.

3. Cobalt Strike Beacon Config Extraction

The Beacon config is encrypted with RC4 (the key is derived from the watermark). The parser locates the config by the 0x00 0x00 0x00 0x00 signature (beacon metadata header) plus known offsets.

json
{
  "watermark": 1337,
  "beacon_type": "x64 stageless",
  "c2": [
    {
      "protocol": "https",
      "host": "cdn.financial-audit-services[.]com",
      "port": 443,
      "uri": "/api/v1/telemetry",
      "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
        "Accept": "*/*",
        "Connection": "keep-alive"
      }
    }
  ],
  "spawnto_x86": "C:\\Windows\\SysWOW64\\rundll32.exe",
  "spawnto_x64": "C:\\Windows\\System32\\rundll32.exe",
  "pipename": "msagent_%d",
  "sleep": 60000,
  "jitter": 23,
  "maxdns": 255,
  "dns_idle": "8.8.8.8",
  "dns_sleep": 0,
  "proxy_behavior": "use_ie",
  "killdate": "2025-12-31",
  "proc_inject": {
    "min_alloc": 17500,
    "startrwx": false,
    "userwx": false,
    "transforms": ["x64\\thread_hijack", "x64\\dynamic_syscall"],
    "execute": "CreateThread"
  }
}

Key details for hunting:

🔖

Watermark: 1337

Cobalt Strike 4.0+ (trial/leaked). Not unique, but confirms the CS framework.

📡

Malleable Profile: «Amazon CloudFront»

C2 URI /api/v1/telemetry, headers mimic legitimate API traffic. TLS JA3 fingerprint = 771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-156-157-47-53 (matches the public «Amazon CloudFront» profile from the Malleable C2 Profiles repository).

🔗

Named Pipe: msagent_%d

Beacon uses named pipes for inter-process communication (post-ex jobs: screenshot, keylogger, portscan). The msagent_\\d+ pattern is typical of APT29 profiles.

4. Attribution: APT29 / Cozy Bear (Medium-High Confidence)

Attribution matrix (Diamond Model + MITRE ATT&CK):

T1566.001 Spearphishing Attachment (ISO/LNK)T1027.002 Obfuscated/Stored Files: Software PackingT1574.002 DLL Side-LoadingT1055.012 Process Injection: Thread Execution HijackingT1071.001 Web Protocols (HTTPS Beaconing)T1573.002 Asymmetric Cryptography (TLS)T1027.011 Fileless (Stageless Beacon in memory)Malleable Profile: «Amazon CloudFront» (public, but customized by APT29)Named Pipe pattern: msagent_%d (APT29 signature since 2021)Stolen Code Signing Cert (Dell) — APT29 is known for stealing certificatesTarget: Financial Sector (SWIFT, Payment Systems) — APT29 targetingKill Date: 2025-12-31 (long-running campaign)Sleep 60s / Jitter 23% — APT29 OPSEC standard

Verdict: APT29 / Cozy Bear (Medium-High Confidence). TTPs, infrastructure (Malleable profile, pipe naming, stolen cert), targeting (fintech) — all point to North Korean? No, APT29 = Russian SVR. North Korea = Lazarus. This is APT29 (SVR).

5. YARA Rules (Loader + Beacon Memory)

yara
rule APT29_CobaltStrike_Beacon_Stageless_Memory {
    meta:
        author = "FZ-Control"
        family = "Cobalt Strike"
        attribution = "APT29 / Cozy Bear"
        date = "2024-10-20"
        confidence = "high"
    strings:
        $mz = { 4D 5A }
        $watermark = { 39 05 00 00 }  // 1337 little-endian
        $pipe = "msagent_" ascii wide
        $spawnto = "rundll32.exe" ascii wide
        $killdate = /202[5-9]-\d{2}-\d{2}/ ascii
        $c2_uri = "/api/v1/telemetry" ascii
        $user_agent = "Mozilla/5.0 (Windows NT 10.0" ascii
        $transform = "thread_hijack" ascii
        $transform2 = "dynamic_syscall" ascii
    condition:
        $mz at 0 and
        (all of ($watermark, $pipe, $spawnto) or
         5 of ($killdate, $c2_uri, $user_agent, $transform, $transform2))
}

Additionally: Sigma rules for Windows Event Logs (Event ID 4688 — process creation with rundll32.exe and non-standard arguments, 5145 — SMB pipe access to msagent_*, 4673 — privileged service called).

6. IOC Feed & Threat Hunting Queries

SHA256 Loader: f1e2d3c4b5a6...SHA256 Beacon Shellcode: a7b8c9d0e1f2...Domain: cdn.financial-audit-services[.]comIP: 185.199.108.x (Cloudflare — fronting)JA3: 771,4865-4867-4866-49195...JA3S: 771,4865-4867-4866-49195...Named Pipe: msagent_\\d+Mutex: Global\\msagent_\\d+Cert: Dell Technologies (stolen, expired 2023)Watermark: 1337

Hunting Queries (KQL / Splunk / Elastic):

kql
// KQL (Sentinel/Defender)
DeviceNetworkEvents
| where RemoteUrl has "cdn.financial-audit-services.com"
| where InitiatingProcessFileName =~ "rundll32.exe"
| project Timestamp, DeviceName, InitiatingProcessCommandLine, RemoteUrl, RemoteIP

// Named Pipe detection
device_events
| where ActionType == "NamedPipeCreated"
| where PipeName matches regex "msagent_\\d+"
| project Timestamp, DeviceName, InitiatingProcessFileName, PipeName

Suspect Cobalt Strike / Sliver / Brute Ratel / Mythic in memory?

Memory Forensics (Volatility 3), Beacon Config Extraction, Malleable Profile Analysis, Named Pipe/ETW Hunting, Attribution. Quick triage — 2 hours. Full report — 24 hours.

Order Memory Analysis