Detection rules › Sigma

Clear PowerShell History - PowerShell

Status
test
Severity
medium
Log source
product windows, category ps_script
Author
Ilyas Ochkov, Jonhnathan Ribeiro, Daniil Yugoslavskiy, oscd.community
Source
github.com/SigmaHQ/sigma

Detects keywords that could indicate clearing PowerShell history

MITRE ATT&CK coverage

Event coverage

Rule body yaml

title: Clear PowerShell History - PowerShell
id: 26b692dc-1722-49b2-b496-a8258aa6371d
related:
    - id: dfba4ce1-e0ea-495f-986e-97140f31af2d
      type: derived
status: test
description: Detects keywords that could indicate clearing PowerShell history
references:
    - https://gist.github.com/hook-s3c/7363a856c3cdbadeb71085147f042c1a
author: Ilyas Ochkov, Jonhnathan Ribeiro, Daniil Yugoslavskiy, oscd.community
date: 2022-01-25
modified: 2022-12-02
tags:
    - attack.stealth
    - attack.t1070.003
logsource:
    product: windows
    category: ps_script
    definition: 'Requirements: Script Block Logging must be enabled'
detection:
    selection1a:
        ScriptBlockText|contains:
            - 'del'
            - 'Remove-Item'
            - 'rm'
    selection1b:
        ScriptBlockText|contains: '(Get-PSReadlineOption).HistorySavePath'
    selection_2:
        ScriptBlockText|contains|all:
            - 'Set-PSReadlineOption'
            - '–HistorySaveStyle'  # not sure if the homoglyph –/- is intended, just checking for both
            - 'SaveNothing'
    selection_3:
        ScriptBlockText|contains|all:
            - 'Set-PSReadlineOption'
            - '-HistorySaveStyle'
            - 'SaveNothing'
    condition: 1 of selection_* or all of selection1*
falsepositives:
    - Legitimate PowerShell scripts
level: medium

Stages and Predicates

Stage 0: condition

1 of selection_* or all of selection1*

Stage 1: selection_2

selection_2:
    ScriptBlockText|contains|all:
        - 'Set-PSReadlineOption'
        - '–HistorySaveStyle'
        - 'SaveNothing'

Stage 2: selection_3

selection_3:
    ScriptBlockText|contains|all:
        - 'Set-PSReadlineOption'
        - '-HistorySaveStyle'
        - 'SaveNothing'

Stage 3: selection1a

selection1a:
    ScriptBlockText|contains:
        - 'del'
        - 'Remove-Item'
        - 'rm'

Stage 4: selection1b

selection1b:
    ScriptBlockText|contains: '(Get-PSReadlineOption).HistorySavePath'

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
ScriptBlockTextmatch
  • (Get-PSReadlineOption).HistorySavePath corpus 2 (sigma 2)
  • -HistorySaveStyle
  • Remove-Item corpus 3 (sigma 2, splunk 1)
  • SaveNothing
  • Set-PSReadlineOption
  • del
  • rm corpus 2 (sigma 2)
  • –HistorySaveStyle