• Skip to primary navigation
  • Skip to main content
  • Skip to footer
lab52

lab52

The threat intelligence division of S2 Grupo

  • Home
  • Faq
  • Blog
  • About
  • Contact

GuLoader as the Gatekeeper of AgentTesla: A Comprehensive Analysis

May 22, 2023

The malware team at Lab52 has a saying that our colleages know well: “We want your malware”. On this occasion, the Theat Intelligence team gifted us a file that appeared to be a dropper. The file was already flagged by 15 antivirus engines on VirusTotal as malicious.

Target file in VirusTotal

Among the open files, the results of specific calls to Powershell.exe are displayed.

VirusTotal information from the sandboxes

Due to its context, it could be interesting to investigate it further, so we eagerly began analyzing it with a curious mindset.

This post provides a comprehensive analysis of the GuLoader malware, its role as a gatekeeper for the notorious AgentTesla stealer, and the entire infection process from start to finish. GuLoader employs sophisticated anti-analysis techniques, which pose challenges to researchers. However, through diligent analysis, the stages leading to the final payload, AgentTesla, are uncovered. While the initial sample is publicly accessible, the subsequent artifacts used to trigger different stages remain elusive in public sources.

Attack chain analysed in this post

First checks on the initial script

The original name of the .vbs file is “Hitni zahtjev za prijedlog za programski ured Vijeca Europe u Skoplju 26.04.2023”, meaning “Urgent request for proposal for the program office of the Council of Europe in Skopje 26.04.2023“.

The code consists of nearly 900 lines, including comments scattered throughout. The first noticeable element in the script is a variable named “Hent,” which corresponds to “WScript.Shell” This suggests that the variable may be invoked later for code execution purposes.

Throughout the script, there is repeated concatenation of new strings to the variable V8. This technique can be employed to make the task of the analyzing analyst more challenging.

WScript.Shell

When searching through the document for the variable name “Hent,” a match is found on line 666 – the number of the beast. In this line, an assignment to the variable “Foret” is observed, which, like “Hent,” is equivalent to “WScript.Shell”

Foret

After this, the variable “Teleg” is found, in which the concatenated string “powershell” is observed followed by the variable “V8” enclosed in quotes.

Following that, the variable “Foret” is present, which will execute the content of the variable “Teleg”.

Teleg assignation

Therefore, it is expected that the script will execute PowerShell commands, which aligns with the preliminary information from VirusTotal.

At the end of the code, there is a signature that has also been used to search for related files in VirusTotal. However, in this case, nothing notable has been found that would expedite this analysis. This means that there is manual analysis work to be done.

Stage 1 – Downloader

When double-clicking on the “Hitni zahtjev za prijedlog za programski ured Vijeca Europe u Skoplju 26.04.2023.vbs” file, a “wscript” process is launched, which ultimately executes “powershell.exe”.

Script powershell (ProcessHacker)

In order to make the code more readable, it has been formatted into a separate document. Upon observing the code, an evident alteration of the strings can be noticed. The “Regent9” function will be responsible for converting the strings, making them readable.

Regent9

Starting from the first variable “Pluvine,” the resulting string is a URL.

Pluvine variable and URL

A successful download of the file referenced in the URL has been completed.

Downloading Genicula.prm

The domain melsicon.com (195.191.148.219) is a legitimate domain created 12 years ago, which does not have visible history of being used by malware in utilities such as VirusTotal, at the time of creating this post. When reviewing the content of the downloaded file, it is observed that it is encoded in base64.

Genicula.prm

The downloaded file remains the same across different executions and maintains the same hash, therefore, it can be considered as an Indicator of Compromise (IOC).

NameHash(256)
Genicula.prm3f0a012d75144686917f5a1ac151b03894c662783c2b9ed4867c02d39e682545

However, the execution does not continue, and a typical message representative of anti-analysis techniques is displayed.

Message displayed during the execution

This type of message has been seen, for example, with GuLoader malware. If that is the case, it’s important to note that such malware often employs sophisticated anti-analysis techniques that are challenging to overcome.

Stage 2 – Deployment

Once “Genicula.prm” is decoded, it can be analyzed in more detail in an attempt to understand it and allow the malware to proceed with its execution. Indeed, as part of the script, a new PowerShell script is detected. There are numerous comments and a function that appears to be responsible for decrypting the strings.

Script powershell

As seen in the previous capture, the function “Udskressv02” is responsible for decrypting strings included in the download itself, being invoked a total of 45 times throughout the execution. All the decrypted strings have been extracted:

