Detection rules › Sigma

Change PowerShell Policies to an Insecure Level

Status
test
Severity
medium
Log source
product windows, category process_creation
Author
frack113
Source
github.com/SigmaHQ/sigma

Detects changing the PowerShell script execution policy to a potentially insecure level using the "-ExecutionPolicy" flag.

MITRE ATT&CK coverage

Event coverage

ProviderEventTitle
SysmonEvent ID 1Process creation

Rule body yaml

title: Change PowerShell Policies to an Insecure Level
id: 87e3c4e8-a6a8-4ad9-bb4f-46e7ff99a180
related:
    - id: cf2e938e-9a3e-4fe8-a347-411642b28a9f # ProcCreation Registry
      type: similar
    - id: 61d0475c-173f-4844-86f7-f3eebae1c66b # ScriptBlock
      type: similar
    - id: fad91067-08c5-4d1a-8d8c-d96a21b37814 # Registry
      type: similar
status: test
description: Detects changing the PowerShell script execution policy to a potentially insecure level using the "-ExecutionPolicy" flag.
references:
    - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.4
    - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4
    - https://adsecurity.org/?p=2604
    - https://thedfirreport.com/2021/11/01/from-zero-to-domain-admin/
author: frack113
date: 2021-11-01
modified: 2025-10-07
tags:
    - attack.execution
    - attack.t1059.001
logsource:
    product: windows
    category: process_creation
detection:
    selection_img:
        - OriginalFileName:
              - 'powershell_ise.exe'
              - 'PowerShell.EXE'
              - 'pwsh.dll'
        - Image|endswith:
              - '\powershell_ise.exe'
              - '\powershell.exe'
              - '\pwsh.exe'
    selection_option:
        CommandLine|contains:
            - '-executionpolicy '
            - ' -ep '
            - ' -exec '
    selection_level:
        CommandLine|contains:
            - 'Bypass'
            - 'Unrestricted'
    filter_main_powershell_core:
        ParentImage:
            - 'C:\Windows\SysWOW64\msiexec.exe'
            - 'C:\Windows\System32\msiexec.exe'
        CommandLine|contains:
            - '-NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\PowerShell\7\'
            - '-NoProfile -ExecutionPolicy Bypass -File "C:\Program Files (x86)\PowerShell\7\'
    filter_optional_avast:
        ParentImage|contains:
            - 'C:\Program Files\Avast Software\Avast\'
            - 'C:\Program Files (x86)\Avast Software\Avast\'
            - '\instup.exe'
        CommandLine|contains:
            - '-ExecutionPolicy ByPass -File "C:\Program Files\Avast Software\Avast'
            - '-ExecutionPolicy ByPass -File "C:\Program Files (x86)\Avast Software\Avast\'
    condition: all of selection_* and not 1 of filter_main_* and not 1 of filter_optional_*
falsepositives:
    - Administrator scripts
level: medium

Stages and Predicates

Stage 0: condition

all of selection_* and not 1 of filter_main_* and not 1 of filter_optional_*

Stage 1: selection_img

selection_img:
    - OriginalFileName:
          - 'powershell_ise.exe'
          - 'PowerShell.EXE'
          - 'pwsh.dll'
    - Image|endswith:
          - '\powershell_ise.exe'
          - '\powershell.exe'
          - '\pwsh.exe'

Stage 2: selection_option

selection_option:
    CommandLine|contains:
        - '-executionpolicy '
        - ' -ep '
        - ' -exec '

Stage 3: selection_level

selection_level:
    CommandLine|contains:
        - 'Bypass'
        - 'Unrestricted'

Stage 4: not filter_main_powershell_core

filter_main_powershell_core:
    ParentImage:
        - 'C:\Windows\SysWOW64\msiexec.exe'
        - 'C:\Windows\System32\msiexec.exe'
    CommandLine|contains:
        - '-NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\PowerShell\7\'
        - '-NoProfile -ExecutionPolicy Bypass -File "C:\Program Files (x86)\PowerShell\7\'

Stage 5: not filter_optional_avast

filter_optional_avast:
    ParentImage|contains:
        - 'C:\Program Files\Avast Software\Avast\'
        - 'C:\Program Files (x86)\Avast Software\Avast\'
        - '\instup.exe'
    CommandLine|contains:
        - '-ExecutionPolicy ByPass -File "C:\Program Files\Avast Software\Avast'
        - '-ExecutionPolicy ByPass -File "C:\Program Files (x86)\Avast Software\Avast\'

Exclusions

Top-level NOT(...) conjuncts: predicates this rule actively suppresses.

FieldKindExcluded values
CommandLinematch-NoProfile -ExecutionPolicy Bypass -File "C:\Program Files (x86)\PowerShell\7\
CommandLinematch-NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\PowerShell\7\
ParentImageeqC:\Windows\SysWOW64\msiexec.exe
ParentImageeqC:\Windows\System32\msiexec.exe
CommandLinematch-ExecutionPolicy ByPass -File "C:\Program Files (x86)\Avast Software\Avast\
CommandLinematch-ExecutionPolicy ByPass -File "C:\Program Files\Avast Software\Avast
ParentImagematchC:\Program Files (x86)\Avast Software\Avast\
ParentImagematchC:\Program Files\Avast Software\Avast\
ParentImagematch\instup.exe

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
CommandLinematch
  • -ep
  • -exec
  • -executionpolicy
  • Bypass corpus 6 (sigma 6)
  • Unrestricted corpus 2 (sigma 2)
Imageends_with
  • \powershell.exe corpus 182 (sigma 182)
  • \powershell_ise.exe corpus 41 (sigma 41)
  • \pwsh.exe corpus 168 (sigma 168)
OriginalFileNameeq
  • PowerShell.EXE corpus 120 (sigma 84, splunk 30, elastic 6)
  • powershell_ise.exe corpus 51 (splunk 30, sigma 18, elastic 3)
  • pwsh.dll corpus 112 (sigma 79, splunk 30, elastic 3)