Detection rules › Sigma

Import New Module Via PowerShell CommandLine

Status
test
Severity
low
Log source
product windows, category process_creation
Author
Nasreddine Bencherchali (Nextron Systems)
Source
github.com/SigmaHQ/sigma

Detects usage of the "Import-Module" cmdlet in order to add new Cmdlets to the current PowerShell session

MITRE ATT&CK coverage

TacticTechniques
ExecutionNo specific technique

Event coverage

ProviderEventTitle
SysmonEvent ID 1Process creation

Rule body yaml

title: Import New Module Via PowerShell CommandLine
id: 4ad74d01-f48c-42d0-b88c-b31efa4d2262
status: test
description: Detects usage of the "Import-Module" cmdlet in order to add new Cmdlets to the current PowerShell session
references:
    - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7.3
    - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-5.1
author: Nasreddine Bencherchali (Nextron Systems)
date: 2023-05-09
modified: 2023-12-01
tags:
    - attack.execution
    - detection.threat-hunting
logsource:
    product: windows
    category: process_creation
detection:
    selection_img:
        - Image|endswith:
              - '\powershell.exe'
              - '\pwsh.exe'
        - OriginalFileName:
              - 'PowerShell.EXE'
              - 'pwsh.dll'
    selection_cmdlet:
        CommandLine|contains:
            - 'Import-Module '
            - 'ipmo '
    filter_main_vsstudio:
        ParentImage|contains:
            - ':\Program Files\WindowsApps\Microsoft.WindowsTerminal_'
            - ':\Windows\System32\cmd.exe'
        CommandLine|contains|all:
            - ':\Program Files\Microsoft Visual Studio\'
            - 'Tools\Microsoft.VisualStudio.DevShell.dll'
    condition: all of selection_* and not 1 of filter_main_*
falsepositives:
    - Depending on the environement, many legitimate scripts will import modules inline. This rule is targeted for hunting purposes.
level: low

Stages and Predicates

Stage 0: condition

all of selection_* and not 1 of filter_main_*

Stage 1: selection_img

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

Stage 2: selection_cmdlet

selection_cmdlet:
    CommandLine|contains:
        - 'Import-Module '
        - 'ipmo '

Stage 3: not filter_main_vsstudio

filter_main_vsstudio:
    ParentImage|contains:
        - ':\Program Files\WindowsApps\Microsoft.WindowsTerminal_'
        - ':\Windows\System32\cmd.exe'
    CommandLine|contains|all:
        - ':\Program Files\Microsoft Visual Studio\'
        - 'Tools\Microsoft.VisualStudio.DevShell.dll'

Exclusions

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

FieldKindExcluded values
ParentImagematch:\Program Files\WindowsApps\Microsoft.WindowsTerminal_
ParentImagematch:\Windows\System32\cmd.exe
CommandLinematch:\Program Files\Microsoft Visual Studio\
CommandLinematchTools\Microsoft.VisualStudio.DevShell.dll

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
  • Import-Module corpus 3 (sigma 3)
  • ipmo corpus 3 (sigma 3)
Imageends_with
  • \powershell.exe corpus 182 (sigma 182)
  • \pwsh.exe corpus 168 (sigma 168)
OriginalFileNameeq
  • PowerShell.EXE corpus 120 (sigma 84, splunk 30, elastic 6)
  • pwsh.dll corpus 112 (sigma 79, splunk 30, elastic 3)