// HackTheBox  ·  writeup

Kraken

HackTheBox Medium PECmdLECmdMFTECmdEvtxECmdAD1-toolsPythondnfileVirusTotal
DFIR

Scenario

Our SOC detected an emerging RAT variant delivered via malicious file execution in its early stages, triggering an alert before C2 communication was fully established. Rapid containment prevented further exfiltration or post-exploitation activities. A full forensic triage was conducted to analyze persistence mechanisms and C2 infrastructure, enabling comprehensive IOC extraction to provide them to our threat intelligence platform for enhanced detection and proactive hunting.

Executive Summary

A user on a workstation double-clicked a JScript file from their Downloads folder, and Windows Script Host immediately dropped and ran a batch file. That batch loader is heavily obfuscated with junk variables and chunked base64; it launches PowerShell, which patches the AMSI scan function in memory before decrypting two embedded PE files with AES and gzip. One is a tiny stub that is harmless alone; the other is a .NET loader carrying an AES-encrypted resource that it decrypts and injects into memory as the final RAT, a Mason/Neptune-family client. The same batch file was copied into the user’s Startup folder for persistence. The containment came before the RAT reached its C2, but its configuration was recovered and matched against public threat intel.

Artifacts

Tip: The release build of ad1extract double-frees on this image. A debug/ASAN build extracts the full tree, and ad1mount over FUSE is a fallback.

Execution

Q1 — What was the exact date and time the malicious file was executed by the user?

Parse prefetch and look at WSCRIPT.EXE: its last run lines up to the second with a Conf.js.lnk shortcut for Downloads\Conf.js, and the files wscript loaded include Conf.js itself and a TEMP_*.BAT. That is the user opening the script. Prefetch LastRun is the time to submit.

PECmd -d work/root/Windows/Prefetch --csv work/pf -q
LECmd -f Conf.js.lnk

Gotcha: The image also holds January 2025 “Ghost Toolbox” activity (TOOLBOX.UPDATER). It looks like a good lead but is unrelated noise; the incident is the June 2025 Conf.js run.

Click flag to reveal 2025-06-13 14:43:27
Q2 — During the initial stage of execution, what is the name of the first file dropped by the malicious file?

From Q1 the wscript prefetch already names a batch file in its loaded-files list. The MFT confirms it: a temp_*.bat under the Administrator profile’s AppData\Local\Temp, created one second after the script ran.

MFTECmd -f work/root/$MFT --csv work/mft --csvf mft.csv
grep -i 'temp_.*\.bat' work/mft/mft.csv
Click to reveal answer temp_993805.bat

Persistence

Q12 — A persistence file was dropped to maintain access for the attacker. What is the full path of this file?

Filter the MFT for files created in the Startup folder after the Q1 execution. One batch file appears about 14 seconds after the script ran, and the extracted copy is the obfuscated loader analysed in the following questions. The mask asks for a full path starting with the drive letter.

grep -i 'Start Menu\\Programs\\Startup' work/mft/mft.csv
Click to reveal answer C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\5c74.bat

Defense Evasion

Q3 — During the initial stage of execution, The malicious file performed in-memory patching of a critical security function by overwriting it with a 6-byte sequence that forces the function to return zero. What is this hexadecimal byte sequence?

The Startup batch is padded with junk %variable% definitions. Strip those, join the base64 chunks, and expand the long execution line (line 362) to get the PowerShell stage. A separate ::: comment line holds UTF-16 base64; decoded, it is a PowerShell script that writes a byte array over the AMSI function. A mov eax,0 ; ret stub is the classic form of that patch, and the array in the script matches it.

python3 -I work/analysis/deob1.py 5c74.bat
python3 -I work/analysis/deob2.py
python3 -I work/analysis/deob3.py 5c74.bat

Tip: The mask is ****,***,****,****,****,****, so submit the bytes exactly as the script writes them (0x prefixes, comma-separated), not as a contiguous hex string.

