osquery-defense-kit/detection/evasion/parent-pid-missing-from-procfs.sql

33 lines
832 B
MySQL
Raw Permalink Normal View History

2023-05-23 15:31:58 +00:00
-- Find a process which has a parent that is not listed in the process table
--
-- Works well for revealing boopkit, so long as boopkit has a child process.
--
-- references:
-- * https://github.com/krisnova/boopkit
-- * https://attack.mitre.org/techniques/T1014/ (Rootkit)
--
-- false positives:
-- * Can by racy if child and parent exit at the right time
--
-- tags: persistent daemon
2024-02-16 22:21:00 +00:00
SELECT
p.*,
2023-05-23 15:31:58 +00:00
hash.sha256,
GROUP_CONCAT(DISTINCT pof.path) AS open_files
2024-02-16 22:21:00 +00:00
FROM
processes p
2023-05-23 15:31:58 +00:00
LEFT JOIN hash ON p.path = hash.path
LEFT JOIN process_open_files pof ON p.pid = pof.pid
WHERE -- Prevent false positives by avoiding short-lived commands
p.start_time < (strftime('%s', 'now') -300)
2023-05-23 15:31:58 +00:00
AND p.parent NOT IN (
2024-02-16 22:21:00 +00:00
SELECT
pid
FROM
processes
2023-05-23 15:31:58 +00:00
)
AND p.parent != 0
AND p.parent IS NOT NULL
2024-02-16 22:21:00 +00:00
GROUP BY
p.pid