PowerShell Share Enumeration Script
Detects scripts that contain PowerShell functions, structures, or Windows API functions related to windows share enumeration activities. Attackers, mainly ransomware groups, commonly identify and inspect network shares, looking for critical information for encryption and/or exfiltration.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2022/08/17"
3integration = ["windows"]
4maturity = "production"
5updated_date = "2024/10/28"
6min_stack_version = "8.14.0"
7min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
8
9[rule]
10author = ["Elastic"]
11description = """
12Detects scripts that contain PowerShell functions, structures, or Windows API functions related to windows share
13enumeration activities. Attackers, mainly ransomware groups, commonly identify and inspect network shares, looking for
14critical information for encryption and/or exfiltration.
15"""
16from = "now-9m"
17index = ["winlogbeat-*", "logs-windows.powershell*"]
18language = "kuery"
19license = "Elastic License v2"
20name = "PowerShell Share Enumeration Script"
21note = """## Triage and analysis
22
23### Investigating PowerShell Share Enumeration Script
24
25PowerShell 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.
26
27Attackers can use PowerShell to enumerate shares to search for sensitive data like documents, scripts, and other kinds of valuable data for encryption, exfiltration, and lateral movement.
28
29#### Possible investigation steps
30
31- 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.
32- 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.
33- Contact the account owner and confirm whether they are aware of this activity.
34- Investigate other alerts associated with the user/host during the past 48 hours.
35- Evaluate whether the user needs to use PowerShell to complete tasks.
36- Check for additional PowerShell and command line logs that indicate that imported functions were run.
37 - Evaluate which information was potentially mapped and accessed by the attacker.
38
39### False positive analysis
40
41- This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
42
43### Response and remediation
44
45- Initiate the incident response process based on the outcome of the triage.
46- Isolate the involved hosts to prevent further post-compromise behavior.
47- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
48- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
49- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
50- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
51- 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).
52"""
53references = [
54 "https://www.advintel.io/post/hunting-for-corporate-insurance-policies-indicators-of-ransom-exfiltrations",
55 "https://thedfirreport.com/2022/04/04/stolen-images-campaign-ends-in-conti-ransomware/",
56 "https://github.com/atc-project/atc-data/blob/master/docs/Logging_Policies/LP_0109_windows_powershell_script_block_log.md",
57]
58risk_score = 47
59rule_id = "4c59cff1-b78a-41b8-a9f1-4231984d1fb6"
60setup = """## Setup
61
62The 'PowerShell Script Block Logging' logging policy must be configured (Enable).
63
64Steps to implement the logging policy with Advanced Audit Configuration:
Computer Configuration > Administrative Templates > Windows PowerShell > Turn on PowerShell Script Block Logging (Enable)
1
2Steps to implement the logging policy via registry:
reg add "hklm\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
1"""
2severity = "medium"
3tags = [
4 "Domain: Endpoint",
5 "OS: Windows",
6 "Use Case: Threat Detection",
7 "Tactic: Discovery",
8 "Tactic: Collection",
9 "Tactic: Execution",
10 "Resources: Investigation Guide",
11 "Data Source: PowerShell Logs",
12]
13timestamp_override = "event.ingested"
14type = "query"
15
16query = '''
17event.category:process and host.os.type:windows and
18 powershell.file.script_block_text:(
19 "Invoke-ShareFinder" or
20 "Invoke-ShareFinderThreaded" or
21 (
22 "shi1_netname" and
23 "shi1_remark"
24 ) or
25 (
26 "NetShareEnum" and
27 "NetApiBufferFree"
28 )
29 ) and not user.id : "S-1-5-18"
30'''
31
32
33[[rule.threat]]
34framework = "MITRE ATT&CK"
35[[rule.threat.technique]]
36id = "T1135"
37name = "Network Share Discovery"
38reference = "https://attack.mitre.org/techniques/T1135/"
39
40
41[rule.threat.tactic]
42id = "TA0007"
43name = "Discovery"
44reference = "https://attack.mitre.org/tactics/TA0007/"
45[[rule.threat]]
46framework = "MITRE ATT&CK"
47[[rule.threat.technique]]
48id = "T1059"
49name = "Command and Scripting Interpreter"
50reference = "https://attack.mitre.org/techniques/T1059/"
51[[rule.threat.technique.subtechnique]]
52id = "T1059.001"
53name = "PowerShell"
54reference = "https://attack.mitre.org/techniques/T1059/001/"
55
56
57[[rule.threat.technique]]
58id = "T1106"
59name = "Native API"
60reference = "https://attack.mitre.org/techniques/T1106/"
61
62
63[rule.threat.tactic]
64id = "TA0002"
65name = "Execution"
66reference = "https://attack.mitre.org/tactics/TA0002/"
67[[rule.threat]]
68framework = "MITRE ATT&CK"
69[[rule.threat.technique]]
70id = "T1039"
71name = "Data from Network Shared Drive"
72reference = "https://attack.mitre.org/techniques/T1039/"
73
74
75[rule.threat.tactic]
76id = "TA0009"
77name = "Collection"
78reference = "https://attack.mitre.org/tactics/TA0009/"
Triage and analysis
Investigating PowerShell Share Enumeration Script
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.
Attackers can use PowerShell to enumerate shares to search for sensitive data like documents, scripts, and other kinds of valuable data for encryption, exfiltration, and lateral movement.
Possible investigation steps
- 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.
- Contact the account owner and confirm whether they are aware of this activity.
- 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.
- Evaluate which information was potentially mapped and accessed by the attacker.
False positive analysis
- This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved hosts to prevent further post-compromise behavior.
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
- 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).
References
Related rules
- PowerShell Suspicious Discovery Related Windows API Functions
- Exchange Mailbox Export via PowerShell
- Potential Process Injection via PowerShell
- PowerShell Keylogging Script
- PowerShell Mailbox Collection Script