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"
 5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
 6min_stack_version = "8.3.0"
 7updated_date = "2024/03/08"
 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 = ["Domain: Endpoint", "OS: Windows", "Use Case: Threat Detection", "Tactic: Discovery", "Tactic: Collection", "Tactic: Execution", "Resources: Investigation Guide", "Data Source: PowerShell Logs"]
 4timestamp_override = "event.ingested"
 5type = "query"
 6
 7query = '''
 8event.category:process and host.os.type:windows and
 9  powershell.file.script_block_text:(
10    "Invoke-ShareFinder" or
11    "Invoke-ShareFinderThreaded" or
12    (
13      "shi1_netname" and
14      "shi1_remark"
15    ) or
16    (
17      "NetShareEnum" and
18      "NetApiBufferFree"
19    )
20  ) and not user.id : "S-1-5-18"
21'''
22
23
24[[rule.threat]]
25framework = "MITRE ATT&CK"
26[[rule.threat.technique]]
27id = "T1135"
28name = "Network Share Discovery"
29reference = "https://attack.mitre.org/techniques/T1135/"
30
31
32[rule.threat.tactic]
33id = "TA0007"
34name = "Discovery"
35reference = "https://attack.mitre.org/tactics/TA0007/"
36[[rule.threat]]
37framework = "MITRE ATT&CK"
38[[rule.threat.technique]]
39id = "T1059"
40name = "Command and Scripting Interpreter"
41reference = "https://attack.mitre.org/techniques/T1059/"
42[[rule.threat.technique.subtechnique]]
43id = "T1059.001"
44name = "PowerShell"
45reference = "https://attack.mitre.org/techniques/T1059/001/"
46
47
48[[rule.threat.technique]]
49id = "T1106"
50name = "Native API"
51reference = "https://attack.mitre.org/techniques/T1106/"
52
53
54[rule.threat.tactic]
55id = "TA0002"
56name = "Execution"
57reference = "https://attack.mitre.org/tactics/TA0002/"
58
59[[rule.threat]]
60framework = "MITRE ATT&CK"
61
62[[rule.threat.technique]]
63id = "T1039"
64name = "Data from Network Shared Drive"
65reference = "https://attack.mitre.org/techniques/T1039/"
66
67[rule.threat.tactic]
68id = "TA0009"
69name = "Collection"
70reference = "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

to-top