Fortinet Inc.

08/28/2024 | Press release | Distributed by Public on 08/28/2024 07:16

Deep Analysis of Snake Keylogger’s New Variant

Affected platforms: Microsoft Windows
Impacted parties: Windows Users
Impact: Collects sensitive information from the victim's computer
Severity level: High

Fortinet's FortiGuard Labs recently caught a phishing campaign in the wild with a malicious Excel document attached to the phishing email. We performed a deep analysis on the campaign and discovered that it delivers a new variant of Snake Keylogger.

Snake Keylogger (aka "404 Keylogger" or "KrakenKeylogger") is a subscription-based keylogger with many capabilities. It is a .NET-based software originally sold on a hacker forum.

Once executed on a victim's computer, it has the ability to steal sensitive data, including saved credentials from web browsers and other popular software, the system clipboard, and basic device information. It can also log keystrokes and capture screenshots.

In the following sections, we will look at the phishing spam, how it lures the recipient into opening a malicious Excel document, how the Excel document downloads and executes a new variant of Snake Keylogger, and what anti-analysis techniques it uses to protect itself from being detected and blocked during the attack.

Snake Keylogger Overview

The Phishing Email

Figure 1: The phishing email.

The email content in Figure 1 attempts to deceive the recipient into opening the attached Excel file (swift copy.xls) by claiming that funds have been transferred into their account. To warn the user, the FortiGuard service marks this phishing email as "[virus detected]," as shown in the subject line.

The Malicious Excel Document

Figure 2: When the Excel file is opened in Excel program.

Figure 2 shows the content of the attached Excel file when opened in the Office Excel program. Meanwhile, malicious code is executed in the background to download other files.

Looking into the binary data of the Excel file, it contains a specially crafted embedded link object that exploits the CVE-2017-0199 vulnerability to download a malicious file. Figure 3 displays the embedded link object ("\x01Ole"). The link is "hxxp[:]//urlty[.]co/byPCO," which is secretly requested by the Excel program when the file is opened.

Figure 3: Crafted embedded OLE link object.

When the link is accessed, it returns with another URL in the "Location" field of the response header, which is "hxxp[:]//192.3.176[.]138/xampp/zoom/107.hta". HTA file is an HTML Application file executed by a Windows application- by default, the HTML Application host (mshta.exe).

The 107.hta file is full of obfuscated JavaScript code that is executed automatically when loaded by mshta.exe. Figure 4 shows a partial view of the JavaScript code.

Figure 4: The partial content of the downloaded file "107.hta".

VBScript Code & PowerShell Code

After decoding and de-obfuscating the JavaScript code, we were able to get a piece of the VBScript code, as shown in Figure 5.

Figure 5: The VBScript code decoded from Javascript code.

It's evident that the VBScript code created an object of "Script.Shell" and executed a piece of PowerShell code decoded from a base64 string, defined in the variable "ps_code". This PowerShell code is then executed by "cmd.exe" (%ComSpec%) when the "shellObj.Run()" function is called.

The base64 decoded PowerShell code is shown below. It invokes a Windows API, URLDownloadToFile(), to download an executable file to the victim's computer and run it after waiting three seconds.

The URL of the executable file is hardcoded as "hxxp[:]//192.3.176[.]138/107/sahost.exe" and the local file is "%Appdata%\sahost.exe". The PowerShell code finally starts the executable file by calling Start "$Env:AppData\sahost.exe".

Dive into the Loader-Module

My research shows that the downloaded EXE file (sahost.exe) contains a new variant of Snake Keylogger, which is extracted, decrypted, loaded, and run by the EXE file. I will refer to this downloaded EXE file as the Loader module.

Figure 6 is a screenshot of its analysis in a packer detection tool. It was developed using the Microsoft .Net Framework.

Figure 6: Properties of the downloaded EXE.

To protect the Snake Keylogger core module from being detected and blocked by cybersecurity products, sahost.exe uses multiple-layer protection techniques, like transformation and encryption, within several named resources. When sahost.exe starts, it extracts several modules (dlls) onto its memory from the Resource section that provide methods to inquire, extract, decrypt, install, and deploy the core module.

The original name of "sahost.exe" is "utGw.exe." It decrypts and extracts a module called "FGMaker.dll" from a resource named "siri" in its Resource section. Figure 7 shows some of that code.

Figure 7: Load a module from Resouce "siri"

The "FGMaker.dll" module extracts additional modules (such as "Q" and "Gammar.dll") that work together to extract and decrypt a module called "Tyrone.dll" from the resource "KKki".

Figure 8: Resource "KKki" is about to load

You may have noticed in Figure 8 that it loads "KKki" as a Bitmap resource. The module "Tyrone.dll" was encrypted, broken down into bytes, and kept in the Bitmap resource. Figure 9 shows the content of the resource "KKki" as a Bitmap picture.

