A sophisticated Python-based malware delivery mechanism has been uncovered, leveraging advanced techniques to deploy a new strain of malware called SwaetRAT. The script utilizes low-level Windows API interactions through libraries such as System.Reflection and ctypes, enabling it to manipulate system behavior, load malicious payloads, and bypass security measures. This approach represents a growing trend in malware development, where legitimate tools and system functions are weaponized for malicious purposes.
The Python script specifically targets Windows operating systems, patching critical APIs like AmsiScanBuffer and EtwEventWrite to disable security features such as the Antimalware Scan Interface (AMSI) and event logging via Event Tracing for Windows (ETW). By overwriting the initial bytes of these APIs with custom code, the malware ensures its actions remain undetected. For 64-bit systems, the patch comprises four bytes (0x48, 0x33, 0xc0, 0xc3), while 32-bit systems use a five-byte patch (0x33, 0xc0, 0xc2, 0x14, 0x00). This manipulation cripples core defenses, allowing the malware to operate freely.
Once executed, the script decodes Base64-encoded data to load a .NET assembly using the Assembly.Load method. This assembly facilitates reflection-based execution, bypassing whitelisting mechanisms and dynamically invoking the malware’s entry point. The decoded payload, identified as a Portable Executable (PE) file with the signature “MZ,” is crafted for the Windows environment. The malware further ensures persistence by copying itself to disguised locations, modifying registry keys, and creating startup shortcuts. Its configuration, including command-and-control (C2) server details, can be extracted from encoded data.
Security experts warn that SwaetRAT exemplifies a growing trend of malware exploiting Python’s versatility and Windows system intricacies. To mitigate risks, organizations are urged to implement robust endpoint detection systems, scrutinize system behavior for anomalies, and stay vigilant against emerging threats. This discovery underscores the critical need for proactive cybersecurity measures to counter increasingly sophisticated malware campaigns.
Reference: