Detection rules › Elastic
Potential Shadow Read via Unprivileged User
This rule detects instances where an unprivileged user changes to the shadow group, via a world-/user-writeable process, potentially indicating the execution of an exploit to read the shadow file.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Privilege Escalation | |
| Credential Access |
Rule body
[rule]
description = """
This rule detects instances where an unprivileged user changes to the shadow group, via a world-/user-writeable process,
potentially indicating the execution of an exploit to read the shadow file.
"""
id = "1d796727-35a3-4d2c-93f0-2a745554b252"
license = "Elastic License v2"
name = "Potential Shadow Read via Unprivileged User"
os_list = ["linux"]
reference = ["https://github.com/0xdeadbeefnetwork/ssh-keysign-pwn"]
version = "1.0.1"
query = '''
process where event.type == "change" and event.action == "gid_change" and
group.name == "shadow" and user.id >= 1000 and process.parent.user.id >= 1000 and process.parent.group.id >= 1000 and
(
process.parent.executable like (".*", "/tmp/*", "/dev/shm/*", "/var/tmp/*", "/home/*/*", "/run/user/*", "/var/run/user/*") or
process.executable like (".*", "/tmp/*", "/dev/shm/*", "/var/tmp/*", "/home/*/*", "/run/user/*", "/var/run/user/*")
) and
not (
process.group_leader.executable in (
"/usr/sbin/lightdm", "/usr/bin/xfce4-session", "/usr/bin/ksmserver", "/tmp/newroot/usr/bin/xfce4-session"
) or
process.executable in (
"/tmp/newroot/usr/bin/i3lock", "/tmp/newroot/newroot/newroot/usr/bin/i3lock", "/tmp/newroot/bin/bash"
)
)
'''
min_endpoint_version = "8.6.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0
[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1068"
name = "Exploitation for Privilege Escalation"
reference = "https://attack.mitre.org/techniques/T1068/"
[threat.tactic]
id = "TA0004"
name = "Privilege Escalation"
reference = "https://attack.mitre.org/tactics/TA0004/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1003"
name = "OS Credential Dumping"
reference = "https://attack.mitre.org/techniques/T1003/"
[[threat.technique.subtechnique]]
id = "T1003.008"
name = "/etc/passwd and /etc/shadow"
reference = "https://attack.mitre.org/techniques/T1003/008/"
[threat.tactic]
id = "TA0006"
name = "Credential Access"
reference = "https://attack.mitre.org/tactics/TA0006/"
[internal]
min_endpoint_version = "8.6.0"
Stages and Predicates
Stage 1: process
process where event.type == "change" and event.action == "gid_change" and
group.name == "shadow" and user.id >= 1000 and process.parent.user.id >= 1000 and process.parent.group.id >= 1000 and
(
process.parent.executable like (".*", "/tmp/*", "/dev/shm/*", "/var/tmp/*", "/home/*/*", "/run/user/*", "/var/run/user/*") or
process.executable like (".*", "/tmp/*", "/dev/shm/*", "/var/tmp/*", "/home/*/*", "/run/user/*", "/var/run/user/*")
) and
not (
process.group_leader.executable in (
"/usr/sbin/lightdm", "/usr/bin/xfce4-session", "/usr/bin/ksmserver", "/tmp/newroot/usr/bin/xfce4-session"
) or
process.executable in (
"/tmp/newroot/usr/bin/i3lock", "/tmp/newroot/newroot/newroot/usr/bin/i3lock", "/tmp/newroot/bin/bash"
)
)
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.executable | in | /tmp/newroot/bin/bash, /tmp/newroot/newroot/newroot/usr/bin/i3lock, /tmp/newroot/usr/bin/i3lock | excludes:process.executable field:"process.executable" value:"/tmp/newroot/bin/bash" field:"process.executable" value:"/tmp/newroot/newroot/newroot/usr/bin/i3lock" field:"process.executable" value:"/tmp/newroot/usr/bin/i3lock" |
process.group_leader.executable | in | /tmp/newroot/usr/bin/xfce4-session, /usr/bin/ksmserver, /usr/bin/xfce4-session, /usr/sbin/lightdm | excludes:process.group_leader.executable |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq value:"gid_change" |
event.type | eq |
| field:"event.type" kind:eq value:"change" |
group.name | eq |
| field:"group.name" kind:eq value:"shadow" |
process.executable | wildcard |
| field:"Image" kind:wildcard |
process.parent.executable | wildcard |
| field:"ParentImage" kind:wildcard |
process.parent.group.id | ge |
| field:"process.parent.group.id" kind:ge value:"1000" |
process.parent.user.id | ge |
| field:"process.parent.user.id" kind:ge value:"1000" |
user.id | ge |
| field:"user.id" kind:ge value:"1000" |