PowerShell Share Enumeration Script
Detects PowerShell scripts that uses ShareFinder functions (Invoke-ShareFinder/Invoke-ShareFinderThreaded) or Windows share enumeration APIs (shi1_netname/shi1_remark with NetShareEnum/NetApiBufferFree). Attackers use share enumeration to map accessible network shares for collection, lateral movement, or ransomware targeting.
Rule type: query
Rule indices:
- winlogbeat-*
- logs-windows.powershell*
Rule Severity: high
Risk Score: 73
Runs every:
Searches indices from: now-9m
Maximum alerts per execution: 100
References:
- https://www.advintel.io/post/hunting-for-corporate-insurance-policies-indicators-of-ransom-exfiltrations
- https://thedfirreport.com/2022/04/04/stolen-images-campaign-ends-in-conti-ransomware/
- https://github.com/atc-project/atc-data/blob/master/docs/Logging_Policies/LP_0109_windows_powershell_script_block_log.md
Tags:
- Domain: Endpoint
- OS: Windows
- Use Case: Threat Detection
- Tactic: Discovery
- Tactic: Collection
- Tactic: Execution
- Resources: Investigation Guide
- Data Source: PowerShell Logs
Version: 114
Rule authors:
- Elastic
Rule license: Elastic License v2
PowerShell Script Block Logging must be enabled to generate the events used by this rule (e.g., 4104). Setup instructions: https://ela.st/powershell-logging-setup
Disclaimer: This guide was created by humans with the assistance of generative AI. While its contents have been manually curated to include the most valuable information, always validate assumptions and adjust procedures to match your internal runbooks and incident triage and response policies.
This alert indicates PowerShell script block content consistent with Windows network share enumeration. The matched text includes ShareFinder functions (for example, Invoke-ShareFinder or Invoke-ShareFinderThreaded) and/or native share enumeration API references (for example, NetShareEnum / NetApiBufferFree and shi1_netname / shi1_remark). Share discovery can be a normal administrative activity, but in attacks it is frequently used to map accessible shares prior to data collection, lateral movement, or impact activity.
user.name,user.domain,user.id: Account execution context for correlation, prioritization, and scoping.host.name,host.id: Host execution context for correlation, prioritization, and scoping.powershell.file.script_block_text: Script block content that matched the detection logic.powershell.file.script_block_id,powershell.sequence,powershell.total: Script block metadata to pivot to other fragments or reconstruct full script content when split across multiple events.file.path,file.directory,file.name: File-origin context when the script block is sourced from an on-disk file.powershell.file.script_block_length: Script block length (size) context.
Establish context and triage priority:
- Use
@timestampas the activity anchor and note the executinguser.name/user.domain/user.idand affectedhost.name/host.id. - Determine whether the account and host are expected to perform share inventory (for example, administrative workstation or management server vs. a standard user endpoint).
- Check whether similar share enumeration activity has occurred recently for the same
user.idor on the samehost.idto identify repeated scanning or automation.
- Use
Review the script block content and classify the activity:
- Inspect
powershell.file.script_block_textand capture relevant excerpts for the case record (function names, API calls, and any referenced hosts/shares). - Differentiate between a function definition/import and an actual invocation:
- Function definition or module load (lower confidence): the text contains the function name as part of a definition or import logic.
- Function invocation (higher confidence): the text shows parameters, target lists, or loops that initiate enumeration.
- Identify which pattern is present and what it implies about scope:
Invoke-ShareFinder: share discovery logic implemented in PowerShell.Invoke-ShareFinderThreaded: broader or faster discovery due to concurrent enumeration.NetShareEnum/NetApiBufferFreewithshi1_netname/shi1_remark: direct use of Windows share enumeration APIs and may reflect customized scripting.
- Extract scoping and intent details from the text when available:
- Target hostnames/IPs, server lists, domain-related identifiers, or UNC paths.
- Filters for share names and remarks, or include/exclude logic that focuses discovery on specific systems or shares.
- Use of alternate credentials or explicit authentication material embedded in the script (if present).
- Any output handling (formatting, writing results to disk, or staging).
- Inspect
Reconstruct full content when script blocks are split:
- Pivot on
powershell.file.script_block_idto collect all related fragments for the same execution context. - Use
powershell.sequenceandpowershell.totalto order fragments and identify missing pieces (if populated). - Review adjacent script blocks for the same
host.idanduser.idnear@timestampto capture supporting functions or follow-on actions that may not appear in the triggering fragment.
- Pivot on
Determine whether the activity originated from an on-disk script:
- If present, use
file.path/file.directory/file.nameto identify the script source. - Assess whether the script location and name align with approved administrative tooling. Scripts originating from user-writable or temporary locations are higher risk than centrally managed locations.
- If an on-disk script is involved, preserve the file for further analysis and determine whether it appears on additional hosts (pivot on
file.namewhere applicable).
- If present, use
Scope across users and hosts:
- Look for additional events containing the same discovery keywords in
powershell.file.script_block_textto identify other affected endpoints. - Check whether the same
user.idperformed similar activity from multiplehost.idvalues in a short period, which can indicate automation or credential misuse. - Identify whether multiple users are performing similar enumeration from the same host, which can indicate a shared jump box or a compromised administrative endpoint.
- Look for additional events containing the same discovery keywords in
Correlate with adjacent telemetry (as available) to confirm intent and detect follow-on behavior:
- Process execution telemetry on the same
host.idaround@timestampto determine how PowerShell was launched and whether the initiating process and execution pattern are consistent with expected activity foruser.id. - Network telemetry around
@timestampfor access to multiple remote hosts consistent with share enumeration and subsequent SMB activity. - Authentication telemetry for
user.idaround@timestampfor unusual access to file servers or multiple servers, especially if the behavior is new for the account. - File activity telemetry (endpoint and/or file server) for unusual access patterns to shared locations following the enumeration (for example, rapid directory traversal or access to sensitive paths).
- Process execution telemetry on the same
Assess risk and impact:
- Prioritize investigation if the script targets high-value systems (for example, file servers) or if the discovery appears broad (large target lists, threading, repeated runs).
- If the executing
user.idis privileged or the host is sensitive, treat the alert as higher risk and expand scoping to additional related activity.
- Legitimate administrative share inventory, auditing, or documentation activity performed by IT or infrastructure teams.
- Approved operational scripts used for backup validation, migration planning, access reviews, or troubleshooting that enumerate shares across servers.
If the activity is unauthorized or suspicious:
- Contain the affected endpoint (
host.id) following your incident response procedures to reduce the risk of further discovery and lateral movement. - Preserve evidence by retaining the complete
powershell.file.script_block_textcontent and all fragments linked bypowershell.file.script_block_id(including ordered reconstruction usingpowershell.sequence/powershell.totalwhen available). - Identify and prioritize potential targets referenced in the script content (servers and shares) and coordinate review of access patterns to those resources.
- Investigate the executing account (
user.name/user.id) for compromise, including recent authentication activity and unexpected resource access, and take appropriate containment actions (credential reset, privilege review, and session invalidation where applicable). - Expand hunting for additional share enumeration and subsequent access attempts associated with the same
user.idor originating from the samehost.id. - If an on-disk script was used (
file.path/file.namepresent), remove or quarantine the artifact per your response process and check for the same file on other systems.
- Contain the affected endpoint (
If the activity is confirmed benign:
- Document the owner, purpose, expected timing, and expected scope (accounts and endpoints) of the share enumeration.
- If tuning is required, scope it narrowly to stable identifiers present in the alert (for example, specific
user.idvalues and known managementhost.idendpoints) and continue to monitor for deviations from the expected pattern. - Consider establishing a documented allowlist of approved share inventory scripts and their expected execution locations to reduce future triage time.
event.category:process and host.os.type:windows and
powershell.file.script_block_text:(
"Invoke-ShareFinder" or
"Invoke-ShareFinderThreaded" or
(
"shi1_netname" and
"shi1_remark"
) or
(
"NetShareEnum" and
"NetApiBufferFree"
)
) and not user.id : "S-1-5-18"
Framework: MITRE ATT&CK
Tactic:
- Name: Discovery
- Id: TA0007
- Reference URL: https://attack.mitre.org/tactics/TA0007/
Technique:
- Name: Network Share Discovery
- Id: T1135
- Reference URL: https://attack.mitre.org/techniques/T1135/
Framework: MITRE ATT&CK
Tactic:
- Name: Execution
- Id: TA0002
- Reference URL: https://attack.mitre.org/tactics/TA0002/
Technique:
- Name: Command and Scripting Interpreter
- Id: T1059
- Reference URL: https://attack.mitre.org/techniques/T1059/
Sub Technique:
- Name: PowerShell
- Id: T1059.001
- Reference URL: https://attack.mitre.org/techniques/T1059/001/
Technique:
- Name: Native API
- Id: T1106
- Reference URL: https://attack.mitre.org/techniques/T1106/
Framework: MITRE ATT&CK
Tactic:
- Name: Collection
- Id: TA0009
- Reference URL: https://attack.mitre.org/tactics/TA0009/
Technique:
- Name: Data from Network Shared Drive
- Id: T1039
- Reference URL: https://attack.mitre.org/techniques/T1039/