$ cat writeup.md…
$ cat writeup.md…
hackthebox
Task: Extract a flag from a malicious Word document used in a ransomware phishing attack. Solution: Extract VBA macros from the .docm file, decode the Base64-encoded PowerShell payload, find an integer array representing XOR-encrypted data, and decrypt with key 0xdf to reveal the flag.
WearRansom ransomware was released in our company. The SOC has traced the initial access to a phishing attack, a Word document with macros. Take a look at the document and see if you can find anything else about the malware and perhaps a flag.
Word documents with macros (.docm) are actually ZIP archives. We can extract them using standard ZIP tools or directly examine the contents:
# Extract as ZIP unzip -q emo.docm -d emo_extracted ls emo_extracted/
Using oletools to extract and analyze VBA macros:
# Extract VBA macros oledump.py emo.docm olevba emo.docm
Key findings:
Document_open() entry point in macros (executes when document opens)The VBA contains a Base64-encoded PowerShell payload. Extract and decode it:
import base64 # The encoded payload from VBA macro encoded = "..." # Base64 string from macro decoded = base64.b64decode(encoded) # Remove non-ASCII characters import re clean = re.sub(rb'[^\x00-\x7F]+', b'', decoded)
The deobfuscated PowerShell contains:
0xdf (found as [byte][char]${_} -bxor 0xdf)# Integers from the decoded payload data = [186,141,228,182,177,171,229,236,239,239,239,228,181,182,171,229,234,239,239,228,185,179,190,184,229,151,139,157,164,235,177,239,171,183,236,141,128,187,235,134,128,158,177,176,139,183,154,173,128,175,151,238,140,183,162,228,170,173,179,229] # XOR with key 0xdf xor_key = 0xdf flag = ''.join(chr(b ^ xor_key) for b in data) print(flag)
#!/usr/bin/env python3 """ emo - HackTheBox Forensic Challenge Solution WearRansom ransomware analysis - extracting flag from obfuscated PowerShell """ # Integers extracted from the deobfuscated PowerShell payload data = [186,141,228,182,177,171,229,236,239,239,239,228,181,182,171,229,234,239,239,228,185,179,190,184,229,151,139,157,164,235,177,239,171,183,236,141,128,187,235,134,128,158,177,176,139,183,154,173,128,175,151,238,140,183,162,228,170,173,179,229] # XOR key found in PowerShell: [byte][char]${_} -bxor 0xdf xor_key = 0xdf # Decode flag = ''.join(chr(b ^ xor_key) for b in data) print(f"Flag: {flag}")
This technique is useful when:
oledump.py: Dump OLE streams (extract macros)olevba: Extract and analyze VBA macros$ cat /etc/motd
Liked this one?
Pro unlocks every writeup, every flag, and API access. $9/mo.
$ cat pricing.md$ grep --similar