Figure 9: Bitmap resource "KKki".

After another decryption sequence, we can see the plaintext of the "Tyrone.dll" module in memory. It is then loaded as an executable module by calling the Assembly.Load() method.

Figure 10 showcases the modules that have been extracted and loaded by the Loader module so far.

Figure 10: Relevant modules extracted by the Loader module.

Dissecting the Deploy Module

I will refer to "Tyrone.dll" as "Deploy module" in the following analysis. It performs the following functions:

  • Renames the Loader module file.

This checks whether the current process's full path is "% AppData%WeENKtk.exe," renames it, and sets attributes (Hidden, ReadOnly, System, etc.) to it if the result is no. On the very first run, it was %AppData%sahost. exe.

  • Ensures Snake Keylogger persistence.

The Deploy module runs the "schetasks.exe" command to create a new scheduled task in the system Task Scheduler. This allows Snake Keylogger to launch at system startup. Figure 11 shows the scheduled task for Snake Keylogger.

Figure 11: Snake Keylogger is added in the system Task Scheduler.

The Deploy module obtains a resource data, "I7O14IyvsdO," from its own Resource section. Then, it decrypts the data with the string key "YRDdITlYRXI" into a final PE file in its memory. This is the core module of Snake Keylogger.

Next, the Deploy module performs process hollowing, a malware technique that creates a new process and then inserts malicious code into it to run. This allows it to hide its original process.

Figure 12: Break on a method calling CreateProcess().

Figure 12 shows that it about to call the obfuscated API CreateProcess(). It has a key argument, "Creation Flag," indicating how to create the process. Its value has been set to 134217732, i.e. 0x08000004 in hexadecimal. It is defined as "CREATE_SUSPENDED" and "CREATE_NO_WINDOW." The process name, the first argument to CreateProcess(), is the same as the Loader module.

To complete the process hollowing, it needs to call some relevant Windows APIs, such as ZwUnmapViewOfSection(), VirtualAllocEx(), ReadProcessMemory(), WriteProcessMemory(), GetThreadContext(), SetThreadContext(), and ResumeThread().

Snake Keylogger Core Module and Features

The core module's original name is "lfwhUWZlmFnGhDYPudAJ.exe." Figure 13 shows that the attacker has fully obfuscated the entire module, which displays its entry point ("Main()") and the obfuscated code, class names, and method names.

Figure 13: Obfuscated Snake Keylogger core module.

The Snake Keylogger's structure is very clear. We can see its capability to collect private and sensitive information from the victim's device, including the device's basic information, saved credentials, keystrokes, screenshots, and data on the system clipboard.

The features are split into different methods driven by Timers. Snake Keylogger also has some relevant flag variables indicating whether the feature is enabled.

This variant of Snake Keylogger only enables the credential collection feature.

First, Snake Keylogger fetches the device's basic information, like the PC name, System time, IP address, Country name, Region name, City name, TimeZone, and so on. Figure 14 shows an example of the basic information collected from one of my testing devices.

Figure 14: Basic information example.

This Snake Keylogger variant includes several hardcoded IP addresses the attacker may believe are used by some sample automatic analysis systems they want to avoid.

Figure 15: Method to detect victim's IP address.

One method called "anti_bot()," shown in Figure 15, checks the hardcoded IP addresses. "BotDetected" is returned if the victim's IP address matches any of those IP addresses. This results in the Snake Keylogger only collecting credentials but never sending them to the attacker.

Credentials Collection

Snake Keylogger collects saved credentials from over 50 popular software programs, categorized as web browsers, email clients, IM clients, and FTP clients.

Figure 16: Method for fetching Google Chrome credentials.

Every software has its own profile folder for saving configuration data. Snake Keylogger traverses all the profile files, looking for the saved credentials. Figure 16 is an example of the method used for Google Chrome. As you may have noticed in the "Locals" tab, it just obtained one set of credentials, including "URL," "Login ID," and "Login Password."

All the software can be categorized as follows:

Chromium-based Web Browsers:
"Google Chrome," "Amigo," "Xpom," "Kometa," "Nichrome," "CocCoc," "QQ Browser," "Orbitum," "Slimjet," "Iridium," "Vivaldi," "Iron," "Chromium," "Ghost Browser," "Cent Browser," "xVast," "Chedot," "Comodo Dragon," "SuperBird," "360 Browser," "360 Chrome," "Brave," "Torch," "UC Browser," "Blisk," "Epic PrivacyBrowser," "Liebao," "Avast," "Kinza," "BlackHawk," "Citrio," "Uran," "Coowon," "7Star," "QIP Surf," "Sleipnir," "Chrome Canary," "ChromePlus," "Sputnik," "Microsoft Edge," and "Slim".

Mozilla-based Web Browsers:
"SeaMonkey," "IceDragon," "CyberFox," "WaterFox," "Postbox," and "PaleMoon"

