SOC Prime Bias: Medium

25 Nov 2025 18:38

DarkGate Under the Hood

Author Photo
Ruslan Mikhalov Chief of Threat Research at SOC Prime linkedin icon Follow
DarkGate Under the Hood
shield icon

Detection stack

  • AIDR
  • Alert
  • ETL
  • Query

Summary

DarkGate is a Delphi-based loader sold as Malware-as-a-Service on criminal markets. It includes full RAT functionality, dynamic API resolution, and layered evasion tricks such as custom base64 character sets, Union-API–style syscall loading, and APC injection. The tool, attributed to the seller “RastaFarEye,” has been adopted by actors like TA577 and Ducktail. It communicates with C2 over HTTP with obfuscated payloads and can deploy remote desktop utilities, steal Discord tokens, and run an interactive reverse shell.

DarkGate Malware Analysis

The publication delivers an in-depth reverse-engineering walkthrough of the DarkGate executable, explaining its bespoke configuration scrambling, XOR-driven BotID generation, and encrypted logging. It catalogs the loader’s persistence techniques, privilege escalation paths, token-theft workflows, and abuse of legitimate binaries such as PsExec and Extexport for DLL side loading. The write-up further documents C2 communication patterns, default hVNC credentials, and the typical HTTP ports leveraged (2351 and 9999).

Mitigation

Blue teams should watch for creation of the referenced files and registry Run entries, immediately invalidate or block the default hVNC credentials, and detect PsExec and Extexport being used for unapproved DLL loading. Behavioral analytics should cover Union-API syscall usage, APC injection via NtTestAlert, and parent-PID spoofing. Network defenses can flag odd HTTP ports and attempt to decode DarkGate’s custom base64 alphabets to surface C2 traffic.

Response

Once DarkGate activity is confirmed, isolate the affected endpoint, harvest the documented artefacts, kill malicious processes, and clean all persistence footholds. Rotate any exposed credentials and block known C2 domains and IP ranges. A thorough forensic review should identify any secondary payloads and verify that all DLLs introduced through Extexport or related loaders have been eradicated.

Attack Flow

Simulation Execution

Prerequisite: The Telemetry & Baseline Pre‑flight Check must have passed.

  • Attack Narrative & Commands:
    The simulated adversary has already infiltrated the endpoint and seeks to establish persistent RDP access. First, they harvest credentials by storing them with cmdkey, then use psexec.exe to move laterally, and finally launch a PowerShell payload that drops a key‑logger stub. Each step is designed to generate the exact process‑creation events the detection rule monitors.

    1. Credential Harvesting (T1552.001) – Store a crafted credential entry that matches the rule’s selection_cmdkey pattern.
    2. Lateral Movement (T1219) – Execute psexec.exe against a remote host, invoking a command that spawns a new PowerShell session.
    3. PowerShell Execution (T1059.001) – Run a PowerShell command that loads a malicious script (simulated here with a base64‑encoded harmless command).
    4. Keylogger Deployment (T1056.001) – Compile and run a tiny C binary that calls GetAsyncKeyState, generating the API field match.
  • Regression Test Script:

    # DarkGate Simulation Script – PowerShell
    # --------------------------------------------------
    # 1. Cmdkey credential entry (matches detection pattern)
    $generic = '""'                         # empty generic as used by DarkGate
    $user    = 'SafeMode'                   # user name the rule expects
    $pass    = 'darkgatepassword0'          # password the rule expects
    cmd.exe /c cmdkey /generic:$generic /user:$user /pass:$pass
    
    # 2. PsExec lateral movement (binary must exist in PATH or specify full path)
    $remoteHost = '10.0.0.5'
    $psexecPath = "$env:SystemRoot\System32\psexec.exe"
    if (Test-Path $psexecPath) {
        & $psexecPath \\$remoteHost -accepteula cmd /c "whoami"
    } else {
        Write-Host "PsExec not found at $psexecPath – skipping this step."
    }
    
    # 3. PowerShell execution (base64‑encoded harmless command)
    $psCommand = 'Write-Output \"PowerShell payload executed\"'
    $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($psCommand))
    powershell.exe -EncodedCommand $encoded
    
    # 4. Keylogger stub compilation & execution
    $cSource = @"
    #include <windows.h>
    int main() {
        // Simple call to GetAsyncKeyState to satisfy the API match
        GetAsyncKeyState(VK_RETURN);
        return 0;
    }
    "@
    $srcPath = "$env:TEMP\keylog_stub.c"
    $exePath = "$env:TEMP\keylog_stub.exe"
    $cSource | Set-Content -Path $srcPath -Encoding ASCII
    # Compile with Visual C++ (cl.exe must be in PATH)
    cl.exe /nologo /O2 /Fe:$exePath $srcPath
    if (Test-Path $exePath) {
        & $exePath
    }
  • Cleanup Commands:

    # Remove credential entry
    cmd.exe /c cmdkey /delete:$generic
    
    # Delete temporary files
    Remove-Item -Force -ErrorAction SilentlyContinue "$env:TEMP\keylog_stub.c"
    Remove-Item -Force -ErrorAction SilentlyContinue "$env:TEMP\keylog_stub.exe"
    
    # Optional: terminate any stray psexec or powershell processes launched by the script
    Get-Process -Name psexec, powershell -ErrorAction SilentlyContinue | Stop-Process -Force