PowerShell Suspicious Discovery Related Windows API Functions

Last updated a month ago on 2026-02-09
Created 4 years ago on 2021-10-13

About

Detects PowerShell scripts that references native Windows API functions commonly used for discovery of users, groups, shares, sessions, domain trusts, and service security. Attackers use these APIs for situational awareness and targeting prior to lateral movement or collection.
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);") ) and not file.directory: "C:\Program Files (x86)\Automox\WDK\Win32\WinSession"

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).