Suspicious PowerShell Script Using Cryptography Namespace
The analytic detects suspicious PowerShell script execution involving the cryptography namespace (excluding SHA and MD5) via EventCode 4104, often associated with malware that decrypts or decodes additional malicious payloads leading to further code execution, privilege escalation, or persistence.
This threat brief focuses on detecting suspicious PowerShell activity involving the System.Security.Cryptography namespace, excluding common hashing algorithms like SHA and MD5. The detection leverages Windows PowerShell Script Block Logging (EventCode 4104) to identify scripts using cryptographic functions. This is significant because malware often uses cryptography to decrypt or decode additional malicious payloads, which can lead to further code execution, privilege escalation, or persistence within the compromised environment. The technique is commonly used by malware families like AsyncRAT, XWorm, and VIP Keylogger. Defenders should investigate the parent process of such scripts, the decrypted data, network connections established by the script, and the user context in which the script is executed.
Attack Chain
- An attacker gains initial access to a system, possibly through phishing or exploiting a vulnerability.
- The attacker executes a PowerShell script on the compromised system.
- The PowerShell script utilizes the
System.Security.Cryptographynamespace to perform cryptographic operations. - The script decrypts or decodes a malicious payload (e.g., a second-stage executable or configuration file).
- The decrypted payload is written to disk or loaded directly into memory.
- The attacker executes the decrypted payload, potentially establishing persistence via registry keys or scheduled tasks.
- The malware leverages the established persistence mechanism for long-term access.
- The attacker performs malicious actions such as data exfiltration, lateral movement, or remote command execution.
Impact
Successful exploitation allows attackers to bypass security measures by hiding malicious code within encrypted payloads. This can lead to data theft, system compromise, and further propagation within the network. Malware families like AsyncRAT, XWorm, and VIP Keylogger use this technique to maintain persistence and perform malicious activities undetected. The impact can range from individual workstation compromise to large-scale data breaches depending on the attacker’s objectives and the compromised system’s role within the organization.
Recommendation
- Enable PowerShell Script Block Logging on all endpoints to generate the necessary logs (EventCode 4104) for detection.
- Deploy the Sigma rule
Detect Suspicious PowerShell Cryptography Namespace Usageto your SIEM to detect the described activity. - Investigate any alerts generated by the Sigma rule by examining the parent process, decrypted data, network connections, and the user executing the script.
- Review and tune the Sigma rule
Detect Suspicious PowerShell Cryptography Namespace Usagebased on your environment’s specific needs and known-good PowerShell usage to reduce false positives. - Implement application control policies to restrict the execution of unsigned or untrusted PowerShell scripts.
Detection coverage 2
Detect Suspicious PowerShell Cryptography Namespace Usage
highDetects suspicious PowerShell scripts using the System.Security.Cryptography namespace, excluding common hashing algorithms, which may indicate malware decrypting or decoding malicious payloads.
Detect PowerShell ScriptBlockText Cryptography Namespace Usage
highDetects suspicious PowerShell ScriptBlockText using the System.Security.Cryptography namespace, excluding common hashing algorithms, which may indicate malware decrypting or decoding malicious payloads.
Detection queries are kept inside the platform. Get full rules →