Remcos RAT Analysis: Multi-Stage Delivery Chain

Remcos RAT Analysis: Multi-Stage Delivery Chain

April 3, 2025
Fuad Aliyev
Malware Analysis
Reverse Engineering
RAT

Initial Discovery and Timeline

This analysis was conducted within 24 hours of the malicious script appearing in the wild, providing insights into a fresh Remcos RAT campaign. At the time of analysis, VirusTotal showed detection by only 9 antivirus engines, and the second-stage payload server remained active and accessible.

Stage 1: VBScript Obfuscation Analysis

File Size Inflation Technique

The initial VBScript file exhibits an unusually large size due to repetitive padding - the same 10 lines repeated thousands of times. This serves dual purposes:

  1. Legitimacy Appearance: Large file sizes can appear more legitimate to cursory inspection
  2. Obfuscation Concealment: Hiding the actual malicious code within the padding

Character Encoding Deobfuscation

The padding consists of ASCII character codes that can be converted to their corresponding characters using standard ASCII tables.

Pattern Recognition in Obfuscated Code

The obfuscated payload reveals a repeating pattern: "⏳लბ⣿༑₫ᨑԿ🖲ᅫҌ⊣ሒȪ⟚"

This pattern is processed by the categorised(ByVal inputText) function, which removes the repeating character sequences to reveal the actual payload.

Dynamic Deobfuscation Technique

Rather than manually reverse-engineering the deobfuscation algorithm, I modified the script to output the deobfuscated content by replacing dozens = categorised(dozens) with WScript.Echo categorised(dozens) and executing it safely with cscript.exe.

Stage 2: PowerShell Payload Analysis

Base64 Decoding Process

The deobfuscated VBScript reveals a PowerShell command that requires two transformations:

  1. Character Substitution: Replace '#' characters with 'A'
  2. Base64 Decoding: Convert the resulting string from Base64 to plaintext

Instead of using external tools, I executed the PowerShell code after removing Invoke-Expression to safely observe the decoded payload.

Second-Stage Download Mechanism

The decoded PowerShell script downloads a PNG file from a remote server. Although the malicious server was taken down within 24 hours, I captured the payload during the active period and uploaded it to MalwareBazaar for research purposes.

Stage 3: Steganographic Payload Extraction

Hidden DLL in PNG File

The downloaded PNG file contains embedded data between <<BASE64_START>> and <<BASE64_END>> markers. After extraction and Base64 decoding, this reveals a .NET DLL file.

I modified the PowerShell code to save the extracted DLL using:

[System.IO.File]::WriteAllBytes("C:\dnlib_image.dll", $cleared)

DLL Analysis with dnSpy

Loading the extracted DLL in dnSpy reveals it as Microsoft.Win32.TaskScheduler, Version=1.1.0.0 with an embedded dnlib component for .NET manipulation.

VM Detection Capabilities

The DLL includes VM detection functionality similar to Robson Felix's VMDetector. However, this particular sample only checks for "qemu" strings, making detection evasion relatively straightforward.

Note: Despite having VM detection capabilities, this specific malware instance doesn't actively use this functionality during execution.

Stage 4: Core Malware Execution

VAI Function Analysis

The malicious code centers around the VAI function, which orchestrates the main payload execution:

Linguistic Analysis: Several variable names appear in Spanish, potentially indicating the malware author's language preference, though this isn't conclusive evidence.

Persistence Mechanism Analysis

The startup_onstart function implements persistence through file system operations:

