2021-10-14 06:54:45 -03:00
[ metadata ]
creation_date = "2021/10/13"
2023-01-04 09:30:07 -05:00
integration = [ "windows" ]
2021-10-14 06:54:45 -03:00
maturity = "production"
2025-03-26 20:34:14 +05:30
updated_date = "2025/03/20"
2021-10-14 06:54:45 -03:00
[ rule ]
author = [ "Elastic" ]
description = "" "
2021-12-07 15:42:58 -09:00
This rule detects the use of discovery-related Windows API functions in PowerShell Scripts. Attackers can use these
2021-10-14 06:54:45 -03:00
functions to perform various situational awareness related activities, like enumerating users, shares, sessions, domain
2021-12-07 15:42:58 -09:00
trusts, groups, etc.
2021-10-14 06:54:45 -03:00
" ""
2022-02-16 13:42:06 -03:00
false_positives = [ "Legitimate PowerShell scripts that make use of these functions." ]
2021-10-14 06:54:45 -03:00
from = "now-9m"
2024-03-13 10:27:44 -03:00
index = [ "winlogbeat-*" , "logs-windows.powershell*" ]
2021-10-14 06:54:45 -03:00
language = "kuery"
license = "Elastic License v2"
name = "PowerShell Suspicious Discovery Related Windows API Functions"
2022-05-18 12:59:39 -03:00
note = "" "## Triage and analysis
2022-01-20 08:56:53 -03:00
### Investigating PowerShell Suspicious Discovery Related Windows API Functions
2023-01-09 08:28:10 -08:00
PowerShell is one of the main tools system administrators use for automation, report routines, and other tasks. This makes it available for use in various environments, and creates an attractive way for attackers to execute code.
2022-01-20 08:56:53 -03:00
2023-01-09 08:28:10 -08:00
Attackers can use PowerShell to interact with the Win32 API to bypass command line based detections, using libraries like PSReflect or Get-ProcAddress Cmdlet.
2022-01-20 08:56:53 -03:00
2022-03-31 11:29:30 -03:00
#### Possible investigation steps
2022-01-20 08:56:53 -03:00
2023-01-09 08:28:10 -08:00
- Examine the script content that triggered the detection; look for suspicious DLL imports, collection or exfiltration capabilities, suspicious functions, encoded or compressed data, and other potentially malicious characteristics.
- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
2022-05-18 12:59:39 -03:00
- Examine file or network events from the involved PowerShell process for suspicious behavior.
- Investigate other alerts associated with the user/host during the past 48 hours.
- Evaluate whether the user needs to use PowerShell to complete tasks.
- Check for additional PowerShell and command-line logs that indicate that imported functions were run.
2022-01-20 08:56:53 -03:00
2022-03-31 11:29:30 -03:00
### False positive analysis
2022-01-20 08:56:53 -03:00
2023-01-09 08:28:10 -08:00
- Discovery activities themselves are not inherently malicious if occurring in isolation, as long as the script does not contain other capabilities, and there are no other alerts related to the user or host; such alerts can be dismissed. However, analysts should keep in mind that this is not a common way of getting information, making it suspicious.
2022-01-20 08:56:53 -03:00
2022-03-31 11:29:30 -03:00
### Related rules
2022-01-20 08:56:53 -03:00
- PowerShell PSReflect Script - 56f2e9b5-4803-4e44-a0a4-a52dc79d57fe
2022-03-31 11:29:30 -03:00
### Response and remediation
2022-01-20 08:56:53 -03:00
2022-03-31 11:29:30 -03:00
- Initiate the incident response process based on the outcome of the triage.
2022-05-18 12:59:39 -03:00
- Isolate the involved hosts to prevent further post-compromise behavior.
- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
2023-01-09 08:28:10 -08:00
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
2023-10-30 16:53:04 +05:30
" ""
references = [
"https://github.com/BC-SECURITY/Empire/blob/9259e5106986847d2bb770c4289c0c0f1adf2344/data/module_source/situational_awareness/network/powerview.ps1#L21413" ,
"https://github.com/atc-project/atc-data/blob/master/docs/Logging_Policies/LP_0109_windows_powershell_script_block_log.md" ,
]
2024-07-22 08:39:40 -03:00
risk_score = 21
2023-10-30 16:53:04 +05:30
rule_id = "61ac3638-40a3-44b2-855a-985636ca985e"
2024-03-11 09:09:40 -03:00
setup = "" "## Setup
2022-01-20 08:56:53 -03:00
The 'PowerShell Script Block Logging' logging policy must be enabled.
2024-03-11 09:09:40 -03:00
Steps to implement the logging policy with Advanced Audit Configuration:
2022-01-20 08:56:53 -03:00
```
2022-07-18 15:41:32 -04:00
Computer Configuration >
Administrative Templates >
Windows PowerShell >
2022-01-20 08:56:53 -03:00
Turn on PowerShell Script Block Logging (Enable)
```
Steps to implement the logging policy via registry:
```
reg add " hklm \ \ SOFTWARE \ \ Policies \ \ Microsoft \ \ Windows \ \ PowerShell \ \ ScriptBlockLogging " /v EnableScriptBlockLogging /t REG_DWORD /d 1
```
" ""
2024-07-22 08:39:40 -03:00
severity = "low"
2025-03-26 20:34:14 +05:30
tags = [
"Domain: Endpoint" ,
"OS: Windows" ,
"Use Case: Threat Detection" ,
"Tactic: Discovery" ,
"Tactic: Collection" ,
"Tactic: Execution" ,
"Resources: Investigation Guide" ,
"Data Source: PowerShell Logs" ,
]
2021-10-14 06:54:45 -03:00
timestamp_override = "event.ingested"
type = "query"
query = '' '
2023-03-05 09:41:19 -09:00
event.category:process and host.os.type:windows and
2021-10-14 06:54:45 -03:00
powershell.file.script_block_text : (
NetShareEnum or
NetWkstaUserEnum or
NetSessionEnum or
NetLocalGroupEnum or
NetLocalGroupGetMembers or
DsGetSiteName or
DsEnumerateDomainTrusts or
WTSEnumerateSessionsEx or
WTSQuerySessionInformation or
LsaGetLogonSessionData or
2023-01-23 20:35:43 -03:00
QueryServiceObjectSecurity or
GetComputerNameEx or
NetWkstaGetInfo or
GetUserNameEx or
NetUserEnum or
NetUserGetInfo or
NetGroupEnum or
NetGroupGetInfo or
NetGroupGetUsers or
NetWkstaTransportEnum or
NetServerGetInfo or
LsaEnumerateTrustedDomains or
NetScheduleJobEnum or
NetUserModalsGet
2024-07-22 08:39:40 -03:00
) and
not powershell.file.script_block_text : (
("DsGetSiteName" and ("DiscoverWindowsComputerProperties.ps1" and "param($SourceType, $SourceId, $ManagedEntityId, $ComputerIdentity)")) or
("# Copyright: (c) 2018, Ansible Project" and "#Requires -Module Ansible.ModuleUtils.AddType" and "#AnsibleRequires -CSharpUtil Ansible.Basic") or
("Ansible.Windows.Setup" and "Ansible.Windows.Setup" and "NativeMethods.NetWkstaGetInfo(null, 100, out netBuffer);")
2023-07-14 15:41:36 -03:00
)
2021-10-14 06:54:45 -03:00
' ''
2025-03-26 20:34:14 +05:30
2024-04-01 17:44:50 -03:00
[ [ rule . filters ] ]
2025-03-26 20:34:14 +05:30
2024-04-01 17:44:50 -03:00
[ rule . filters . meta ]
negate = true
[ rule . filters . query . wildcard . "file.path" ]
2025-03-26 20:34:14 +05:30
case_insensitive = true
value = "?:\\\\ProgramData\\\\Microsoft\\\\Windows Defender Advanced Threat Protection\\\\DataCollection\\\\*"
2021-10-14 06:54:45 -03:00
[ [ rule . threat ] ]
framework = "MITRE ATT&CK"
2023-01-04 09:30:07 -05:00
[ [ rule . threat . technique ] ]
id = "T1069"
name = "Permission Groups Discovery"
reference = "https://attack.mitre.org/techniques/T1069/"
[ [ rule . threat . technique . subtechnique ] ]
id = "T1069.001"
name = "Local Groups"
reference = "https://attack.mitre.org/techniques/T1069/001/"
2025-03-26 20:34:14 +05:30
2023-01-23 20:35:43 -03:00
[ [ rule . threat . technique ] ]
id = "T1087"
name = "Account Discovery"
reference = "https://attack.mitre.org/techniques/T1087/"
[ [ rule . threat . technique . subtechnique ] ]
id = "T1087.001"
name = "Local Account"
reference = "https://attack.mitre.org/techniques/T1087/001/"
2021-10-14 06:54:45 -03:00
[ [ rule . threat . technique ] ]
id = "T1135"
name = "Network Share Discovery"
reference = "https://attack.mitre.org/techniques/T1135/"
2025-03-26 20:34:14 +05:30
[ [ rule . threat . technique ] ]
id = "T1482"
name = "Domain Trust Discovery"
reference = "https://attack.mitre.org/techniques/T1482/"
2021-10-14 06:54:45 -03:00
[ rule . threat . tactic ]
id = "TA0007"
name = "Discovery"
reference = "https://attack.mitre.org/tactics/TA0007/"
[ [ rule . threat ] ]
framework = "MITRE ATT&CK"
[ [ rule . threat . technique ] ]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[ [ rule . threat . technique . subtechnique ] ]
id = "T1059.001"
name = "PowerShell"
reference = "https://attack.mitre.org/techniques/T1059/001/"
[ [ rule . threat . technique ] ]
id = "T1106"
name = "Native API"
reference = "https://attack.mitre.org/techniques/T1106/"
[ rule . threat . tactic ]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
2023-10-15 18:12:20 -03:00
[ [ rule . threat ] ]
framework = "MITRE ATT&CK"
[ [ rule . threat . technique ] ]
id = "T1039"
name = "Data from Network Shared Drive"
reference = "https://attack.mitre.org/techniques/T1039/"
2025-03-26 20:34:14 +05:30
2023-10-15 18:12:20 -03:00
[ rule . threat . tactic ]
id = "TA0009"
name = "Collection"
reference = "https://attack.mitre.org/tactics/TA0009/"