2022-10-14 18:19:13 +00:00
|
|
|
-- Applications setting environment variables to bypass security protections
|
|
|
|
--
|
2022-09-08 21:58:56 +00:00
|
|
|
-- Inpsired by BPFdoor and other intrusions
|
|
|
|
-- https://www.sandflysecurity.com/blog/compromised-linux-cheat-sheet/
|
2022-10-14 18:19:13 +00:00
|
|
|
--
|
2022-10-17 21:10:51 +00:00
|
|
|
-- WARNING: This query is known to require a higher than average wall time.
|
|
|
|
--
|
2023-02-01 21:17:36 +00:00
|
|
|
-- interval: 30
|
2022-10-20 18:56:16 +00:00
|
|
|
-- platform: darwin
|
2022-09-24 15:12:23 +00:00
|
|
|
SELECT
|
|
|
|
key,
|
|
|
|
value,
|
|
|
|
p.pid,
|
|
|
|
p.path,
|
2023-02-01 18:55:55 +00:00
|
|
|
p.cwd,
|
2022-09-24 15:12:23 +00:00
|
|
|
p.cmdline,
|
|
|
|
p.parent AS parent_pid,
|
2022-10-14 18:19:13 +00:00
|
|
|
pp.cmdline AS parent_cmd
|
2022-11-03 15:51:54 +00:00
|
|
|
-- Querying processes first and filtering by time gives a massive 20X speed improvement
|
|
|
|
-- over querying process_envs first and JOIN'ing against processes
|
|
|
|
FROM
|
|
|
|
processes p
|
2022-10-27 20:54:41 +00:00
|
|
|
LEFT JOIN process_envs pe ON p.pid = pe.pid
|
2022-09-24 15:12:23 +00:00
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
2022-10-27 20:54:41 +00:00
|
|
|
WHERE -- This time should match the interval
|
|
|
|
p.start_time > (strftime('%s', 'now') - 20)
|
|
|
|
AND (
|
2022-09-24 15:12:23 +00:00
|
|
|
key = 'HISTFILE'
|
|
|
|
AND NOT VALUE LIKE '/Users/%/.%_history'
|
|
|
|
)
|
|
|
|
OR (
|
|
|
|
key = 'LD_PRELOAD'
|
|
|
|
AND NOT p.path LIKE '%/firefox'
|
2022-10-13 18:59:32 +00:00
|
|
|
AND NOT pe.value = 'libfakeroot.so'
|
2022-09-24 15:12:23 +00:00
|
|
|
AND NOT pe.value LIKE 'libmozsandbox.so%'
|
2022-10-17 23:01:16 +00:00
|
|
|
AND NOT pe.value LIKE ':/snap/%' -- Yes, on macOS (emote)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
OR (
|
2022-10-05 20:15:40 +00:00
|
|
|
key = 'DYLD_INSERT_LIBRARIES' -- actively exploited on programs which disable library security
|
2023-02-15 01:16:02 +00:00
|
|
|
AND NOT pe.value = '/System/Library/PrivateFrameworks/PreviewsInjection.framework/PreviewsInjection'
|
2023-02-24 21:30:17 +00:00
|
|
|
AND NOT pe.value LIKE '/opt/homebrew/Cellar/r/4.%/lib/R/lib/libR.dylib'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
OR (
|
|
|
|
key = 'DYLD_FRAMEWORK_PATH' -- sort of obsolete, but may affect SIP abusers
|
|
|
|
)
|