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
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
| Tactic | Techniques |
|---|---|
| Execution | No specific technique |
Telemetry coverage
| Provider | Record / event type |
|---|---|
| Sysmon | Event 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.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
ParentImage | match | :\Program Files\WindowsApps\Microsoft.WindowsTerminal_ | excludes:ParentImage field:"ParentImage" value:":\Program Files\WindowsApps\Microsoft.WindowsTerminal_" |
ParentImage | match | :\Windows\System32\cmd.exe | excludes:ParentImage field:"ParentImage" value:":\Windows\System32\cmd.exe" |
CommandLine | match | :\Program Files\Microsoft Visual Studio\ | excludes:CommandLine field:"CommandLine" value:":\Program Files\Microsoft Visual Studio\" |
CommandLine | match | Tools\Microsoft.VisualStudio.DevShell.dll | excludes:CommandLine field:"CommandLine" value:"Tools\Microsoft.VisualStudio.DevShell.dll" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
CommandLine | match |
| field:"CommandLine" kind:match |
Image | ends_with |
| field:"Image" kind:ends_with |
OriginalFileName | eq |
| field:"OriginalFileName" kind:eq |