Click flag to reveal 0xb8,0x0,0x00,0x00,0x00,0xC3
Q4 — What is the name of the file responsible for dropping the second-stage PE Files? (2nd Stage)

The decoded PowerShell stage hardcodes a drop location in the user profile and reads two :: comment blobs from the batch file. Each blob is AES-CBC encrypted and gzip compressed, and decrypting them yields the two PE files. The file name comes from that hardcoded path in the script, not from a filesystem record: no matching file survived in the image to confirm it. This one was reasoned from the script rather than read from an artifact.

python3 -I work/analysis/dec.py 5c74.bat
grep -i 'dwm.bat' work/mft/mft.csv
Click to reveal answer dwm.bat
Q5 — What is the SHA-1 hash of the PE file created during the infection process, not malicious on its own?

Of the two PEs from Q4, one is a 4096-byte .NET stub with only a Main method and no payload logic, which fits “not malicious on its own”. Its SHA-256 also appears in vendor IOC lists for this family. The other PE is the real loader (Q6). The pick of the stub is reasoned from its size and contents rather than read from an artifact. Hash both decrypted PEs and take the stub’s SHA-1.

sha1sum work/analysis/stage3_part*
Click flag to reveal 339e27243df24f2b8979e78711e396698f4f47cc
Q6 — In the third stage, what is the name of the malicious encrypted file that is injected into memory?

The second PE is a .NET loader. List its manifest resources: a single embedded resource with an oddly repetitive name is the encrypted payload. The loader decrypts it and loads the result in memory. The mask is 28 characters plus .exe.

import dnfile
pe = dnfile.dnPE("stage3_part1.bin")
print([r.name for r in pe.net.resources])
Click to reveal answer xxxxxxxxxxxxxxxxxxxxxxxxxxxx.exe
Q7 — What encryption key and initialization vector (IV) were used to decrypt the file prior to memory injection?

The loader holds the AES key and IV as base64 strings. Pull the strings from the second PE; the pair that decrypts the Q6 resource to a gzip stream, which in turn unpacks to an MZ file, is the right one. Submit key then IV, comma-separated.

strings -n 20 stage3_part1.bin
Click flag to reveal ALWIGeOnxudniHR2K4CNZmnaEZffXt6zKsRFoAM2/mA=,JXYbOTuuz3cErOl30kAKhw==
Q8 — What is the SHA-1 hash of that file after decryption?

Decrypt the Q6 resource with the Q7 key and IV, gunzip it, and hash the result. The output is a .NET client whose internal name is MasonClient1.exe, which ties it to the Mason/Neptune RAT family. VirusTotal recognises the hash.

sha1sum payload_dec.bin
Click to reveal answer 052c0687f023564a3c31fb652bea3405341272cb

Command and Control

Q9 — There are 3 user agent strings in that PE File, what is the one related to the Mobile Device?

The decrypted payload stores its user agents as UTF-16 strings, so plain strings misses them. Dump wide strings and filter for the mobile one.

strings -el payload_dec.bin | grep -i iphone
Click flag to reveal Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1
Q10 — What variable stores the mutex object created by this binary?

No .NET decompiler was available, so read the IL directly. Find the Mutex::.ctor call and the stsfld that follows it; the field token it stores to resolves to a row in the Field metadata table, and that row’s name is the variable.

import dnfile
pe = dnfile.dnPE("payload_dec.bin")
print(pe.net.mdtables.Field.rows[12].Name)
Click to reveal answer Territories
Q11 — What is the ip address and port number that C2 file connects to during that time?

The payload config holds a DuckDNS hostname (apostlejob3[.]duckdns[.]org) and port 2468. The IP is not in the evidence: the containment cut the connection before it resolved, and the event logs hold nothing for it. It comes from a public threat report on this Mason/Neptune RAT version, whose IOC list pairs that hostname with an address (Gurucul research).

