2022-10-19 20:56:32 +00:00
|
|
|
-- Find processes that run with a lower effective UID than their parent (event-based)
|
2022-10-14 18:19:13 +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:
|
|
|
|
-- * unexpected-privilege-escalation.sql
|
|
|
|
--
|
|
|
|
-- tags: events process escalation
|
2022-11-08 01:36:37 +00:00
|
|
|
-- platform: linux
|
2022-10-14 18:19:13 +00:00
|
|
|
-- interval: 30
|
2022-10-07 20:19:18 +00:00
|
|
|
SELECT
|
|
|
|
p.pid AS child_pid,
|
|
|
|
p.path AS child_path,
|
2022-10-13 18:59:32 +00:00
|
|
|
REGEX_MATCH (RTRIM(file.path, '/'), '.*/(.*?)$', 1) AS child_name,
|
2022-10-07 20:19:18 +00:00
|
|
|
p.cmdline AS child_cmdline,
|
2022-11-08 01:36:37 +00:00
|
|
|
p.time,
|
2022-12-15 15:20:16 +00:00
|
|
|
pp.cgroup_path,
|
2022-11-08 01:36:37 +00:00
|
|
|
pp.start_time,
|
2022-10-07 20:19:18 +00:00
|
|
|
p.euid AS child_euid,
|
|
|
|
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-10-07 20:19:18 +00:00
|
|
|
FROM
|
|
|
|
process_events 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-10-07 20:19:18 +00:00
|
|
|
WHERE
|
|
|
|
p.time > (strftime('%s', 'now') -30)
|
|
|
|
AND p.euid < pp.euid
|
|
|
|
AND p.path NOT IN (
|
2022-12-15 14:20:41 +00:00
|
|
|
'/',
|
2022-10-27 14:23:15 +00:00
|
|
|
'/bin/ps',
|
|
|
|
'/usr/bin/doas',
|
2022-10-07 20:19:18 +00:00
|
|
|
'/usr/bin/fusermount',
|
|
|
|
'/usr/bin/fusermount3',
|
|
|
|
'/usr/bin/login',
|
|
|
|
'/usr/bin/sudo',
|
2022-11-08 17:59:11 +00:00
|
|
|
'/usr/bin/gpgsm',
|
|
|
|
'/usr/bin/gpgconf',
|
|
|
|
'/usr/bin/gpg',
|
2022-10-27 14:23:15 +00:00
|
|
|
'/usr/bin/top',
|
|
|
|
'/usr/lib/snapd/snap-confine',
|
2022-10-27 20:55:00 +00:00
|
|
|
'/usr/lib/snapd/snap-update-ns',
|
2022-11-03 15:51:54 +00:00
|
|
|
'/opt/1Password/1Password-KeyringHelper',
|
2022-10-27 20:55:00 +00:00
|
|
|
'/usr/lib/systemd/systemd',
|
2022-10-28 23:24:00 +00:00
|
|
|
'/usr/lib/Xorg.wrap',
|
|
|
|
'/usr/lib/xorg/Xorg.wrap'
|
2022-10-07 20:19:18 +00:00
|
|
|
)
|
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'
|
2022-10-27 14:23:15 +00:00
|
|
|
AND p.path NOT LIKE '/snap/snapd/%/usr/lib/snapd/snap-confine'
|
2022-12-15 21:51:58 +00:00
|
|
|
AND p.path NOT LIKE '/snap/snapd/%/usr/lib/snapd/snap-update-ns'
|
2022-11-08 17:59:11 +00:00
|
|
|
AND NOT pp.cmdline = '/usr/lib/systemd/systemd --user'
|
2022-12-15 14:20:41 +00:00
|
|
|
-- used by kind
|
|
|
|
AND NOT (
|
2022-12-15 15:20:16 +00:00
|
|
|
p.path = '/usr/bin/bash'
|
|
|
|
AND p.cmdline = '/bin/bash /usr/local/bin/mount-product-files'
|
2022-12-15 14:20:41 +00:00
|
|
|
)
|
2022-10-07 20:19:18 +00:00
|
|
|
AND NOT (
|
|
|
|
child_name = 'polkit-agent-helper-1'
|
|
|
|
AND parent_path = '/usr/bin/gnome-shell'
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
child_name = 'fusermount3'
|
|
|
|
AND parent_path = '/usr/lib/xdg-document-portal'
|
|
|
|
)
|
2022-10-27 14:23:15 +00:00
|
|
|
AND NOT (
|
|
|
|
child_name IN ('dash', 'pkexec')
|
|
|
|
AND parent_path = '/usr/bin/update-notifier'
|
|
|
|
)
|