This challenge name should be
No Star Where
, the challenge maker was so "cay".
The challenge gives us a packet capture file. We don't have to care all of packets in it.
We just attend some packets like this. As you can see, the victim machine with IP address 192.168.25.164
had downloaded a zip file from 140.238.217.117:4953
.
After exporting and unzipping it, I have two files.
I thought Security Baseline Discipline.docx
had malicious macros in it, but after using olevba to analyse, it seems not a malware.
Checking file type of baseline.scr
, I got it is PE32 execute file.
First, I disassembled it and saw the code, but its code is too complicated to analyse and this is not a reverse challenge. This is a forensics challenge.
So I ran it and used Process Hacker
to see baseline.scr
process.
It called child process cmd.exe
and cmd.exe
called its child processes conhost.exe
and curl.exe
.
After a while, it called run32dll.exe and displayed error messages.
The cmd.exe
process ran the batch file from Temp\50E1.tmp\50E2.tmp
I went to this location and saw the content of 50E3.bat file
After deobfuscated it, I got:
This batch file checks if bundau.dll
in Temp
exists, It would execute rundll32.exe
running bundau.dll
.
If not, it would download WINWORD.EXE
which contains bundau.dll
and unzip it using 7zip with password Njg1NDM4NjY0YzQwNjc
, then execute rundll32.exe bundau.dll Start
command.
If you don't know how to do dynamic analysis, you can drop it into virustotal to analyse, well, and it makes the challenge more simple.
You can export WINWORD.EXE
from Wireshark.
Like scr
file, this file is so complicated to analyse, so I dropped it to Virustotal to check. It seems to be a Havoc demon.
Yeah, and Havoc is an open source C2 framework, so I can find its source and read. https://github.com/HavocFramework/Havoc
In Transport.c
, we can easily see that C2 payload can transport via HTTP or SMB
If we filter "http", we can see the command and result transfer between server and victim machine.
We can see package structure in Demon.c
The first HTTP POST request packet from 192.168.25.164
to 140.238.217.117
is an initial packet. It contains AES Key, IV,…like package structure.
But, the package header is quite different than the package structure we've seen before. And it makes me a while to understand.
According to the package structure, in 16-byte first, 4-byte is SIZE, next 4-byte is magic value, next 4-byte is agent id and last 4-byte is command id right, and next is aes key right? But, AES key can not start with null character, so I thought it has some byte to obfuscated or something.
But after reading the Package.c
, I understood why the package structure I found in Demon.c
and the package structure I found in the packet are different. Yeah, Havoc C2 had a new update 3 months ago and what we saw in Demon.c
is old. The new stucture of packet is Size -> Magic Value -> Agent ID -> Command ID ->Request ID.
Update: Demon.c
has updated new structure here.
Base on it, I can extract aes key and iv from the initial packet.
The Key and IV are from the 20th byte, next 32-byte is Key and then 16-byte is IV.
Key = d67078c44224e658f402ae447a101206e88e20ca3028062c668e60a41082fab8
IV = 8a34bce42cc46a2ad0a48ebcfeb0aa36
Okay, we have Key and IV, but what kind of AES is it? I usually decrypt AES mode CBC and I thought this AES mode is CBC too but I was wrong.
After a while struggle with this I read a source code and found AES Mode is CTR.
Let decrypt all packet.
For packet from the server (packet contain command), we have to decrypt data from 12nd byte.
tshark -r capture.pcap -Y 'http && frame.len != 153 && frame.len != 206 && frame.len != 78' -T fields -e data.data > data2.txt
And the packet from implant (packet contain result), we have to decrypt data from 20th byte (except initial packet).
tshark -r capture.pcap -Y 'http && frame.len != 153 && frame.len != 206 && frame.len != 78 && frame.len != 660 && frame.len != 111 && frame.len != 268' -T fields -e media.type > data.txt
Command:
Result:
We can see the MZ file:
Retrieve it and load it into dnspy. We can see the function unhide
that decript byte array below.
I wrote a python script to decrypt it.
And got the flag.
Flag: HTB{4_r4ns0mw4r3_4lw4ys_wr34k5_h4v0c}
Reference: https://www.zscaler.com/blogs/security-research/havoc-across-cyberspace