Hosts File Modified

The hosts file on endpoints is used to control manual IP address to hostname resolutions. The hosts file is the first point of lookup for DNS hostname resolution so if adversaries can modify the endpoint hosts file, they can route traffic to malicious infrastructure. This rule detects modifications to the hosts file on Microsoft Windows, Linux (Ubuntu or RHEL) and macOS systems.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/07/07"
  3integration = ["endpoint", "windows"]
  4maturity = "production"
  5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
  6min_stack_version = "8.3.0"
  7updated_date = "2023/10/19"
  8
  9[rule]
 10author = ["Elastic"]
 11description = """
 12The hosts file on endpoints is used to control manual IP address to hostname resolutions. The hosts file is the first
 13point of lookup for DNS hostname resolution so if adversaries can modify the endpoint hosts file, they can route traffic
 14to malicious infrastructure. This rule detects modifications to the hosts file on Microsoft Windows, Linux (Ubuntu or
 15RHEL) and macOS systems.
 16"""
 17from = "now-9m"
 18index = ["auditbeat-*", "winlogbeat-*", "logs-endpoint.events.*", "logs-windows.*"]
 19language = "eql"
 20license = "Elastic License v2"
 21name = "Hosts File Modified"
 22note = """## Triage and analysis
 23
 24### Investigating Hosts File Modified
 25
 26Operating systems use the hosts file to map a connection between an IP address and domain names before going to domain name servers. Attackers can abuse this mechanism to route traffic to malicious infrastructure or disrupt security that depends on server communications. For example, Russian threat actors modified this file on a domain controller to redirect Duo MFA calls to localhost instead of the Duo server, which prevented the MFA service from contacting its server to validate MFA login. This effectively disabled MFA for active domain accounts because the default policy of Duo for Windows is to "Fail open" if the MFA server is unreachable. This can happen in any MFA implementation and is not exclusive to Duo. Find more details in this [CISA Alert](https://www.cisa.gov/uscert/ncas/alerts/aa22-074a).
 27
 28This rule identifies modifications in the hosts file across multiple operating systems using process creation events for Linux and file events in Windows and macOS.
 29
 30#### Possible investigation steps
 31
 32- Identify the specifics of the involved assets, such as role, criticality, and associated users.
 33- Investigate the process 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.
 34- Identify the user account that performed the action and whether it should perform this kind of action.
 35- Contact the account owner and confirm whether they are aware of this activity.
 36- Investigate other alerts associated with the user/host during the past 48 hours.
 37- Examine the changes to the hosts file by comparing it against file backups, volume shadow copies, and other restoration mechanisms.
 38
 39### False positive analysis
 40
 41- This mechanism can be used legitimately. Analysts can dismiss the alert if the administrator is aware of the activity and the configuration was justified.
 42
 43### Response and remediation
 44
 45- Initiate the incident response process based on the outcome of the triage.
 46- Consider isolating the involved host 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- Review the privileges of the administrator account that performed the action.
 49- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 50- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 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 = ["https://www.elastic.co/guide/en/beats/auditbeat/current/auditbeat-reference-yml.html"]
 54risk_score = 47
 55rule_id = "9c260313-c811-4ec8-ab89-8f6530e0246c"
 56setup = """## Setup
 57
 58For Windows systems using Auditbeat, this rule requires adding `C:/Windows/System32/drivers/etc` as an additional path in the 'file_integrity' module of auditbeat.yml.
 59
 60If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2,
 61events will not define `event.ingested` and default fallback for EQL rules was not added until version 8.2.
 62Hence for this rule to work effectively, users will need to add a custom ingest pipeline to populate
 63`event.ingested` to @timestamp.
 64For more details on adding a custom ingest pipeline refer - https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html
 65"""
 66severity = "medium"
 67tags = ["Domain: Endpoint", "OS: Linux", "OS: Windows", "OS: macOS", "Use Case: Threat Detection", "Tactic: Impact", "Resources: Investigation Guide", "Data Source: Elastic Defend"]
 68timeline_id = "4d4c0b59-ea83-483f-b8c1-8c360ee53c5c"
 69timeline_title = "Comprehensive File Timeline"
 70timestamp_override = "event.ingested"
 71type = "eql"
 72
 73query = '''
 74any where
 75
 76  /* file events for creation; file change events are not captured by some of the included sources for linux and so may
 77     miss this, which is the purpose of the process + command line args logic below */
 78  (
 79   event.category == "file" and event.type in ("change", "creation") and
 80     file.path : ("/private/etc/hosts", "/etc/hosts", "?:\\Windows\\System32\\drivers\\etc\\hosts") and 
 81     not process.name in ("dockerd", "rootlesskit", "podman", "crio")
 82  )
 83  or
 84
 85  /* process events for change targeting linux only */
 86  (
 87   event.category == "process" and event.type in ("start") and
 88     process.name in ("nano", "vim", "vi", "emacs", "echo", "sed") and
 89     process.args : ("/etc/hosts") and 
 90     not process.parent.name in ("dhclient-script", "google_set_hostname")
 91  )
 92'''
 93
 94[[rule.threat]]
 95framework = "MITRE ATT&CK"
 96
 97[[rule.threat.technique]]
 98id = "T1565"
 99name = "Data Manipulation"
100reference = "https://attack.mitre.org/techniques/T1565/"
101
102[[rule.threat.technique.subtechnique]]
103id = "T1565.001"
104name = "Stored Data Manipulation"
105reference = "https://attack.mitre.org/techniques/T1565/001/"
106
107[rule.threat.tactic]
108id = "TA0040"
109name = "Impact"
110reference = "https://attack.mitre.org/tactics/TA0040/"

Triage and analysis

Investigating Hosts File Modified

Operating systems use the hosts file to map a connection between an IP address and domain names before going to domain name servers. Attackers can abuse this mechanism to route traffic to malicious infrastructure or disrupt security that depends on server communications. For example, Russian threat actors modified this file on a domain controller to redirect Duo MFA calls to localhost instead of the Duo server, which prevented the MFA service from contacting its server to validate MFA login. This effectively disabled MFA for active domain accounts because the default policy of Duo for Windows is to "Fail open" if the MFA server is unreachable. This can happen in any MFA implementation and is not exclusive to Duo. Find more details in this CISA Alert.

This rule identifies modifications in the hosts file across multiple operating systems using process creation events for Linux and file events in Windows and macOS.

Possible investigation steps

  • Identify the specifics of the involved assets, such as role, criticality, and associated users.
  • Investigate the process 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.
  • Identify the user account that performed the action and whether it should perform this kind of action.
  • 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.
  • Examine the changes to the hosts file by comparing it against file backups, volume shadow copies, and other restoration mechanisms.

False positive analysis

  • This mechanism can be used legitimately. Analysts can dismiss the alert if the administrator is aware of the activity and the configuration was justified.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Consider isolating the involved host 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.
  • Review the privileges of the administrator account that performed the action.
  • 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.
  • 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