grep -rla apostlejob work/files
bin/vt 052c0687f023564a3c31fb652bea3405341272cb --json

Tip: Search both UTF-8 and UTF-16 when grepping for the hostname; the config strings are wide.

Click flag to reveal 107.172.232.84:2468

Attack Summary

PhaseAction
ExecutionUser opens Conf.js from Downloads; wscript runs it
ExecutionJScript drops and runs temp_993805.bat in the user’s Temp folder
PersistenceObfuscated batch loader copied into the Startup folder as 5c74.bat
Defense EvasionPowerShell stage patches the AMSI function in memory
Defense EvasionAES and gzip blobs in the batch are decrypted into two PE files
Defense Evasion.NET loader decrypts an embedded resource and loads the RAT in memory
Command and ControlRAT config points at a DuckDNS host on port 2468; containment stopped the connection

IOCs

TypeValue
FileDownloads\Conf.js
FileUsers\Administrator\AppData\Local\Temp\temp_993805.bat
FileC:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\5c74.bat
Resource namexxxxxxxxxxxxxxxxxxxxxxxxxxxx.exe
AES keyALWIGeOnxudniHR2K4CNZmnaEZffXt6zKsRFoAM2/mA=
AES IVJXYbOTuuz3cErOl30kAKhw==
SHA-1 (decrypted payload)052c0687f023564a3c31fb652bea3405341272cb
Mutex variableTerritories
Domainapostlejob3[.]duckdns[.]org
C2107.172.232[.]84:2468

MITRE ATT&CK

TechniqueIDDescription
User Execution: Malicious FileT1204.002User opens Conf.js from Downloads
Command and Scripting Interpreter: JavaScriptT1059.007wscript runs the JScript dropper
Command and Scripting Interpreter: Windows Command ShellT1059.003Dropped and Startup batch loaders
Command and Scripting Interpreter: PowerShellT1059.001Stage that patches AMSI and decrypts the PEs
Boot or Logon Autostart Execution: Registry Run Keys / Startup FolderT1547.0015c74.bat in the Startup folder
Impair Defenses: Disable or Modify ToolsT1562.001In-memory AMSI patch
Obfuscated Files or InformationT1027Junk variables, chunked base64, encrypted resource
Deobfuscate/Decode Files or InformationT1140AES-CBC and gzip decoding at runtime
Reflective Code LoadingT1620Payload loaded from memory by the .NET loader
Dynamic ResolutionT1568C2 hostname on a dynamic DNS provider

Defender Takeaways

Script files in Downloads shouldn’t run under wscript. A .js double-clicked from a user folder spawning a dropped .bat is a short, high-signal chain. Associate .js with a text editor by policy, or block wscript and cscript from user-writable paths with WDAC or AppLocker.

AMSI tampering needs its own detection. The batch stage overwrote an AMSI function in memory before decrypting anything, which blinds script scanning for the rest of the chain. Script block logging and EDR telemetry on VirtualProtect against amsi.dll catch it at the first stage rather than the last.

Startup-folder writes by script interpreters are a clean alert. The loader copied itself into the Startup folder seconds after launch. File-creation monitoring on that path, filtered to non-installer processes, would have flagged it immediately.

Prefetch and the MFT carry the whole timeline. The execution time, the first dropped file and the persistence file all came from PECmd and MFTECmd output on a single image. Make sure both stay enabled and collected on endpoints, since the payload itself only exists encrypted.

Recover C2 config even when containment wins. The connection never completed, yet the payload config gave a hostname and port, and a vendor report completed the IP. Feed config-derived indicators to the threat intel platform, not just observed network traffic.

Conclusion

The RAT never reached its C2, but it had already patched AMSI, decrypted its payload in memory and planted a Startup-folder loader. Every stage hid behind a layer of encryption, so the early signals were the script launch, the dropped batch and the persistence write, all visible in prefetch and the MFT.