if (flag12) { bool flag13 = !File.Exists(Path.Combine(caminho, nomedoarquivo + \uE11C.\uE000(12567) + extençao)); bool flag14 = flag13; if (flag14) { Process.Start(new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, FileName = \uE11C.\uE000(12607), // "cmd.exe" Arguments = string.Concat(new string[] { \uE11C.\uE000(12599), // "/C copy *." extençao, // "vbs" \uE11C.\uE000(12770), // " \"" Path.Combine(caminho, nomedoarquivo), // @"C:\ProgramData" + "millipascals" \uE11C.\uE000(12567), // "." extençao, // "vbs" \uE11C.\uE000(12282) // "\"" }) }).WaitForExit(); } Loader.ExecutarMetodoVAI(taskname, caminho, nomedoarquivo, extençao); }

Translated Command: cmd.exe /C copy *.vbs "C:\ProgramData\millipascals.vbs"

This copies the VBScript to a persistent location for future execution.

Stage 5: UAC Bypass and Privilege Escalation

Resource Loading and Execution

The ExecutarMetodoVAI function loads an embedded resource ending with "UAC.dll":

string text = Array.Find<string>(Assembly.GetExecutingAssembly().GetManifestResourceNames(), new Predicate<string>(Loader.<>c.<>9.\uE000)); byte[] array; using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text)) { using (MemoryStream memoryStream = new MemoryStream()) { manifestResourceStream.CopyTo(memoryStream); array = memoryStream.ToArray(); } } Assembly assembly = Assembly.Load(array);

CMSTP.exe UAC Bypass Technique

The UAC.dll implements a sophisticated UAC bypass using cmstp.exe:

Command Generation:

cmd.exe /c powershell -Command "schtasks /Create /TN 'blinkered' /TR 'wscript.exe C:\ProgramData\millipascals.vbs' /SC ONSTART /RL HIGHEST /RU SYSTEM /F"

INF File Template Abuse:

  1. Creates a malicious INF file in the temporary directory
  2. Modifies the REPLACE_COMMAND_LINE placeholder in the INF template
  3. Executes C:\Windows\system32\cmstp.exe /au "<inf_file_path>"

This technique leverages Windows' trusted cmstp.exe binary to execute the malicious command with elevated privileges, bypassing UAC warnings.

Stage 6: Process Injection and Final Payload

MSBuild.exe Process Hollowing

The malware performs process injection using Microsoft Build Engine (MSBuild.exe) as the target process:

Injection Process:

  1. Create new MSBuild.exe process in suspended state
  2. Allocate memory space within the target process
  3. Write malicious code starting at address 0x400000
  4. Resume thread execution with modified entry point

Payload Reconstruction

I extracted the injected data segments and combined them to reconstruct the final executable:

copy /b to400000.bin+to401000.bin+to459000.bin+to472000.bin+to478000.bin+to47D000.bin combined.exe

The reconstructed file reveals a Microsoft Visual C++ 8 executable containing the core Remcos RAT functionality.

Key Function Analysis

Critical function identified: FUN_0040e560(0x400000,0,pcVar7) - likely the main execution entry point containing RAT capabilities.

Command and Control Analysis

Network Infrastructure

Primary C2 Servers:

  • relentlesswicked.duckdns.org
  • relentless.webredirect.org

Both servers were offline during analysis, preventing live C2 communication observation.

Capability Assessment

String analysis reveals comprehensive RAT functionality:

  • Remote Access Trojan capabilities
  • Keylogger functionality
  • Information Stealer modules
  • System Logger components

Technical Evasion Techniques

Anti-Analysis Measures

Dynamic API Resolution: Uses GetProcAddress to resolve function addresses at runtime, complicating static analysis

Process Hollowing: Injects into legitimate Windows processes (MSBuild.exe) to evade process-based detection

UAC Bypass: Leverages trusted Windows binaries for privilege escalation without user prompts

Multi-Stage Delivery: Complex delivery chain makes automated analysis challenging

Mitigation and Detection

Indicators of Compromise (IOCs)

File Paths:

  • C:\ProgramData\millipascals.vbs

Network Indicators:

  • relentlesswicked.duckdns.org
  • relentless.webredirect.org

Scheduled Tasks:

  • Task Name: blinkered
  • Command: wscript.exe C:\ProgramData\millipascals.vbs

Detection Strategies

Behavioral Detection: Monitor for cmstp.exe execution with suspicious INF files

Network Monitoring: Block access to identified C2 domains

Process Monitoring: Detect unexpected MSBuild.exe processes with anomalous memory patterns

Conclusion

This Remcos RAT campaign demonstrates sophisticated multi-stage delivery techniques combining steganography, UAC bypass, and process injection. The malware's use of legitimate Windows tools like cmstp.exe and MSBuild.exe for malicious purposes highlights the importance of monitoring trusted binary abuse.

The analysis reveals a well-engineered attack chain designed to evade detection through multiple layers of obfuscation and legitimate process abuse. Organizations should implement behavioral detection strategies that focus on process relationships and suspicious system tool usage patterns.

Reference: The legitimate Remcos RAT tool is available at Breaking Security for educational and research purposes.