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
|
|
|
|
--
|
2022-10-14 18:26:49 +00:00
|
|
|
-- tags: persistent daemon
|
2023-02-02 22:58:19 +00:00
|
|
|
SELECT
|
|
|
|
s.authority AS p0_auth,
|
2023-02-01 18:55:55 +00:00
|
|
|
s.identifier AS p0_id,
|
|
|
|
DATETIME(f.ctime, 'unixepoch') AS p0_changed,
|
|
|
|
DATETIME(f.mtime, 'unixepoch') AS p0_modified,
|
|
|
|
-- Child
|
2023-02-09 22:01:29 +00:00
|
|
|
p0.pid AS p0_pid,
|
2023-02-01 18:55:55 +00:00
|
|
|
p0.path AS p0_path,
|
|
|
|
p0.name AS p0_name,
|
|
|
|
p0.cmdline AS p0_cmd,
|
|
|
|
p0.cwd AS p0_cwd,
|
|
|
|
p0.euid AS p0_euid,
|
|
|
|
p0_hash.sha256 AS p0_sha256,
|
|
|
|
-- Parent
|
|
|
|
p0.parent AS p1_pid,
|
|
|
|
p1.path AS p1_path,
|
|
|
|
p1.name AS p1_name,
|
|
|
|
p1_f.mode AS p1_mode,
|
|
|
|
p1.euid AS p1_euid,
|
|
|
|
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
|
2023-02-02 22:58:19 +00:00
|
|
|
FROM
|
|
|
|
processes p0
|
2023-02-01 18:55:55 +00:00
|
|
|
LEFT JOIN file f ON p0.path = f.path
|
|
|
|
LEFT JOIN signature s ON p0.path = s.path
|
|
|
|
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
|
|
|
|
LEFT JOIN processes p1 ON p0.parent = p1.pid
|
|
|
|
LEFT JOIN file p1_f ON p1.path = p1_f.path
|
|
|
|
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
|
2023-02-02 22:58:19 +00:00
|
|
|
WHERE
|
|
|
|
p0.pid IN (
|
|
|
|
SELECT
|
|
|
|
p.pid
|
|
|
|
FROM
|
|
|
|
processes p
|
2023-02-02 21:59:12 +00:00
|
|
|
-- NOTE: This is an expensive join on macOS
|
2023-03-30 22:44:01 +00:00
|
|
|
JOIN processes pp ON p.parent = pp.pid
|
2023-02-02 22:58:19 +00:00
|
|
|
WHERE
|
2023-02-08 19:37:09 +00:00
|
|
|
p.parent NOT IN (0, 1, 2)
|
2023-02-02 21:59:12 +00:00
|
|
|
AND p.path != ""
|
|
|
|
-- macOS Optimization
|
|
|
|
AND p.path NOT LIKE '/System/%'
|
|
|
|
AND p.path NOT LIKE '/usr/libexec/%'
|
|
|
|
AND p.path NOT LIKE '/usr/bin/%'
|
|
|
|
AND p.path NOT LIKE '/sbin/%'
|
|
|
|
-- Exceptions
|
|
|
|
AND pp.path NOT LIKE '/opt/homebrew/Cellar/%'
|
|
|
|
AND pp.path NOT LIKE '%google-cloud-sdk/.install/.backup%'
|
|
|
|
AND pp.path NOT LIKE '/private/var/folders/%/T/PKInstallSandboxTrash/%.sandboxTrash/%'
|
2023-03-03 12:24:42 +00:00
|
|
|
AND pp.path NOT IN (
|
|
|
|
"",
|
|
|
|
"/sbin/launchd",
|
2023-09-14 21:13:12 +00:00
|
|
|
"/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin)",
|
|
|
|
"/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper"
|
2023-03-03 12:24:42 +00:00
|
|
|
)
|
2023-02-02 21:59:12 +00:00
|
|
|
AND pp.on_disk != 1
|
2023-02-02 22:58:19 +00:00
|
|
|
);
|