skip to content
secrary[dot]com

Remcos RAT - Analysis

/

Introduction

Remcos Remote Control - Control your computers remotely, anywhere in the world.

In this analysis, I will explore the Remcos Remote Access Trojan (RAT), focusing on its behavior, how it operates, and techniques for unpacking it.

Overview

I am using the free version of Remcos along with MPRESS as a packer.

remcos

You can download a sample from hybrid-analysis.com.

Packing Analysis

As we can see, it’s packed with MPRESS:

protID

Let’s examine its behavior using Procmon:

procmon

The malware creates a folder named remcos and a PE file called remcos.exe in the %APPDATA% directory. It uses the Run key as a persistence method and also creates a file called install.bat in the %TEMP% directory.

From hybrid-analysis, we obtain similar information:

hybrid-analysis

The install.bat file pings the C&C server, executes remcos.exe from the %APPDATA% directory, and then removes itself:

install.bat

After this, we can connect to our C&C server and control the machine:

image

Unpacking Process

Let’s dive deeper and open it in IDA Pro:

ida

We notice a few functions, a suspicious entry point, and high entropy, which are signs of a packed executable:

imports entropy

Let’s open it in x32dbg and unpack it.

MPRESS is a generic packer that reduces the size of programs and libraries, improving load times from slow media or networks. It is not designed for protecting applications, making it relatively easy to unpack.

At the entry point, we see the pushad instruction, which is common for packers like UPX. This instruction saves all register values on the stack, and after unpacking, the application restores them using the popa(d) instruction.

x32dbg

There are various methods to unpack such files. One approach is to set a hardware breakpoint on any pushed register values and run the program:

unpack

We hit the popad instruction:

image

Let’s follow the jmp instruction; there are likely unpacked instructions:

image

We see except_handler3 from C++ and several other normal functions, indicating that it has been unpacked.

Let’s dump it using x32dbg’s built-in plugin Scylla:

  • Plugin -> Scylla -> IAT Autosearch -> Get Imports -> Dump -> Fix Dump
dump

Now, let’s open it in IDA Pro:

image

We can see WinMain and std functions, confirming that it has been unpacked. You can download the unpacked version from hybrid-analysis.

Detailed Analysis

In the WinMain function, it checks command line arguments, and if the -l option is present, it creates a lic.txt file:

image

At 00403BC7, it creates a Mutex, and if one already exists, it terminates itself:

image

At 00403BDE, it retrieves function addresses using LoadLibraryA and GetProcAddress. At 00403C09, it gets the product name from SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName, and at 00403C28, it checks if the process is running on a 64-bit Windows system:

image image

It checks if the process is executed with admin privileges:

image

This information is likely sent to the C&C server.

At 00403D5D, the function retrieves the directory path based on configuration:

image

The function at 00403DEB creates the remcos directory and copies files into it:

image

It creates install.bat in the %TEMP% directory:

image

The install.bat file is filled with the following code:

image

After successful execution, the application exits:

image

The install.bat file creates a new instance of remcos.exe from the %APPDATA% directory:

image

To understand what happens when install.bat executes remcos.exe, we must patch the instruction at 00403D7A or manually jump to loc_403DFA:

image

At 00403E82, the function adds another entry in the registry:

image

The value of EXEpath is the encrypted path to the original executable:

Before encryption:

image

Before setting the value:

image

The application disables DEP and calls a function that appears to be a loop:

image

Let’s examine the function called at 00403F14. It seems to set up a connection:

image

The most critical call is at 00406277:

image

The recv_and_exec function receives commands and executes them:

image

The lpStartAddress is passed as an argument to recv_and_exec. Let’s investigate it; the RunCommands function at 00406371 is the core of the RAT, executing commands from the C&C server.

C&C Panel

This is the C&C panel:

image

The RunCommands function acts like a switch statement, with the following possible values: filemgr, downloadfromurltofile, downloadfromlocaltofile, getproclist, prockill, getwindows, closewindow, maxwindow, restorewindow, closeprocfromwindow, execcom, consolecmd, openaddress, initializescrcap, freescrcap, deletefile, close, uninstall, updatefromurl, updatefromlocal, msgbox, keyinput, mclick, OSpower, getclipboard, setclipboard, emptyclipboard, dlldata, dllurl, initfun, initremscript, initregedit, renamebck, initsocks, SetSuspendState.

Let’s investigate some of them:

  • filemgr uses FindFirstFileW and FindNextFileW to list files:
image

Inside filemgr, there are several other commands, such as newfolder, upload, download, etc.

image

C&C Communication

image
  • downloadfromurltofile downloads from a URL and executes it:
image

The downloadfromurltofile command downloads a file from the C&C server, saves it to the %TEMP% directory, and executes it:

image image

Process Management

  • getproclist lists processes using CreateToolhelp32Snapshot, Process32FirstW, and Process32NextW functions:
image
  • prockill determines a process using the TerminateProcess function:
image
  • Window Management: Commands like getwindows, closewindow, maxwindow, restorewindow, and closeprocfromwindow are used to manipulate windows:
image image
  • Command Execution: The execcom command executes commands:
image
  • Console Access: The consolecmd command opens a command prompt:
capture
  • Web Access: The openaddress command opens a web page:
image
  • Screen Capture: The initializescrcap command uses various image functions (MSDN “MSDN”) to capture the screen. The freescrcap command is called when we close the Capture window in the C&C panel:
image
  • File Management: The deletefile and close commands are straightforward:
image
  • Uninstallation: The uninstall command removes the value from the Run key:
image

It creates Uninstall.bat in the %TEMP% directory and runs it:

image
  • Updates: The updatefromurl command downloads a file from the internet, replacing all old files and registry entries:
image

It then runs update.bat:

image
  • Local Updates: The updatefromlocal command is similar to updatefromurl:
image
  • Message Box: The msgbox command calls MessageBoxA:
image
  • Keylogging: The keyinput and mclick commands are likely used in keylogging, which is not available in the free edition:
image
  • Clipboard Management: The getclipboard, setclipboard, and emptyclipboard commands perform corresponding actions:
image
  • DLL Injection: The dlldata and dllurl commands download a DLL from the attacker’s machine and the internet:
image

It injects the DLL without writing it to disk using CreateFileMappingA and MapViewOfFileEx:

image

I suspect it uses reflective DLL injection, with LoadLibraryA and GetProcAddress used to retrieve imports for the injected DLL:

image
  • Registry Manipulation: The initregedit command performs operations in the registry:
image

It uses functions from Shlwapi.dll to manipulate the registry:

image
  • Script Execution: The initremscript command executes scripts from the C&C server:
image

It executes VBScript:

image
  • ID Management: The renamebck command changes the value of the name key at Software\Remcos-MUTEXval, which is used as an ID:
image
  • Power Management: The OSpower command is used to sleep, shut down, log off, hibernate, or restart the infected machine.

The sleep command uses SetSuspendState:

image

The shutdown command uses ExitWindowsEx:

image
  • Proxy Management: The initsocks command is used to obtain a SOCKS proxy:
image

Data Transmission

Let’s see how it sends files and information. This is the data before the encryption routine:

senddatabefire

This is the encryption routine:

encryptfunction

This is the data after encryption:

senddataafterenc

We can inject into the malicious application and observe the data before it is sent using Echo Mirage:

encryptedechomirage

This is the same data.

Conclusion

I may have overlooked something due to my limited knowledge. If you find anything interesting, please contact me.

That’s all for now. I’m new to reversing malware, and any feedback would be helpful for me.