Potential Shadow File Read via Command Line Utilities

Identifies access to the /etc/shadow file via the commandline using standard system utilities. After elevating privileges to root, threat actors may attempt to read or dump this file in order to gain valid credentials. They may utilize these to move laterally undetected and access additional resources.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2022/09/01"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/01/15"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Identifies access to the /etc/shadow file via the commandline using standard system utilities. After elevating
 11privileges to root, threat actors may attempt to read or dump this file in order to gain valid credentials. They may
 12utilize these to move laterally undetected and access additional resources.
 13"""
 14from = "now-9m"
 15index = ["logs-endpoint.events.*", "endgame-*"]
 16language = "kuery"
 17license = "Elastic License v2"
 18name = "Potential Shadow File Read via Command Line Utilities"
 19references = ["https://www.cyberciti.biz/faq/unix-linux-password-cracking-john-the-ripper/"]
 20risk_score = 47
 21rule_id = "9a3a3689-8ed1-4cdb-83fb-9506db54c61f"
 22setup = """## Setup
 23
 24This rule requires data coming in from Elastic Defend.
 25
 26### Elastic Defend Integration Setup
 27Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
 28
 29#### Prerequisite Requirements:
 30- Fleet is required for Elastic Defend.
 31- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 32
 33#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 34- Go to the Kibana home page and click "Add integrations".
 35- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 36- Click "Add Elastic Defend".
 37- Configure the integration name and optionally add a description.
 38- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 39- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
 40- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 41- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
 42For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 43- Click "Save and Continue".
 44- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
 45For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 46"""
 47severity = "medium"
 48tags = [
 49    "Domain: Endpoint",
 50    "OS: Linux",
 51    "Use Case: Threat Detection",
 52    "Tactic: Privilege Escalation",
 53    "Tactic: Credential Access",
 54    "Data Source: Elastic Endgame",
 55    "Data Source: Elastic Defend",
 56    "Resources: Investigation Guide",
 57]
 58timestamp_override = "event.ingested"
 59type = "new_terms"
 60query = '''
 61host.os.type : "linux" and event.category : "process" and event.action : ("exec" or "exec_event") and
 62(process.args : "/etc/shadow" or (process.working_directory: "/etc" and process.args: "shadow")) and not (
 63  (process.executable : ("/bin/chown" or "/usr/bin/chown") and process.args : "root:shadow") or
 64  (process.executable : ("/bin/chmod" or "/usr/bin/chmod") and process.args : "640") or
 65  process.executable:(/vz/* or /var/lib/docker/* or /run/containerd/* or /tmp/.criu* or /tmp/newroot/*) or
 66  process.parent.name:(gen_passwd_sets or scc_* or wazuh-modulesd)
 67)
 68'''
 69note = """## Triage and analysis
 70
 71> **Disclaimer**:
 72> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
 73
 74### Investigating Potential Shadow File Read via Command Line Utilities
 75
 76In Linux environments, the `/etc/shadow` file stores hashed passwords, making it a prime target for attackers seeking credential access. Adversaries with elevated privileges may exploit command-line utilities to read this file, aiming to extract credentials for lateral movement. The detection rule identifies suspicious access attempts by monitoring process activities related to the file, excluding legitimate operations, thus highlighting potential unauthorized access attempts.
 77
 78### Possible investigation steps
 79
 80- Review the process details to identify the executable and arguments used, focusing on the process.args field to confirm access attempts to /etc/shadow.
 81- Check the process.parent.name field to determine the parent process and assess if it is associated with known legitimate activities or suspicious behavior.
 82- Investigate the user context under which the process was executed to verify if the user had legitimate reasons to access the /etc/shadow file.
 83- Examine the host's recent activity logs for any privilege escalation events that might have preceded the access attempt, indicating potential unauthorized privilege elevation.
 84- Correlate the event with other alerts or logs from the same host to identify patterns or sequences of actions that suggest lateral movement or further credential access attempts.
 85- Assess the environment for any recent changes or deployments that might explain the access attempt, such as updates or configuration changes involving user management.
 86
 87### False positive analysis
 88
 89- System maintenance tasks may trigger alerts when legitimate processes like chown or chmod access the /etc/shadow file. To handle these, consider excluding these specific processes when they are executed by trusted system administrators during scheduled maintenance.
 90- Containerized environments might generate false positives if processes within containers access the /etc/shadow file. Exclude paths such as /var/lib/docker/* or /run/containerd/* to reduce noise from container operations.
 91- Security tools like wazuh-modulesd or custom scripts (e.g., gen_passwd_sets) that legitimately interact with the /etc/shadow file for monitoring or compliance checks can be excluded by adding them to the process.parent.name exclusion list.
 92- Automated scripts or cron jobs that perform routine checks or updates on system files, including /etc/shadow, should be reviewed and, if deemed safe, excluded from triggering alerts by specifying their process names or paths in the exclusion criteria.
 93
 94### Response and remediation
 95
 96- Immediately isolate the affected system from the network to prevent further unauthorized access or lateral movement.
 97- Terminate any suspicious processes identified in the alert that are attempting to access the /etc/shadow file.
 98- Conduct a thorough review of user accounts and privileges on the affected system to identify any unauthorized privilege escalations or account creations.
 99- Change all passwords for accounts on the affected system, especially those with elevated privileges, to mitigate the risk of credential compromise.
100- Review and update access controls and permissions for sensitive files like /etc/shadow to ensure they are restricted to only necessary users and processes.
101- Monitor for any further attempts to access the /etc/shadow file across the network, using enhanced logging and alerting mechanisms to detect similar threats.
102- Escalate the incident to the security operations team for further investigation and to determine if additional systems have been compromised."""
103
104[[rule.threat]]
105framework = "MITRE ATT&CK"
106
107[[rule.threat.technique]]
108id = "T1068"
109name = "Exploitation for Privilege Escalation"
110reference = "https://attack.mitre.org/techniques/T1068/"
111
112[rule.threat.tactic]
113id = "TA0004"
114name = "Privilege Escalation"
115reference = "https://attack.mitre.org/tactics/TA0004/"
116[[rule.threat]]
117framework = "MITRE ATT&CK"
118
119[[rule.threat.technique]]
120id = "T1003"
121name = "OS Credential Dumping"
122reference = "https://attack.mitre.org/techniques/T1003/"
123
124[[rule.threat.technique.subtechnique]]
125id = "T1003.008"
126name = "/etc/passwd and /etc/shadow"
127reference = "https://attack.mitre.org/techniques/T1003/008/"
128
129[rule.threat.tactic]
130id = "TA0006"
131name = "Credential Access"
132reference = "https://attack.mitre.org/tactics/TA0006/"
133
134[rule.new_terms]
135field = "new_terms_fields"
136value = ["process.executable"]
137
138[[rule.new_terms.history_window_start]]
139field = "history_window_start"
140value = "now-10d"

Triage and analysis

Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

Investigating Potential Shadow File Read via Command Line Utilities

In Linux environments, the /etc/shadow file stores hashed passwords, making it a prime target for attackers seeking credential access. Adversaries with elevated privileges may exploit command-line utilities to read this file, aiming to extract credentials for lateral movement. The detection rule identifies suspicious access attempts by monitoring process activities related to the file, excluding legitimate operations, thus highlighting potential unauthorized access attempts.

Possible investigation steps

  • Review the process details to identify the executable and arguments used, focusing on the process.args field to confirm access attempts to /etc/shadow.
  • Check the process.parent.name field to determine the parent process and assess if it is associated with known legitimate activities or suspicious behavior.
  • Investigate the user context under which the process was executed to verify if the user had legitimate reasons to access the /etc/shadow file.
  • Examine the host's recent activity logs for any privilege escalation events that might have preceded the access attempt, indicating potential unauthorized privilege elevation.
  • Correlate the event with other alerts or logs from the same host to identify patterns or sequences of actions that suggest lateral movement or further credential access attempts.
  • Assess the environment for any recent changes or deployments that might explain the access attempt, such as updates or configuration changes involving user management.

False positive analysis

  • System maintenance tasks may trigger alerts when legitimate processes like chown or chmod access the /etc/shadow file. To handle these, consider excluding these specific processes when they are executed by trusted system administrators during scheduled maintenance.
  • Containerized environments might generate false positives if processes within containers access the /etc/shadow file. Exclude paths such as /var/lib/docker/* or /run/containerd/* to reduce noise from container operations.
  • Security tools like wazuh-modulesd or custom scripts (e.g., gen_passwd_sets) that legitimately interact with the /etc/shadow file for monitoring or compliance checks can be excluded by adding them to the process.parent.name exclusion list.
  • Automated scripts or cron jobs that perform routine checks or updates on system files, including /etc/shadow, should be reviewed and, if deemed safe, excluded from triggering alerts by specifying their process names or paths in the exclusion criteria.

Response and remediation

  • Immediately isolate the affected system from the network to prevent further unauthorized access or lateral movement.
  • Terminate any suspicious processes identified in the alert that are attempting to access the /etc/shadow file.
  • Conduct a thorough review of user accounts and privileges on the affected system to identify any unauthorized privilege escalations or account creations.
  • Change all passwords for accounts on the affected system, especially those with elevated privileges, to mitigate the risk of credential compromise.
  • Review and update access controls and permissions for sensitive files like /etc/shadow to ensure they are restricted to only necessary users and processes.
  • Monitor for any further attempts to access the /etc/shadow file across the network, using enhanced logging and alerting mechanisms to detect similar threats.
  • Escalate the incident to the security operations team for further investigation and to determine if additional systems have been compromised.

References

Related rules

to-top