2022-10-19 20:56:32 +00:00
|
|
|
-- Find processes that run with a lower effective UID than their parent (state-based)
|
2022-10-07 16:46:55 +00:00
|
|
|
--
|
2022-10-19 20:56:32 +00:00
|
|
|
-- references:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1548/001/ (Setuid and Setgid)
|
|
|
|
-- * https://cybersecurity.att.com/blogs/labs-research/shikitega-new-stealthy-malware-targeting-linux
|
|
|
|
--
|
|
|
|
-- related:
|
2022-10-07 16:46:55 +00:00
|
|
|
-- * unexpected-privilege-escalation-events.sql
|
2022-10-13 18:59:32 +00:00
|
|
|
--
|
2022-10-17 12:43:29 +00:00
|
|
|
-- tags: transient rapid state process escalation
|
2022-11-08 01:36:37 +00:00
|
|
|
-- platform: linux
|
2022-09-24 15:12:23 +00:00
|
|
|
SELECT
|
|
|
|
p.pid AS child_pid,
|
|
|
|
p.path AS child_path,
|
|
|
|
p.name AS child_name,
|
|
|
|
p.cmdline AS child_cmdline,
|
|
|
|
p.euid AS child_euid,
|
|
|
|
p.state AS child_state,
|
|
|
|
file.mode AS child_mode,
|
|
|
|
hash.sha256 AS child_hash,
|
|
|
|
p.parent AS parent_pid,
|
|
|
|
pp.path AS parent_path,
|
|
|
|
pp.name AS parent_name,
|
|
|
|
pp.cmdline AS parent_cmdline,
|
|
|
|
pp.euid AS parent_euid,
|
|
|
|
pfile.mode AS parent_mode,
|
2022-11-08 01:36:37 +00:00
|
|
|
phash.sha256 AS parent_hash
|
2022-09-24 15:12:23 +00:00
|
|
|
FROM
|
|
|
|
processes p
|
|
|
|
JOIN processes pp ON p.parent = pp.pid
|
|
|
|
LEFT JOIN file ON p.path = file.path
|
|
|
|
LEFT JOIN hash ON p.path = hash.path
|
2022-10-21 21:38:29 +00:00
|
|
|
LEFT JOIN file AS pfile ON pp.path = pfile.path
|
|
|
|
LEFT JOIN hash AS phash ON pp.path = phash.path
|
2022-09-24 15:12:23 +00:00
|
|
|
WHERE
|
2022-11-08 01:36:37 +00:00
|
|
|
p.euid < p.uid
|
2022-09-24 15:12:23 +00:00
|
|
|
AND p.path NOT IN (
|
2022-11-03 15:51:54 +00:00
|
|
|
'/bin/ps',
|
|
|
|
'/usr/bin/doas',
|
2022-09-24 15:12:23 +00:00
|
|
|
'/usr/bin/fusermount',
|
|
|
|
'/usr/bin/fusermount3',
|
2023-01-27 01:40:47 +00:00
|
|
|
'/usr/libexec/Xorg',
|
2022-09-24 15:12:23 +00:00
|
|
|
'/usr/bin/login',
|
2022-11-03 15:51:54 +00:00
|
|
|
'/usr/bin/su',
|
2022-09-24 15:12:23 +00:00
|
|
|
'/usr/bin/sudo',
|
|
|
|
'/usr/bin/top'
|
|
|
|
)
|
2022-10-13 18:59:32 +00:00
|
|
|
AND p.path NOT LIKE '/nix/store/%/bin/sudo'
|
|
|
|
AND p.path NOT LIKE '/nix/store/%/bin/dhcpcd'
|
2023-01-03 13:50:19 +00:00
|
|
|
AND p.path NOT LIKE '/snap/snapd/%/usr/lib/snapd/snap-confine'
|
2022-09-24 15:12:23 +00:00
|
|
|
AND NOT (
|
|
|
|
p.name = 'polkit-agent-he'
|
|
|
|
AND parent_path = '/usr/bin/gnome-shell'
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
p.name = 'fusermount3'
|
|
|
|
AND parent_path = '/usr/lib/xdg-document-portal'
|
|
|
|
)
|
2022-10-25 13:20:18 +00:00
|
|
|
AND NOT (
|
2022-10-25 15:39:51 +00:00
|
|
|
p.path = '/usr/bin/pkexec'
|
2022-10-25 13:20:18 +00:00
|
|
|
AND parent_path = '/usr/bin/update-notifier'
|
|
|
|
)
|
2022-10-25 15:39:51 +00:00
|
|
|
AND NOT (
|
|
|
|
p.path = '/usr/libexec/xdg-permission-store'
|
|
|
|
AND parent_path = '/usr/lib/systemd/systemd'
|
|
|
|
)
|