osquery-defense-kit/detection/evasion/missing-from-disk-linux.sql

52 lines
1.4 KiB
MySQL
Raw Normal View History

2022-10-14 18:19:13 +00:00
-- Processes that do not exist on disk, running in osquery's namespace
--
2022-10-14 18:19:13 +00:00
-- false positives:
-- * none observed
--
2022-10-19 20:56:32 +00:00
-- references:
-- * https://attack.mitre.org/techniques/T1070/004/ (Indicator Removal on Host: File Deletion)
--
-- tags: persistent process state
2022-10-14 13:36:28 +00:00
-- platform: linux
2022-09-24 15:07:34 +00:00
SELECT
p.pid,
2022-10-14 13:36:28 +00:00
p.euid,
2022-09-24 15:07:34 +00:00
p.cmdline,
p.path,
p.cgroup_path,
2022-09-24 15:07:34 +00:00
mnt_namespace,
p.cwd,
p.on_disk,
p.state,
file.inode,
2022-09-24 15:07:34 +00:00
pp.on_disk AS parent_on_disk,
pp.path AS parent_path,
pp.cmdline AS parent_cmdline,
pp.cwd AS parent_cwd,
ph.sha256 AS parent_sha256
FROM
processes p
LEFT JOIN file ON p.path = file.path
2022-09-24 15:07:34 +00:00
LEFT JOIN process_namespaces ON p.pid = process_namespaces.pid
LEFT JOIN processes pp ON p.parent = pp.pid
LEFT JOIN hash ph ON pp.path = ph.path
WHERE
p.on_disk != 1
AND p.path != ''
2022-09-24 15:07:34 +00:00
-- use osquery as the reference mount namespace
AND mnt_namespace IN (
SELECT DISTINCT
(mnt_namespace)
FROM
process_namespaces
JOIN processes ON processes.pid = process_namespaces.pid
WHERE
processes.name IN ('osqueryi', 'osqueryd')
2022-09-24 15:07:34 +00:00
)
-- This is truly a missing program, not just one that has been updated with a new binary.
AND file.inode IS NULL
2023-04-17 20:20:35 +00:00
AND p.path != '/bpfilter_umh'
-- Snap packages?
AND p.path NOT LIKE '/tmp/.mount_%'
AND p.path NOT LIKE '/home/%/.cache/yay/1password-cli/pkg/1password-cli/usr/bin/op'
AND p.path NOT IN ('/usr/bin/python3.10')