Detection rules › Sigma

Import New Module Via PowerShell CommandLine

Status
test
Severity
low
Log source
category process_creation, product windows
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

Known false positives

  • Depending on the environement, many legitimate scripts will import modules inline. This rule is targeted for hunting purposes.

MITRE ATT&CK coverage

TacticTechniques
ExecutionNo specific technique

Telemetry coverage

ProviderRecord / event type
SysmonEvent ID 1: Process creation

Rule body

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

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
ParentImagematch:\Program Files\WindowsApps\Microsoft.WindowsTerminal_excludes:ParentImage field:"ParentImage" value:":\Program Files\WindowsApps\Microsoft.WindowsTerminal_"
ParentImagematch:\Windows\System32\cmd.exeexcludes:ParentImage field:"ParentImage" value:":\Windows\System32\cmd.exe"
CommandLinematch:\Program Files\Microsoft Visual Studio\excludes:CommandLine field:"CommandLine" value:":\Program Files\Microsoft Visual Studio\"
CommandLinematchTools\Microsoft.VisualStudio.DevShell.dllexcludes:CommandLine field:"CommandLine" value:"Tools\Microsoft.VisualStudio.DevShell.dll"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
CommandLinematch
  • Import-Module corpus 3 (sigma 3)
  • ipmo corpus 3 (sigma 3)
field:"CommandLine" kind: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