Detection rules › Sigma

Potential PowerShell Command Line Obfuscation

Status
test
Severity
high
Log source
category process_creation, product windows
Author
Teymur Kheirkhabarov (idea), Vasiliy Burov (rule), oscd.community, Tim Shelton (fp)
Source
github.com/SigmaHQ/sigma

Detects the PowerShell command lines with special characters

Known false positives

  • Amazon SSM Document Worker
  • Windows Defender ATP

MITRE ATT&CK coverage

Telemetry coverage

ProviderRecord / event type
SysmonEvent ID 1: Process creation

Rule body

title: Potential PowerShell Command Line Obfuscation
id: d7bcd677-645d-4691-a8d4-7a5602b780d1
status: test
description: Detects the PowerShell command lines with special characters
references:
    - https://speakerdeck.com/heirhabarov/hunting-for-powershell-abuse?slide=64
author: Teymur Kheirkhabarov (idea), Vasiliy Burov (rule), oscd.community, Tim Shelton (fp)
date: 2020-10-15
modified: 2024-04-15
tags:
    - attack.execution
    - attack.stealth
    - attack.t1027
    - attack.t1059.001
logsource:
    category: process_creation
    product: windows
detection:
    selection_img:
        - Image|endswith:
              - '\powershell.exe'
              - '\pwsh.exe'
        - OriginalFileName:
              - 'PowerShell.EXE'
              - 'pwsh.dll'
    selection_re:
        # TODO: Optimize for PySIGMA
        - CommandLine|re: '\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+'
        - CommandLine|re: '\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{'
        - CommandLine|re: '\^.*\^.*\^.*\^.*\^'
        - CommandLine|re: '`.*`.*`.*`.*`'
    filter_optional_amazonSSM:
        ParentImage: C:\Program Files\Amazon\SSM\ssm-document-worker.exe
    filter_optional_defender_atp:
        CommandLine|contains:
            - 'new EventSource("Microsoft.Windows.Sense.Client.Management"'
            - 'public static extern bool InstallELAMCertificateInfo(SafeFileHandle handle);'
    condition: all of selection_* and not 1 of filter_optional_*
falsepositives:
    - Amazon SSM Document Worker
    - Windows Defender ATP
level: high

Stages and Predicates

Stage 0: condition

all of selection_* and not 1 of filter_optional_*

Stage 1: selection_img

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

Stage 2: selection_re

selection_re:
    - CommandLine|re: '\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+'
    - CommandLine|re: '\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{'
    - CommandLine|re: '\^.*\^.*\^.*\^.*\^'
    - CommandLine|re: '`.*`.*`.*`.*`'

Stage 3: not filter_optional_*

filter_optional_amazonSSM:
    ParentImage: C:\Program Files\Amazon\SSM\ssm-document-worker.exe
filter_optional_defender_atp:
    CommandLine|contains:
        - 'new EventSource("Microsoft.Windows.Sense.Client.Management"'
        - 'public static extern bool InstallELAMCertificateInfo(SafeFileHandle handle);'

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
CommandLinematchnew EventSource("Microsoft.Windows.Sense.Client.Management"excludes:CommandLine
CommandLinematchpublic static extern bool InstallELAMCertificateInfo(SafeFileHandle handle);excludes:CommandLine field:"CommandLine" value:"public static extern bool InstallELAMCertificateInfo(SafeFileHandle handle);"
ParentImageeqC:\Program Files\Amazon\SSM\ssm-document-worker.exeexcludes:ParentImage field:"ParentImage" value:"C:\Program Files\Amazon\SSM\ssm-document-worker.exe"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
CommandLineregex_match
  • +.*+.*+.*+.*+.*+.*+.*+.*+.*+.*+.*+.*+.*+
  • ^.*^.*^.*^.*^
  • {.*{.*{.*{.*{.*{.*{.*{.*{.*{
  • `.*`.*`.*`.*`
field:"CommandLine" kind:regex_match
Imageends_with
  • \powershell.exe corpus 179 (sigma 178, kusto 1)
  • \pwsh.exe corpus 165 (sigma 164, kusto 1)
field:"Image" kind:ends_with
OriginalFileNameeq
  • PowerShell.EXE corpus 138 (sigma 84, splunk 30, elastic 24)
  • pwsh.dll corpus 112 (sigma 79, splunk 30, elastic 3)
field:"OriginalFileName" kind:eq