Detection rules › Sigma
Import New Module Via PowerShell CommandLine
Detects usage of the "Import-Module" cmdlet in order to add new Cmdlets to the current PowerShell session
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | No specific technique |
Event coverage
| Provider | Event | Title |
|---|---|---|
| Sysmon | Event ID 1 | Process 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.
| Field | Kind | Excluded values |
|---|---|---|
ParentImage | match | :\Program Files\WindowsApps\Microsoft.WindowsTerminal_ |
ParentImage | match | :\Windows\System32\cmd.exe |
CommandLine | match | :\Program Files\Microsoft Visual Studio\ |
CommandLine | match | Tools\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.
| Field | Kind | Values |
|---|---|---|
CommandLine | match |
|
Image | ends_with |
|
OriginalFileName | eq |
|