Detection of PowerShell Execution Policy Weakening
Adversaries often downgrade PowerShell execution policies to execute unauthorized scripts, bypassing security controls by invoking the Set-ExecutionPolicy cmdlet with 'Unrestricted' or 'Bypass' parameters.
Attackers frequently attempt to bypass PowerShell's built-in security features, specifically the Execution Policy, to facilitate the execution of malicious scripts or payloads. The Set-ExecutionPolicy cmdlet is a common target for modification to lower security standards, specifically moving from default constrained settings to 'Unrestricted' or 'Bypass' states. This behavior is a common precursor to deploying lateral movement tools, credential harvesters, or secondary backdoors within a compromised Windows environment. Defensive teams should be aware that while some legitimate administrative tasks or automated installers (such as Chocolatey) may require such modifications, unauthorized execution of these commands by user-level processes or unexpected service accounts represents a significant indicator of malicious activity during the post-exploitation phase.
Attack Chain
- Initial access is established through phishing or exploit delivery to a workstation.
- The attacker executes a primary stager or drops a malicious script to disk.
- The attacker determines that the current PowerShell execution policy prevents the execution of the unsigned or remote-origin script.
- The attacker executes "Set-ExecutionPolicy -ExecutionPolicy Bypass" or "Unrestricted" via an interactive shell or automated script block.
- The system policy is downgraded, allowing the subsequent execution of the malicious script or payload without further prompt.
- The malicious payload executes, performing objectives such as credential dumping, discovery, or C2 beaconing.
Impact
Successful execution policy downgrades enable attackers to bypass security restrictions designed to prevent unauthorized script execution. This facilitates the deployment of malware, administrative tools, or weaponized scripts that would otherwise be blocked, increasing the likelihood of successful lateral movement and data exfiltration.
Recommendation
- Enable PowerShell Script Block Logging (Event ID 4104) across the environment to capture the command line content necessary to identify this activity.
- Deploy the Sigma rule below to monitor for unauthorized execution policy modifications.
- Audit administrative usage of execution policy changes and establish a baseline of legitimate deployment processes to reduce noise from installers like Chocolatey.
Immediate actions
Enable PowerShell Script Block Logging (Event ID 4104) across all Windows endpoints
Threat Hunt
Identify historical usage of Set-ExecutionPolicy in logs
Data: Event ID 4104 (Script Block Logging)
Mitigations
Enforce Execution Policy via Group Policy (GPO) to prevent local user modification
T1059.001
Detection coverage 1
Detect PowerShell Execution Policy Weakening
mediumDetects changing the PowerShell script execution policy to a potentially insecure level using the Set-ExecutionPolicy cmdlet.
Detection queries are available on the platform. Get full rules →