Coauthored by Karthickkumar Kathiresan of Uptycs Threat Research Team
In a sophisticated twist to the traditional sideloading tactics, the Quasar RAT introduces a novel dual DLL sideloading technique, ingeniously utilizing two commonly trusted Microsoft files: "ctfmon.exe" and "calc.exe." Such a method not only leverages the inherent trust these files enjoy within the Windows ecosystem but also presents an increased challenge to threat detection mechanisms. This article dives deep into the meticulous design and execution of these sideloading techniques, illustrating how they stealthily introduce, deploy, and run malicious payloads under the radar.
QuasarRAT, also known as CinaRAT or Yggdrasil, is a lightweight remote administration tool written in C#. This tool is openly accessible as a GitHub project. This tool is capable of various functions such as gathering system data, running applications, transferring files, recording keystrokes, taking screenshots or camera captures, recovering system passwords, and overseeing operations like File Manager, Startup Manager, Remote Desktop, and executing shell commands.
Windows users, system administrators, and cybersecurity professionals need to be on high alert. The use of legitimate processes to cloak malicious activities helps them bypass traditional security measures. Hence, the need for advanced threat detection and response mechanisms becomes paramount.
Given the prevalence of sideloading techniques in malware campaigns, it's vital to understand their mechanisms to defend against them effectively. The case of QuasarRAT provides an insightful example.
Historical context:
In 2022, we detected the Qbot malware employing a DLL sideloading attack using "calc.exe." Such tactics are not new but seeing them evolve and get adopted by other malware strains shows the adaptability of threat actors. Now, in 2023, a strikingly parallel method in two phases has been observed with the QuasarRAT malware.
Step-by-step breakdown:
1. Initial contact and execution:
The threat actor begins by employing DLL side-loading techniques. Interestingly, they opted for two distinct Microsoft files for their attack: "ctfmon.exe" and "calc.exe."2. Payload release:
This 'stage 1' payload plays a dual role. It is responsible for releasing both the legitimate "calc.exe" file and the malevolent DLL into the system.
3. Second phase of attack:
4. Process hollowing:
With the "QuasarRAT" payload now residing in the computer’s memory, the payload employs a technique known as 'process hollowing.' Here, it embeds itself into a legitimate system process, further camouflaging its malicious intentions and making detection more challenging.
Figure 1 depicts the QuasarRAT workflow.
We first verified the ISO file and after a successful extraction, we obtained three separate files:
Figure 2 depicts the Process flow of the new QuasarRAT.
When the binary file "eBill-997358806.exe" is run, it initiates the loading of a file titled "MsCtfMonitor.dll" (name masqueraded) via dll side loading technique, within which malicious code is concealed.
Within the "MsCtfMonitor.dll" file, there exists a resource section containing encrypted data.
The resource section (RCDATA:400) has encrypted data of size 5AC00 hex bytes.
This data is accessed via a sequence of APIs as seen in Figure 4.
To decrypt the data, the key size is F2 hex bytes and Systemfunction032 API is used to decrypt the encrypted data. This is an undocumented API that indirectly calls BCryptGeneratesymmetrickey, CryptEncrypt, and CryptDestroyKey to decrypt data by RC4 where the key is also stored in .rsrc section (RCDATA: 401)
After decryption, the resource data is decrypted and give’s PE file which is stage 1 "FileDownloader.exe."
This PE File is then injected into Regasm.exe by the following sequence of API : CreateProcess, GetThreadContext, ReadProcessMemory, VirtualAllocEx and WriteProcessMemory, GetThreadContext, SetThreadContext and ResumeThread.
In Figure 7 we can observe the presence of the stage 1 payload within the memory of the RegAsm process.
The stage 1 payload is a 64-bit MSIL binary file, which includes a resource section containing three binaries stored in a zip archive format.
The stage 1 payload is equipped with code to unzip this archive successfully, depositing all the files into the Public Pictures folder.
The following files are placed in the Public Pictures folder:
1. Calc.exe - Legitimate windows file
2. Secure32.dll - Malicious DLL
3. Winsecu32.dll - Legitimate windows file
Next, "Calc.exe" was run using the command "c:\Users\Public\Pictures\Calc.exe /quit."
"/quit" serves as an argument or parameter for the Calculator executable, instructing it to open and promptly close upon launch.
When you run calc.exe, it loads a malicious DLL named "Secure32.dll." again via Dll-side loading technique. This DLL contains an encrypted resource section.
This resource data is accessed via a sequence of APIs like previous method mentioned as in the stage 1 (Figure 4)
To decrypt the data, Key size is 2F hex bytes and Systemfunction32 API is used to decrypt the encrypted data same as in the first case which again gives a PE file.
This PE File is now injected into memory space Regasm.exe via process hollowing. The API sequence followed is the same as in stage 1. But here, while calling VirtualAllocEx, the default memory address of regasm.exe (0x400000) is explicitly passed to hollow the regasm.exe and replace it with the malicious PE file.
By getting the dump of the above region(Figure 11), we can analyze that this PE file is an MSIL executable obfuscated by Smart assembly.
Looking at the copyright of the file as "Copyright © MaxXor 2020", it looks like it might be inspired by open-source Quasar RAT by MaxXor.
After deobfuscating, we can see commands executed in the function names which include keylogging, file transfer, shell execute, etc.
It also drops a .bat script to create the restart batch file in the %Temp% directory which is executed and runs chcp 65001 && ping -n 10 localhost.
Figure 13 - .bat file
The RAT creates a socket connection to CNC (3[.]94[.]91[.]208 >> ec2-3-94-91-208[.]compute-1[.]amazonaws.com) where it sends the victim's info such as IP, Country code etc.
After deobfuscating more content, we can see strings related to Quasar RAT such as Quasar Server etc.
We can see a lot of base64 content also in the memory which on decoding gives various strings such as:
SELECT * FROM Win32_OperatingSystem WHERE Primary='true'
SELECT * FROM Win32_BaseBoard
SELECT * FROM FirewallProduct
SELECT * FROM Win32_Processor
SELECT * FROM AntivirusProduct
By looking at the above strings we can understand that then the RAT is querying for the AntiVirusProduct and Firewall WMI class. The Quasar RAT payload also looks for BIOS infrastructure, GPU details, hostname , etc.
Quasar RAT is an open-source remote access trojan (RAT) that has been widely used by threat actors due to its powerful techniques. Quasar RAT capabilities include Keylogging, stealing passwords, taking screenshots, reverse proxy, Downloading and uploading files etc. We can see in the below figure Reverse proxy functionalities inside our final payload.
The malware also establishes a persistent entry within the Windows registry.
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\WindowsCalculator “c:\Users\Public\Pictures\Calc.exe /quit”
In addition to having YARA built in and being armed with other advanced detection capabilities, Uptycs XDR users can easily scan for QuasarRAT. XDR contextual detection provides important details about identified malware. Users can navigate to the toolkit data section in the detection screen, and then click a detected item to reveal its profile.
Figure 17 - Uptycs Detection
File Name |
Md5 |
ISO |
e4eb623a0f675960acb002d225c6f1d6 |
eBill-997358806.exe |
B625C18E177D5BEB5A6F6432CCF46FB3 |
monitor.ini |
7074832F0EFB8A2130B1935EAE5A90D6 |
MsCtfMonitor.dll |
B0DB6ADA5B81E42AADB82032CBC5FD60 |
Stage 1/ FileDownloader.exe |
32DE5C2E0BA35CEAC3C515FA767E42BF |
Calc.exe |
5da8c98136d98dfec4716edd79c7145f |
Secure32.dll |
d07e4afd8f26f3e2ce4560e08b7278fb |
Winsecu32.dll |
f11c63cb70a726f1f0b6accd5934e83 |
Final Payload/Remotify Client |
532AF2DB4C10352B2199724D528F535F |
3[.]94[.]91[.]208 |
ec2-3-94-91-208[.]compute-1[.]amazonaws.com |
Thanks to the Threat Hunting Team of Uptycs for sharing the IOC.