2023-05-16 20:31:31 +00:00
|
|
|
-- Slow query to find root programs with an open socket and few shared libraries
|
|
|
|
--
|
|
|
|
-- false positives:
|
|
|
|
-- * some minimalist daemons
|
|
|
|
--
|
|
|
|
-- references:
|
|
|
|
-- * https://www.deepinstinct.com/blog/bpfdoor-malware-evolves-stealthy-sniffing-backdoor-ups-its-game
|
|
|
|
--
|
|
|
|
-- tags: persistent process state seldom
|
|
|
|
-- platform: macos
|
2023-05-17 14:54:16 +00:00
|
|
|
SELECT
|
2023-06-01 15:52:20 +00:00
|
|
|
p.uid,
|
|
|
|
p.euid,
|
|
|
|
pos.protocol,
|
|
|
|
pos.pid,
|
|
|
|
pos.remote_address,
|
|
|
|
pos.local_address,
|
|
|
|
pos.local_port,
|
|
|
|
pos.remote_port,
|
|
|
|
p.name,
|
|
|
|
p.start_time,
|
|
|
|
p.parent,
|
|
|
|
p.cgroup_path,
|
|
|
|
p.path,
|
|
|
|
pos.state,
|
|
|
|
GROUP_CONCAT(DISTINCT pmm.path) AS libs,
|
|
|
|
COUNT(DISTINCT pmm.path) AS lib_count,
|
|
|
|
-- Normally we would use signatures for exceptions, but it was triggering
|
|
|
|
-- an unusual performance issue in osquery.
|
|
|
|
CONCAT (MIN(p.euid, 500), ',', p.name, ',', p.path) AS exception_key
|
2023-05-17 14:54:16 +00:00
|
|
|
FROM
|
2023-06-01 15:52:20 +00:00
|
|
|
processes p
|
|
|
|
-- For some reason, joining this table increases the runtime by 30X
|
|
|
|
-- LEFT JOIN signature s ON p.path = s.path
|
|
|
|
JOIN process_memory_map pmm ON p.pid = pmm.pid
|
|
|
|
JOIN process_open_sockets pos ON p.pid = pos.pid
|
2023-05-17 14:54:16 +00:00
|
|
|
WHERE
|
2023-06-01 15:52:20 +00:00
|
|
|
p.pid IN (
|
|
|
|
SELECT
|
|
|
|
processes.pid
|
|
|
|
FROM
|
|
|
|
processes
|
|
|
|
JOIN process_open_sockets ON processes.pid = process_open_sockets.pid
|
|
|
|
AND family != 1
|
|
|
|
WHERE
|
|
|
|
processes.path NOT LIKE '/System/%'
|
|
|
|
AND processes.path NOT LIKE '/Library/Apple/%'
|
|
|
|
AND processes.path NOT LIKE '/usr/libexec/%'
|
|
|
|
AND processes.path NOT LIKE '/usr/sbin/%'
|
|
|
|
AND processes.path NOT LIKE '/sbin/%'
|
|
|
|
AND processes.path NOT LIKE '/private/var/db/com.apple.xpc.roleaccountd.staging/%'
|
|
|
|
AND processes.path NOT LIKE '/usr/bin/%'
|
|
|
|
AND processes.path NOT LIKE '/nix/store/%/bin/nix'
|
|
|
|
AND processes.path NOT LIKE '/usr/local/kolide-k2/bin/osqueryd-updates/%/osqueryd'
|
|
|
|
AND processes.path NOT LIKE '/usr/local/kolide-k2/bin/launcher-updates/%/Kolide.app/Contents/MacOS/launcher'
|
2023-06-08 22:26:57 +00:00
|
|
|
AND processes.start_time < (strftime('%s', 'now') -600)
|
2023-06-01 15:52:20 +00:00
|
|
|
GROUP BY
|
|
|
|
processes.path
|
|
|
|
)
|
|
|
|
AND pmm.path LIKE "%.dylib"
|
|
|
|
AND exception_key NOT IN (
|
|
|
|
'500,Slack,/Applications/Slack.app/Contents/MacOS/Slack',
|
2023-06-07 13:55:17 +00:00
|
|
|
'500,J8RPQ294UB.com.skitch.SkitchHelper,/Applications/Skitch.app/Contents/Library/LoginItems/J8RPQ294UB.com.skitch.SkitchHelper.app/Contents/MacOS/J8RPQ294UB.com.skitch.SkitchHelper',
|
2023-06-01 15:52:20 +00:00
|
|
|
'500,Slack Helper (GPU),/Applications/Slack.app/Contents/Frameworks/Slack Helper (GPU).app/Contents/MacOS/Slack Helper (GPU)',
|
|
|
|
'500,Slack Helper (Renderer),/Applications/Slack.app/Contents/Frameworks/Slack Helper (Renderer).app/Contents/MacOS/Slack Helper (Renderer)',
|
|
|
|
'500,Snagit 2020,/Applications/Snagit 2020.app/Contents/MacOS/Snagit 2020',
|
2023-06-30 20:38:31 +00:00
|
|
|
'500,Bitwarden,/Applications/Bitwarden.app/Contents/MacOS/Bitwarden',
|
2023-06-07 13:55:17 +00:00
|
|
|
'500,Revolt Helper (GPU),/Applications/Revolt.app/Contents/Frameworks/Revolt Helper (GPU).app/Contents/MacOS/Revolt Helper (GPU)',
|
|
|
|
'500,Revolt,/Applications/Revolt.app/Contents/MacOS/Revolt',
|
|
|
|
'500,Steam Helper,/Users/kaniini/Library/Application Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/Frameworks/Steam Helper.app/Contents/MacOS/Steam Helper',
|
2023-06-01 15:52:20 +00:00
|
|
|
'500,SnagitHelper2020,/Applications/Snagit 2020.app/Contents/Library/LoginItems/SnagitHelper2020.app/Contents/MacOS/SnagitHelper2020',
|
|
|
|
'500,Todoist,/Applications/Todoist.app/Contents/MacOS/Todoist',
|
|
|
|
'500,WhatsApp Helper (GPU),/Applications/WhatsApp.app/Contents/Frameworks/WhatsApp Helper (GPU).app/Contents/MacOS/WhatsApp Helper (GPU)'
|
|
|
|
)
|
2023-06-07 13:55:17 +00:00
|
|
|
AND exception_key NOT LIKE '500,MacVim,/%/MacVim.app/Contents/MacOS/MacVim'
|
2023-05-17 14:54:16 +00:00
|
|
|
GROUP BY
|
2023-06-01 15:52:20 +00:00
|
|
|
pos.pid
|
2023-05-17 14:54:16 +00:00
|
|
|
HAVING
|
2023-06-01 15:52:20 +00:00
|
|
|
lib_count IN (1, 2)
|
2023-06-30 20:38:31 +00:00
|
|
|
AND libs NOT LIKE '/Applications/%/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libffmpeg.dylib,/usr/lib/libobjc-trampolines.dylib'
|
|
|
|
|