// HackTheBox  ·  writeup

Takedown

HackTheBox Easy tsharkVirusTotal
SOC

Scenario

We’ve identified an unusual pattern in our network activity, indicating a possible security breach. Our team suspects an unauthorized intrusion into our systems, potentially compromising sensitive data. Your task is to investigate this incident.

Executive Summary

A victim host opened a VBScript from a remote SMB share hosted on an attacker-controlled domain. The script reached out over HTTP to a second domain and pulled a PowerShell stager. That stager downloaded a legitimate AutoHotkey interpreter, a decoy text payload, and an AutoHotkey script, then saved the script to disk so the interpreter could run it. The script was a DarkGate RAT loader, and the infected host then beaconed to a single external IP over plain HTTP using a Chrome user-agent. The entire chain is recoverable from one packet capture.

Artifacts

Format note: Several answers are URLs or hashes with a fixed shape. The task format masks (*************.***/********) match the host and path exactly as seen on the wire, so don’t add or drop a scheme unless the mask shows one.

Initial Access

Q1 — From what domain is the VBS script downloaded?

Start with a conversation and DNS overview of the capture to see which hosts the victim talked to. The script does not arrive over HTTP: the SMB2 tree connect names the share as \\escuelademarina.com\cloud, and the domain is the host part of that UNC path.

tshark -r Takedown.pcap -Y smb2 -T fields -e frame.number -e smb2.cmd -e smb2.tree
Click flag to reveal escuelademarina.com
Q2 — What was the IP address associated with the domain in question #1 used for this attack?

From Q1 we have the domain. Pull the DNS responses for it and read the A record the victim resolved before connecting to the share.

tshark -r Takedown.pcap -Y dns -T fields -e dns.qry.name -e dns.a
Click to reveal answer 165.22.16.55
Q3 — What is the filename of the VBS script used for initial access?

Inside the SMB2 session to the cloud share, the Create request names the file being opened and the following Read responses carry its contents. One .vbs file is opened, and its name is built to look like a document.

tshark -r Takedown.pcap -Y "smb2.cmd == 5" -T fields -e frame.number -e smb2.filename
Click flag to reveal AZURE_DOC_OPEN.vbs

Execution

Q4 — What was the URL used to get a PowerShell script?

List every HTTP request in the capture and drop the repeating GET / beacons. What remains is a short run of requests to a second domain with random-looking eight-letter paths. The first of them returns a PowerShell script, which is the stager the VBS launches.

tshark -r Takedown.pcap -Y http.request -T fields -e frame.number -e http.host -e http.request.uri
Click to reveal answer badbutperfect.com/nrwncpwo
Q5 — What likely legit binary was downloaded to the victim machine?

Export the response from Q4 and read it. The script downloads three further objects from the same host. One is saved with the output name AutoHotkey.exe, a legitimate scripting interpreter that will run whatever script it is handed.

tshark -r Takedown.pcap --export-objects http,work/obj
Click flag to reveal AutoHotkey.exe
Q6 — From what URL was the malware used with the binary from question #5 downloaded?

The stager pulls two non-binary objects besides the interpreter. One is a large hex-encoded text blob. The other is a small AutoHotkey script, and that is the payload the interpreter executes. Match the -OutFile target in the PowerShell to the request path.

tshark -r Takedown.pcap -Y "http.request.uri contains jvtobaqj" -T fields -e http.host -e http.request.uri

Gotcha: The biggest object in the capture is the hex blob, and it is easy to take it for the malware. It is a decoy payload served as text. The malware is the short .ahk script, and --export-objects can miss large objects, so reassemble the TCP stream when an export comes back short.

Click to reveal answer http://badbutperfect.com/jvtobaqj
Q7 — What filename was the malware from question #6 given on disk?

The same PowerShell stager from Q4 decides the on-disk name. Find the -OutFile argument paired with the Q6 URL.

tshark -r Takedown.pcap -Y "frame.number == <stager frame>" -T fields -e http.file_data | xxd -r -p
Click flag to reveal script.ahk
Q8 — What is the TLSH of the malware?

Reassemble the TCP payload of the Q6 download, strip the HTTP headers, hash the body and look the SHA-256 up on VirusTotal. The file details tab shows the TLSH.

tshark -r Takedown.pcap -q -z follow,tcp,raw,<stream> | xxd -r -p > work/o2/ahk.txt
vt 5aac7d31149048763e688878c3910ae4881826db80e078754f5d08f2c1f39572

Gotcha: The TLSH of the hex blob from Q6 looks equally valid and is a different file. Make sure the hash comes from the .ahk body, not the largest object.

Click to reveal answer T15E430A36DBC5202AD8E3074270096562FE7DC0215B4B32659C9EF16835CF6FF9B6A1B8
Q9 — What is the name given to this malware? Use the name used by McAfee, Ikarus, and alejandro.sanchez.

The same VirusTotal report from Q8 lists vendor detections. McAfee and Ikarus both use one family name, and the community comment agrees. This comes from the VirusTotal verdicts rather than from anything in the capture.

Click flag to reveal DarkGate

Command and Control

Q10 — What is the user-agent string of the infected machine?

After the staging downloads, the capture is dominated by repeating GET / requests, which are the RAT beacons. Print the user-agent field on those requests.

tshark -r Takedown.pcap -Y 'http.request.uri == "/"' -T fields -e http.user_agent | sort | uniq -c
Click to reveal answer Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Q11 — To what IP does the RAT from the previous question connect?

Group the beacon requests from Q10 by destination. Every one goes to the same external address, which is the C2.

tshark -r Takedown.pcap -q -z endpoints,ip
Click flag to reveal 103.124.105.78

Attack Summary

PhaseAction
Initial AccessVictim opens a VBScript from an SMB share on an attacker domain
ExecutionThe VBS fetches a PowerShell stager over HTTP from a second domain
ExecutionThe stager downloads the AutoHotkey interpreter, a decoy hex payload and an AutoHotkey script
ExecutionThe script is saved as script.ahk and run by the interpreter
Command and ControlDarkGate beacons to a single external IP over HTTP with a Chrome user-agent

IOCs

TypeValue
Domain (SMB share)escuelademarina[.]com
IP165.22.16[.]55
FileAZURE_DOC_OPEN.vbs
Domain (staging)badbutperfect[.]com
URL (PowerShell stager)badbutperfect[.]com/nrwncpwo
URL (AHK malware)hxxp[://]badbutperfect[.]com/jvtobaqj
FileAutoHotkey.exe, script.ahk
SHA-256 (AHK script)5aac7d31149048763e688878c3910ae4881826db80e078754f5d08f2c1f39572
TLSHT15E430A36DBC5202AD8E3074270096562FE7DC0215B4B32659C9EF16835CF6FF9B6A1B8
C2 IP103.124.105[.]78

MITRE ATT&CK

TechniqueIDDescription
User Execution: Malicious FileT1204.002Victim opens the VBScript from the remote share
Command and Scripting Interpreter: Visual BasicT1059.005VBS launches the chain
Command and Scripting Interpreter: PowerShellT1059.001Stager downloads the interpreter and payloads
Command and Scripting Interpreter: AutoHotKey & AutoITT1059.010DarkGate loader runs as an AutoHotkey script
Ingress Tool TransferT1105Interpreter, decoy and script pulled from the staging host
Application Layer Protocol: Web ProtocolsT1071.001HTTP beacons to the C2

Defender Takeaways

Outbound SMB to the internet should be blocked. The VBS reached the victim through a UNC path to an external domain. Dropping TCP 445 (and WebDAV fallback) at the perimeter would have broken the first step.

Script host launches from network paths deserve an alert. wscript/cscript opening a .vbs from a remote share, followed by a PowerShell child making web requests, is a short and distinctive process chain.

A legitimate interpreter dropped to disk is still an indicator. AutoHotkey on a host that does not use it, run against a freshly written .ahk file, is the actual malware execution. Allowlisting or alerting on non-standard interpreters catches it.

Plain HTTP beacons with a static user-agent are huntable. Repeated GET / to one external IP with an identical browser user-agent is easy to baseline in proxy or NetFlow data.

Conclusion

The attacker needed one opened script to reach a DarkGate RAT beaconing from the victim, and every stage after it used a legitimate interpreter and plain HTTP. The whole chain is visible in a single packet capture, and the detection value sits in the odd sequence of SMB, script host, PowerShell and AutoHotkey rather than in any single binary.