Potential Sudo Hijacking
Identifies the creation of a sudo binary located at /usr/bin/sudo. Attackers may hijack the default sudo binary and replace it with a custom binary or script that can read the user's password in clear text to escalate privileges or enable persistence onto the system every time the sudo binary is executed.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/07/26"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2024/09/23"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies the creation of a sudo binary located at /usr/bin/sudo. Attackers may hijack the default sudo binary and
11replace it with a custom binary or script that can read the user's password in clear text to escalate privileges or
12enable persistence onto the system every time the sudo binary is executed.
13"""
14from = "now-9m"
15index = ["logs-endpoint.events.file*"]
16language = "eql"
17license = "Elastic License v2"
18name = "Potential Sudo Hijacking"
19references = [
20 "https://eapolsniper.github.io/2020/08/17/Sudo-Hijacking/",
21 "https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms",
22]
23risk_score = 47
24rule_id = "88fdcb8c-60e5-46ee-9206-2663adf1b1ce"
25setup = """## Setup
26
27This rule requires data coming in from Elastic Defend.
28
29### Elastic Defend Integration Setup
30Elastic 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.
31
32#### Prerequisite Requirements:
33- Fleet is required for Elastic Defend.
34- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
35
36#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
37- Go to the Kibana home page and click "Add integrations".
38- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
39- Click "Add Elastic Defend".
40- Configure the integration name and optionally add a description.
41- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
42- 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).
43- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
44- 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.
45For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
46- Click "Save and Continue".
47- 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.
48For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
49"""
50severity = "medium"
51tags = [
52 "Domain: Endpoint",
53 "OS: Linux",
54 "Use Case: Threat Detection",
55 "Tactic: Privilege Escalation",
56 "Tactic: Persistence",
57 "Data Source: Elastic Defend",
58]
59timestamp_override = "event.ingested"
60type = "eql"
61
62query = '''
63file where host.os.type == "linux" and event.action in ("creation", "rename") and
64file.path in ("/usr/bin/sudo", "/bin/sudo") and not (
65 file.Ext.original.path in ("/usr/bin/sudo", "/bin/sudo") or
66 process.executable in (
67 "/bin/dpkg", "/usr/bin/dpkg", "/bin/dockerd", "/usr/bin/dockerd", "/usr/sbin/dockerd", "/bin/microdnf",
68 "/bin/rpm", "/usr/bin/rpm", "/bin/snapd", "/usr/bin/snapd", "/bin/yum", "/usr/bin/yum", "/bin/dnf", "/usr/bin/dnf",
69 "/bin/podman", "/usr/bin/podman", "/bin/dnf-automatic", "/usr/bin/dnf-automatic", "/bin/pacman", "/usr/bin/pacman",
70 "/usr/bin/dpkg-divert", "/bin/dpkg-divert", "/sbin/apk", "/usr/sbin/apk", "/usr/local/sbin/apk", "/usr/bin/apt",
71 "/usr/sbin/pacman", "/usr/bin/microdnf", "/usr/local/bin/dockerd", "/usr/local/bin/podman", "/usr/local/bin/dnf",
72 "/kaniko/executor", "/proc/self/exe", "/usr/bin/apt-get", "/usr/bin/apt-cache", "/usr/bin/apt-mark"
73 ) or
74 file.Ext.original.extension == "dpkg-new" or
75 process.executable : (
76 "/nix/store/*", "/var/lib/dpkg/*", "/tmp/vmis.*", "/snap/*", "/dev/fd/*", "/var/lib/docker/*"
77 ) or
78 process.executable == null or
79 (process.name == "sed" and file.name : "sed*")
80)
81'''
82
83
84[[rule.threat]]
85framework = "MITRE ATT&CK"
86[[rule.threat.technique]]
87id = "T1548"
88name = "Abuse Elevation Control Mechanism"
89reference = "https://attack.mitre.org/techniques/T1548/"
90[[rule.threat.technique.subtechnique]]
91id = "T1548.003"
92name = "Sudo and Sudo Caching"
93reference = "https://attack.mitre.org/techniques/T1548/003/"
94
95
96
97[rule.threat.tactic]
98id = "TA0004"
99name = "Privilege Escalation"
100reference = "https://attack.mitre.org/tactics/TA0004/"
101[[rule.threat]]
102framework = "MITRE ATT&CK"
103[[rule.threat.technique]]
104id = "T1574"
105name = "Hijack Execution Flow"
106reference = "https://attack.mitre.org/techniques/T1574/"
107
108
109[rule.threat.tactic]
110id = "TA0003"
111name = "Persistence"
112reference = "https://attack.mitre.org/tactics/TA0003/"
References
Related rules
- At Job Created or Modified
- Systemd Service Started by Unusual Parent Process
- Process Capability Set via setcap Utility
- Potential Suspicious File Edit
- Deprecated - Potential Process Injection via LD_PRELOAD Environment Variable