Decrypted strings

Among the strings, references to variables already present in the script can be found. The lines that stand out the most are the last ones, where copy operations can be observed, as well as the use of “Invoke” to execute commands.

The variable “Conjuga” will load the VirtualAlloc function, which will be used to store the handle of the memory stored in the variables “Minefa3” and “Maudlinlyh”. The sections will have write, read, and execute permissions.

Following this, there are two copy operations from the variable “Tsarit”. This last was part of the first PowerShell script as one of the encrypted strings. The content of “Tsarit” represents the second stage, already converted from base64.

Tsarit assignation

Following the execution, it is possible to determine that it will copy the following bytes to the following variables:

  • “Minefa3”: The first 665 bytes of the second stage.
  • “Maudlinlyh”: Starting from byte 665, it will copy the next 192528 bytes.
Bytes copied

Afterward, the variable “Anthemi” will be invoked, which corresponds to CallWindowProcA, taking as parameters the variables assigned earlier, and the variable “Signasvrm,” which corresponds to the native function NtProtectVirtualMemory.

Final execution
Parameter $Maudlinlyh loaded into the memory of a PowerShell process

The parameter $Minefa3 will contain the shellcode that initiates stage 3.

Stage3 – GuLoader shellcodes

This phase consists of two shellcodes. The first one, corresponding to $Minefa3, serves as a “trampoline” and is responsible for decrypting various sections of the second shellcode and obtaining the entry point.

The second shellcode exhibits characteristics associated with GuLoader execution. As an anti-analysis technique, both shellcodes employ jumps to unaligned bytes.

Example of jmp to unaligned instructions in memory

$Minefa: preparing the second shellcode

As mentioned, it is observed that the first shellcode, referred to as $Minefa3, is used to decrypt sections of the second shellcode and obtain its entry point. In the end, the first shellcode will jump to the offset 0381E336 of the second shellcode.

Entry point shellcode2

Neither of the shellcodes is found on VirusTotal at the time of conducting this analysis.

NameHash(256)
$Minefa3f724e9ded6f84e572248f4a51bff05d5ea53f8cab3a93db5cdc1455f3d1100b7
Shellcode21CC9F1BCE50563E8FCD2A4B77CD53A7AF3CB0B69CA51D33DD2DF70599B3DF46A

In the end, the first shellcode will jump to the offset 0381E336 of the second shellcode.

Shellcode2 – Anti-analysis techniques

Is not the first time that we have to talk about anti-analysis techniques and for sure it will be not the last one. Once inside the second shellcode, characteristics closely related to the Guloader malware are identified. This malware employs several anti-analysis techniques that have been described in other reports. Some of the anti-analysis techniques used by GuLoader are so complex that some researchers focus solely on dissecting one or a subset of them. Some are listed bellow. A complete list can be found in the following article.

Vectored Exception Handler

To slow down the analysis, the malware utilizes the VEH (Vectored Exception Handler) technique. This method is used by malware to hinder the debugging and analysis process. It involves setting up a custom exception handler that intercepts specific types of exceptions, such as breakpoints or access violations, before they are handled by the operating system’s default exception handling mechanism.

Breakpoints that gnerate exceptions when debugging

When a debugger tries to set a breakpoint or debug the code, the malware detects the exception generated by the debugger and triggers its custom exception handler. This allows the malware to control the exception handling process and potentially alter the flow of execution, making it difficult for the debugger to accurately trace and analyze the malware’s behavior.

By utilizing VEH, malware can effectively evade or delay analysis attempts, as it can detect and react to debugging activities, making it more challenging for analysts to analyze the malicious code and understand its behavior.

Anti-brute force

To decrypt the strings within the binary, the shellcode utilizes XOR encryption.

Routine responsible for decrypting the strings

The encrypted strings are placed in different memory sections. In some reports, brute-force techniques are suggested to obtain the strings. However, the sample being analysed in this post uses takes anti-brute force precautions: the encrypted strings are constructed using simple operations such as addition, subtraction, or XOR logical operation.

Creation of encrypted strings using simple operations

Anti-VM checks

The malware utilizes the instructions “rdtsc” and “cpuid” to check if it is running on a virtual machine.

rdtsc and cpuid instructions

The “rdtsc” (Read Time Stamp Counter) instruction is used to read the CPU’s time stamp counter. In a virtualized environment, the behavior of this instruction may be different compared to a physical machine, allowing the malware to detect virtualization.

