Detection of PowerShell-Based DLL Placement in System Directories
Adversaries utilize PowerShell commands to move malicious DLLs into protected Windows system directories, a technique commonly associated with persistence and credential access.
This threat brief focuses on the behavioral detection of PowerShell scripts used to copy or move files, specifically malicious DLLs, into sensitive Windows system directories such as C:\Windows\System32 or C:\Windows\SysWOW64. This activity is frequently observed in post-exploitation scenarios where an attacker seeks to establish persistence or facilitate credential access, such as by installing a custom password filter DLL. By moving binaries into these directories, attackers often attempt to blend in with legitimate system files or exploit search order hijacking vulnerabilities. Defenders must monitor PowerShell Script Block logging (Event ID 4104) to identify these administrative operations initiated by potentially compromised user or service accounts.
Attack Chain
- Initial compromise of a workstation or server via phishing or exploit.
- Execution of a PowerShell command to locate or download a malicious DLL payload.
- Escalation of privileges to reach the level required for writing into protected directories.
- Use of
Copy-ItemorcpiPowerShell cmdlets to move the malicious DLL into a target path within System32 or SysWOW64. - Modification of registry keys (e.g., Notification Packages or Password Filters) to link the dropped DLL.
- Service restart or system reboot to force the loading of the malicious DLL by system processes.
- Final objective achieved: persistent code execution in the context of high-privileged system processes for credential dumping or C2.
Impact
Successful execution allows attackers to maintain persistent access to the host, bypass security controls, and capture sensitive credentials (such as plaintext passwords or NTLM hashes) directly from the LSASS process, potentially leading to domain-wide compromise.
Recommendation
- Enable PowerShell Script Block Logging (Event ID 4104) to capture the full command strings executed by PowerShell.
- Deploy the provided Sigma rule to identify unauthorized file operations targeting sensitive directories.
- Implement File Integrity Monitoring (FIM) on C:\Windows\System32 and C:\Windows\SysWOW64 to alert on the creation of new, unexpected DLLs.
- Enforce strict least-privilege policies to ensure that standard user or service accounts cannot write to protected system directories.
Immediate actions
Enable PowerShell Script Block Logging (Event ID 4104) across all endpoints.
Threat Hunt
Search for instances of files written to System32/SysWOW64 by non-trusted processes or users.
Data: Sysmon Event ID 11, Endpoint EDR file write events
Detection coverage 1
Detect PowerShell Copy-Item to System Directory
highDetects usage of Copy-Item or cpi to copy files into system directories like System32 or SysWOW64
Detection queries are available on the platform. Get full rules →