osquery-defense-kit/detection/evasion/parent-missing-from-disk-li...

102 lines
2.8 KiB
MySQL
Raw Normal View History

2022-10-19 20:56:32 +00:00
-- A program where the parent PID is not on disk
--
2022-09-11 19:07:54 +00:00
-- Reveals boopkit if a child is spawned
2022-09-29 20:19:30 +00:00
-- TODO: Make mount namespace aware
2022-10-19 20:56:32 +00:00
--
-- false positives:
-- * none observed
--
-- references:
-- * https://attack.mitre.org/techniques/T1070/004/ (Indicator Removal on Host: File Deletion)
--
-- false positives:
-- * none observed
--
-- tags: persistent daemon
SELECT
-- Child
p0.pid AS p0_pid,
p0.path AS p0_path,
p0.name AS p0_name,
p0.cmdline AS p0_cmd,
p0.cwd AS p0_cwd,
p0.cgroup_path AS p0_cgroup,
p0.euid AS p0_euid,
p0_hash.sha256 AS p0_sha256,
-- Parent
p0.parent AS p1_pid,
p1.cgroup_path AS p1_cgroup,
p1.path AS p1_path,
p1.name AS p1_name,
p1.cmdline AS p1_cmd,
p1_hash.sha256 AS p1_sha256,
-- Grandparent
p1.parent AS p2_pid,
p2.name AS p2_name,
p2.path AS p2_path,
p2.cmdline AS p2_cmd,
p2_hash.sha256 AS p2_sha256
FROM
processes p0
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
LEFT JOIN processes p1 ON p0.parent = p1.pid
LEFT JOIN hash p1_hash ON p1.path = p1_hash.path
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p1.on_disk != 1
AND p0.on_disk = 1
AND NOT p0.pid IN (1, 2)
AND NOT p1.pid IN (1, 2) -- launchd, kthreadd
AND NOT p1.path IN (
'/opt/brave.com/brave/brave',
'/opt/google/chrome/chrome',
'/usr/bin/alacritty',
'/usr/bin/doas',
'/usr/bin/dockerd',
'/usr/bin/fusermount3',
'/usr/bin/gnome-shell',
'/usr/bin/ibus-daemon',
2023-04-17 20:20:35 +00:00
'/usr/bin/kitty',
'/usr/bin/osqueryd',
'/usr/bin/sudo',
'/usr/bin/tmux',
'/usr/bin/yay',
'/usr/libexec/gdm-wayland-session',
'/usr/libexec/gdm-x-session',
'/usr/libexec/gnome-terminal-server',
2023-05-08 17:11:24 +00:00
'/usr/lib/gnome-session-binary',
2023-05-03 20:30:03 +00:00
'/usr/lib/systemd/systemd',
2023-05-08 17:11:24 +00:00
'/usr/lib/xdg-document-portal',
'/usr/sbin/auditd',
'/usr/sbin/gdm3',
'/usr/sbin/sshd',
2023-05-03 20:30:03 +00:00
'/usr/share/code/code'
2022-09-29 20:19:30 +00:00
) -- long-running launchers
AND NOT p1.name IN (
'lightdm',
'nvim',
'gnome-shell',
'fish',
'bash',
'slack',
'kube-proxy',
'kubelet'
2022-09-29 20:19:30 +00:00
) -- These alerts were unfortunately useless - lots of spam on macOS
AND NOT (
p1.path LIKE '/app/%'
AND p1.cgroup_path LIKE '/user.slice/user-1000.slice/user@1000.service/app.slice/%'
)
2023-03-20 21:05:02 +00:00
AND NOT p2.name = 'bwrap'
AND p1.cgroup_path NOT LIKE '/system.slice/docker-%'
2023-03-20 21:05:02 +00:00
AND p1.cgroup_path != '/system.slice/docker.service'
AND p1.cgroup_path NOT LIKE '/user.slice/user-1000.slice/user@1000.service/user.slice/nerdctl-%'
AND p1.cgroup_path NOT LIKE '/user.slice/user-1000.slice/user@1000.service/user.slice/libpod-%'
AND p1.path NOT LIKE '/opt/homebrew/Cellar/%'
AND p1.path NOT LIKE '/tmp/.mount_%/%'
AND p1.path NOT LIKE '%google-cloud-sdk/.install/.backup%'
2022-09-30 15:14:20 +00:00
AND NOT (
p1.name LIKE 'kworker/%+events_unbound'
AND p0.name IN ('modprobe')
)