Castle RAT Client Malware: Tactics, Techniques, and Tradecraft
Detection stack
- AIDR
- Alert
- ETL
- Query
Summary
CastleRAT is a remote access Trojan first observed in March 2025, shipped in both Python and compiled C variants. It gathers system metadata, keystrokes, clipboard contents, screenshots, and media device details, then exfiltrates this information to a C2 server using RC4 encryption. The malware can fetch extra payloads, launch them via rundll32, and establish persistence through scheduled tasks and UAC bypass methods.
Investigation
The Splunk Threat Research Team reverse-engineered the Python and C implementations, mapping their behaviors to MITRE ATT&CK techniques including system discovery, keylogging, screen capture, audio/video device enumeration, dead-drop resolvers, and handle duplication for privilege escalation. The research emphasized CastleRAT’s reliance on legitimate Windows binaries (rundll32, ComputerDefaults.exe) and its use of www.ip-api.com to obtain the public IP address.
Mitigation
Defenders should detect suspicious outbound connections to unfamiliar domains, RC4-encrypted traffic patterns, and executions of rundll32 using ordinal-based DLL loads. Monitor for scheduled tasks created to start CastleRAT, UAC bypass attempts leveraging ComputerDefaults.exe, and processes launched with muted-audio browser flags. Block access to known dead-drop resolver locations, including abused Steam Community pages.
Response
When CastleRAT activity is identified, isolate the impacted host, kill the malicious processes, and remove any associated scheduled tasks or persistence artifacts. Collect forensic evidence such as process hierarchies, command-line arguments, and registry changes. Perform a comprehensive hunt for additional DLL plugins and C2 channels, then roll out remediation and hardening measures across the wider environment.
“`mermaid graph TB %% Class definitions classDef technique fill:#e6f7ff %% Node definitions t1016_001[“<b>Technique</b> – T1016.001 System Network Configuration Discovery<br/>Collects system details such as computer name, username, machine GUID, OS version, and public IP address to send to C2”] class t1016_001 technique t1115[“<b>Technique</b> – T1115 Clipboard Data<br/>Harvests data from the Windows clipboard and exfiltrates it, often using simulated paste actions”] class t1115 technique t1036[“<b>Technique</b> – T1036 Masquerading<br/>Names dropped files and environment variables to appear as legitimate Python or Java components”] class t1036 technique t1056_001[“<b>Technique</b> – T1056.001 Input Capture: Keylogging<br/>Intercepts keystrokes, writes them to a local file, encrypts the file with RC4, and sends it to the attacker”] class t1056_001 technique t1559[“<b>Technique</b> – T1559 Inter-Process Communication<br/>Spawns a hidden shell process with its standard streams redirected through anonymous pipes, allowing remote command execution without a visible console”] class t1559 technique t1123[“<b>Technique</b> – T1123 Audio Capture<br/>Enumerates media capture devices via Media Foundation”] class t1123 technique t1125[“<b>Technique</b> – T1125 Video Capture<br/>Enumerates media capture devices via Media Foundation”] class t1125 technique t1218_011[“<b>Technique</b> – T1218.011 System Binary Proxy Execution: Rundll32<br/>Loads malicious DLL export function by ordinal”] class t1218_011 technique t1055_001[“<b>Technique</b> – T1055.001 Process Injection: Dynamic-link Library Injection<br/>Uses rundll32.exe to load a malicious DLL”] class t1055_001 technique t1547_010[“<b>Technique</b> – T1547.010 Boot or Logon Autostart Execution: Port Monitors<br/>Downloads additional DLL plugins from C2, decrypts them with RC4, and loads them”] class t1547_010 technique t1053[“<b>Technique</b> – T1053 Scheduled Task/Job<br/>Creates a scheduled task to launch malware at startup”] class t1053 technique t1113[“<b>Technique</b> – T1113 Screen Capture<br/>Periodically captures screenshots and exfiltrates them”] class t1113 technique t1102_001[“<b>Technique</b> – T1102.001 Web Service: Dead Drop Resolver<br/>Retrieves configuration or payloads from benign external websites”] class t1102_001 technique t1127[“<b>Technique</b> – T1127 Trusted Developer Utilities Proxy Execution<br/>Uses ComputerDefaults.exe and handle duplication to bypass UAC and execute code with elevated privileges”] class t1127 technique t1027[“<b>Technique</b> – T1027 Obfuscated Files or Information<br/>Uses RC4 encryption for command and data payloads”] class t1027 technique t1048_001[“<b>Technique</b> – T1048.001 Exfiltration Over Alternative Protocol: Symmetric Encrypted Non C2 Protocol<br/>Sends encrypted data to C2”] class t1048_001 technique t1132_001[“<b>Technique</b> – T1132.001 Data Encoding: Standard Encoding<br/>Encodes data before transmission”] class t1132_001 technique %% Connections showing attack flow t1016_001 –>|leads_to| t1115 t1115 –>|leads_to| t1036 t1036 –>|leads_to| t1056_001 t1056_001 –>|leads_to| t1559 t1559 –>|leads_to| t1123 t1123 –>|leads_to| t1125 t1125 –>|leads_to| t1218_011 t1218_011 –>|leads_to| t1055_001 t1055_001 –>|leads_to| t1547_010 t1547_010 –>|leads_to| t1053 t1053 –>|leads_to| t1113 t1113 –>|leads_to| t1102_001 t1102_001 –>|leads_to| t1127 t1127 –>|leads_to| t1027 t1027 –>|leads_to| t1048_001 t1048_001 –>|leads_to| t1132_001 “`
Attack Flow
Detections
Possible Execution by Scheduled Task Activity with PowerShell (via powershell)
View
Steam Communtiy DNS Request Perfomed By Suspicious Process (via dns_query)
View
IOCs (HashSha256) to detect: Behind the Walls: Techniques and Tactics in Castle RAT Client Malware
View
Possible Execution by Scheduled Task Activity with PowerShell (via powershell)
View
Steam Communtiy DNS Request Perfomed By Suspicious Process (via dns_query)
View
Simulation Execution
Prerequisite: The Telemetry & Baseline Pre‑flight Check must have passed.
Rationale: This section details the precise execution of the adversary technique (TTP) designed to trigger the detection rule. The commands and narrative MUST directly reflect the TTPs identified and aim to generate the exact telemetry expected by the detection logic. Abstract or unrelated examples will lead to misdiagnosis.
-
Attack Narrative & Commands:
- Stage 1 – Deploy CastleRAT binary: The attacker copiesÂ
CastleRAT.exe to the victim’sÂ%APPDATA% directory to blend with user data. - Stage 2 – Execute keylogging: Using a small C#‑in‑memory loader, the attacker invokesÂ
SetWindowsHookEx to install a low‑level keyboard hook, causing Sysmon to record the API in the CallTrace of the process creation event. - Stage 3 – Privilege escalation: The same loader then callsÂ
DuplicateHandle to duplicate a handle from a privileged system process (e.g.,Âlsass.exe), enabling the malware to run with SYSTEM rights. Both API calls appear in the same Sysmon CallTrace, satisfying the detection rule’s criteria.
- Stage 1 – Deploy CastleRAT binary: The attacker copiesÂ
-
Regression Test Script:
# ------------------------------------------------- # CastleRAT simulation – triggers SetWindowsHookEx and DuplicateHandle # ------------------------------------------------- $castlePath = "$env:APPDATA\CastleRAT.exe" # 1. Drop a minimal stub that loads the real payload (simulated here) $payload = @" using System; using System.Runtime.InteropServices; public class Loader { [DllImport("user32.dll")] public static extern IntPtr SetWindowsHookEx(int idHook, IntPtr lpfn, IntPtr hMod, uint dwThreadId); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool DuplicateHandle(IntPtr hSourceProcessHandle, IntPtr hSourceHandle, IntPtr hTargetProcessHandle, out IntPtr lpTargetHandle, uint dwDesiredAccess, bool bInheritHandle, uint dwOptions); public static void Execute() { // Install a low‑level keyboard hook (WH_KEYBOARD_LL = 13) SetWindowsHookEx(13, IntPtr.Zero, IntPtr.Zero, 0); // Duplicate a handle from the current process (simulated) IntPtr dupHandle; DuplicateHandle((IntPtr)-1, (IntPtr)0x1234, (IntPtr)-1, out dupHandle, 0, false, 0); } }
“@
# Compile the C# code on‑the‑fly
Add-Type -TypeDefinition $payload -Language CSharp
# Copy the current PowerShell process (acts as CastleRAT.exe) to the target path
Copy-Item -Path $PSCommandPath -Destination $castlePath -Force
# Execute the malicious payload
[Loader]::Execute()
# Keep the process alive briefly to ensure Sysmon logs the call stack
Start-Sleep -Seconds 5
-
Cleanup Commands:
# Remove the simulated CastleRAT binary Remove-Item -Path "$env:APPDATA\CastleRAT.exe" -Force # Optionally unload any hooks (not needed for the stub, but included for completeness) # No explicit unload required for the SetWindowsHookEx call with NULL callback used above.