The “cpuid” instruction is used to obtain information about the processor, such as the manufacturer, processor family, and supported features. By checking certain values returned by the “cpuid” instruction, the malware can identify if it is running on a virtual machine.

Code responsible for overwriting the shellcode

If it is detected that it is running on a virtual machine, part of the shellcode is overwritten by writing zeros. After this, the typical message “This program cannot be run under virtual environment or debugging software!” is shown and the execution stops.

However, if it is not detected, the malware will use the function EnumWindow in order to check if the number of windows is greater than than 12. In other case, the execution is halted.

EnumWindows

It will also use the functions EnumDeviceDrivers and GetDeviceDriverBaseName to obtain the names of the drivers installed on the system, and the functions OpenScManagerA and EnumServicesStatusA to search for services related to virtual machines.

GetDeviceDriverBaseNameA
EumServiceStatusA

As a summary, this malware uses the following anti-vm techniques:

  • rdtsc and cpuid.
  • EnumWindow
  • List of drivers – EnumDeviceDrivers, GetDeviceDriverBaseName
  • Search for services related with virtual machines – OpenScManagerA, EnumServicesStatusA

If the malware analyst manages to overcome these obstacles, the shellcode will create the process “CasPol.exe” and inject another shellcode into it.

capsol.exe
CasPol.exe (ProcessHacker)

Within this new process, the malware contacts the domain “melsicon” again, this time using the URL https://melsicon[.]com/PUPWI75.bin to search for a new stage.

URL for download the new stage

Stage4 – AgentTesla

The downloaded file corresponds to a ciphered binary, which we will refer to as PUPWI75.bin based on the name it is downloaded with.

NameHash(256)
PUPWI75.bin7f6866693efe3ffa4e35433e180298daa5c11b94535625c6a243ba854e10c909

This file will be loaded into memory, decrypted and executed within the legitimate CasPol system process.

PUPWI75.bin (CFF Explorer)

Once the binary is decrypted, the resulting executable exhibits distinct characteristics of AgentTesla. For example, two modules “a” and “A”, where the configuration is in A.b.

Visualization of AgentTesla’s characteristic modules

Moreover, the module has several classes of the same style observed in previous AgentTesla samples, responsible for decrypting the credentials of each program.

Example of class responsible for decrypting the credentials of each program.
Configuration class

And finally, the strings are decrypted using the XORStrings tool by dr4k0nia, which is a characteristic of the new versions of AgentTesla.

Function in charge of decoding text strings

As it is known, AgentTesla is a type of stealer malware. In this case, the malware exfiltrates data via FTP using the domain larrysteaks.com.

Exfiltration method

So far, this domain has not been linked to malicious activity according to the sources consulted.

Information about larrysteaks.com in VirusTotal

Conclusions

This post details the complete infection process starting from a VBS file received via email. The anti-analysis techniques used by GuLoader have made the analysis challenging, but once overcome, the analysis reaches the final stage where AgentTesla is downloaded. While the initial sample is public, the other artifacts that trigger the different stages have not been found in the publicly available sources consulted.

Summary of artifacts

NameHash(256)
infected.vbs6c2a68a45a4c25c8058bd440e86e4a36e730cfd1e1844f4083a334d901fb3b5d
Genicula.prm3f0a012d75144686917f5a1ac151b03894c662783c2b9ed4867c02d39e682545
$Minefa3f724e9ded6f84e572248f4a51bff05d5ea53f8cab3a93db5cdc1455f3d1100b7
Shellcode21CC9F1BCE50563E8FCD2A4B77CD53A7AF3CB0B69CA51D33DD2DF70599B3DF46A
PUPWI75.bin7f6866693efe3ffa4e35433e180298daa5c11b94535625c6a243ba854e10c909

Summary of Indicators of Compromise (IOCs)

IOCDescription
hxxps://melsicon[.]com/Genicula.prmDownloads GuLoader binary
hxxps://melsicon[.]com/PUPWI75.binDownloads AgentTesla binary
ftp://ftp.larrysteaks.comAgentTesla – exfiltration method

3722304989

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related

GRU: Military Unit 54777
February 03, 2025
GRU military unit 29155
October 11, 2024
Tags: cyberwar, GRU
Pelmeni Wrapper: New Wrapper of Kazuar (Turla Backdoor)
February 19, 2024
Tags: Backdoor, Kazuar, Pelmeni Wrapper, Trula, Wrapper

Footer

Copyright &copy Lab52 2019 by S2 Grupo | Legal notice | Cookie policy | Privacy policy