Other Web Browsers:
"Opera," "Firefox".

Email clients:
"FoxMail," "Thunderbird".

FTP clients:
"FileZilla".

IM client:
"Pidgin," "Discord".

All the credentials collected from the above software are temporarily stored in a global variable.

Stolen Credentials Submitted Over SMTP

Snake Keylogger variants have several ways to submit harvested credentials to the attacker, including uploading the data onto an FTP server, sending it to an email address, and submitting it over Telegram's bot over HTTP Post method. This variant of Snake Keylogger sends data over SMTP.

Figure 17 is a screenshot of how it builds the email content. The upper part contains the code that includes the email's sender, recipient, subject, and body, while the lower part shows the content of the variable "mailMessage" with the data filled by the code.

Figure 17: Created email message with collected credentials.

The email's body contains the computer's basic information saved in a global variable, followed by the credentials stolen from the victim's computer saved in another global variable. It then creates an SMTP client, and its Send() method is called to send the credentials to the attacker.

Figure 18 shows an example of how the email looks in Microsoft Outlook.

Figure 18: Attacker's view of the email.

Snake Keylogger Summary

Figure 19 illustrates the entire workflow of the Snake Keylogger campaign.

Figure 19: Snake Keylogger campaign workflow.

This analysis reviewed the entire process of this Snake Keylogger campaign, which is being led by a phishing email.

The phishing email, which included a malicious Excel document, lured the recipient into opening the file to see the details of a "balance payment." The Excel document was displayed in different tools, and I explained how it downloads an HTA file by exploiting a known vulnerability.

It then leverages multiple language scripts, such as JavaScript, VBScript, and PowerShell, to download the Snake Keylogger's Loader module.

Afterward, I elaborated on how the Loader module extracts multiple modules (including several middle modules and the Deploy module) from the file's Resource section. Malware often uses a process like this to prevent being detected and analyzed.

Next, I introduced how the Snake Keylogger Deploy module establishes persistence on the victim's computer and conducts process hollowing to put the core module into a newly created process to run.

Finally, we examined how the Snake Keylogger steals sensitive information from the victim's computer and how the stolen data is sent to the attacker using the SMTP protocol.

Fortinet Protections

Fortinet customers are already protected from this campaign with FortiGuard's AntiSPAM, Web Filtering, IPS, and AntiVirus services as follows:

The relevant URLs are rated as "Malicious Websites" by the FortiGuard Web Filtering service.

FortiMail recognizes the phishing email as "virus detected." In addition, real-time anti-phishing provided by FortiSandbox embedded in Fortinet's FortiMail, web filtering, and antivirus solutions provides advanced protection against both known and unknown phishing attempts.

FortiGuard IPS service detects the vulnerability exploit against CVE-2017-0199 with the signature "MS.Office.OLE.autolink.Code.Execution".

FortiGuard Antivirus service detects the attached Excel document, 107.hta, the downloaded executable file and the extracted Snake Keylogger with the following AV signatures.

MSExcel/CVE_2017_0199.DDOC!exploit
VBS/SnakeKeylogger.119B!tr.dldr
MSIL/SnakeKeylogger.FQQD!tr
MSIL/SnakeKeylogger.AES!tr.spy

FortiGate, FortiMail, FortiClient, and FortiEDR support the FortiGuard AntiVirus service. The FortiGuard AntiVirus engine is part of each solution. As a result, customers who have these products with up-to-date protections are already protected.

The FortiGuard CDR (content disarm and reconstruction) service can disarm the embedded link object inside the Excel document.

To stay informed of new and emerging threats, you can sign up to receive future alerts.

We also suggest our readers go through the free Fortinet Cybersecurity Fundamentals (FCF) training, a module on Internet threats designed to help end users learn how to identify and protect themselves from phishing attacks.

If you believe this or any other cybersecurity threat has impacted your organization, please contact our Global FortiGuard Incident Response Team.

IOCs

URLs

hxxp://urlty[.]co/byPCO
hxxp[:]//192.3.176[.]138/xampp/zoom/107.hta
hxxp[:]//192.3.176[.]138/107/sahost.exe

Relevant Sample SHA-256

[swift copy.xls]
8406A1D7A33B3549DD44F551E5A68392F85B5EF9CF8F9F3DB68BD7E02D1EABA7

[107.hta]
6F6A660CE89F6EA5BBE532921DDC4AA17BCD3F2524AA2461D4BE265C9E7328B9

[The Loader module/sahost.exe / WeENKtk.exe / utGw.exe]
484E5A871AD69D6B214A31A3B7F8CFCED71BA7A07E62205A90515F350CC0F723

[Snake Keylogger core module / lfwhUWZlmFnGhDYPudAJ.exe]
207DD751868995754F8C1223C08F28633B47629F78FAAF70A3B931459EE60714