PowerShell Suspicious Discovery Related Windows API Functions

Last updated 9 months ago on 2025-03-20
Created 4 years ago on 2021-10-13

About

This rule detects the use of discovery-related Windows API functions in PowerShell Scripts. Attackers can use these functions to perform various situational awareness related activities, like enumerating users, shares, sessions, domain trusts, groups, etc.
Tags
Domain: EndpointOS: WindowsUse Case: Threat DetectionTactic: DiscoveryTactic: CollectionTactic: ExecutionData Source: PowerShell LogsLanguage: kuery
Severity
low
Risk Score
21
MITRE ATT&CK™

Discovery (TA0007)(external, opens in a new tab or window)

Execution (TA0002)(external, opens in a new tab or window)

Collection (TA0009)(external, opens in a new tab or window)

False Positive Examples
Legitimate PowerShell scripts that make use of these functions.
License
Elastic License v2(external, opens in a new tab or window)

Definition

Rule Type
Query (Kibana Query Language)
Integration Pack
Prebuilt Security Detection Rules
Index Patterns
winlogbeat-*logs-windows.powershell*
Related Integrations

windows(external, opens in a new tab or window)

Query
text code block:
event.category:process and host.os.type:windows and 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 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 ) 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);") )

Install detection rules in Elastic Security

Detect PowerShell Suspicious Discovery Related Windows API Functions in the Elastic Security detection engine by installing this rule into your Elastic Stack.

To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).