2023-05-16 20:31:31 +00:00
|
|
|
-- Find unexpected programs with open lock files
|
|
|
|
--
|
|
|
|
-- false positives:
|
|
|
|
-- * many possible
|
|
|
|
--
|
|
|
|
-- references:
|
|
|
|
-- * https://www.deepinstinct.com/blog/bpfdoor-malware-evolves-stealthy-sniffing-backdoor-ups-its-game
|
|
|
|
--
|
|
|
|
-- tags: persistent filesystem state
|
|
|
|
-- platform: posix
|
2023-06-01 15:52:20 +00:00
|
|
|
SELECT
|
|
|
|
CONCAT (
|
|
|
|
MIN(p0.euid, 500),
|
|
|
|
',',
|
|
|
|
COALESCE(REGEX_MATCH (p0.path, '.*/(.*)', 1), p0.path),
|
|
|
|
',',
|
|
|
|
COALESCE(
|
|
|
|
REGEX_MATCH (REPLACE(pof.path, u.directory, '~'), '(.*)/.*', 1),
|
|
|
|
REPLACE(pof.path, u.directory, '~')
|
|
|
|
)
|
|
|
|
) AS exception_key,
|
|
|
|
pof.path AS lock,
|
2023-05-23 15:31:37 +00:00
|
|
|
-- Child
|
|
|
|
p0.pid AS p0_pid,
|
|
|
|
p0.path AS p0_path,
|
|
|
|
p0.name AS p0_name,
|
|
|
|
p0.start_time AS p0_start,
|
|
|
|
p0.cmdline AS p0_cmd,
|
|
|
|
p0.cwd AS p0_cwd,
|
|
|
|
p0.cgroup_path AS p0_cgroup,
|
|
|
|
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.start_time AS p1_start,
|
|
|
|
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.start_time AS p2_start,
|
|
|
|
p2.path AS p2_path,
|
|
|
|
p2.cmdline AS p2_cmd,
|
|
|
|
p2_hash.sha256 AS p2_sha256
|
2023-06-01 15:52:20 +00:00
|
|
|
FROM
|
|
|
|
processes p0
|
|
|
|
JOIN users u ON p0.euid = u.uid
|
|
|
|
LEFT JOIN process_open_files pof ON p0.pid = pof.pid
|
|
|
|
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
|
|
|
|
LEFT JOIN processes p1 ON p0.parent = p1.pid
|
|
|
|
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
|
|
|
|
WHERE
|
|
|
|
pof.path LIKE "%.lock"
|
2023-06-02 23:08:08 +00:00
|
|
|
AND NOT pof.path NOT LIKE "/run/user/%/%.lock"
|
2023-06-01 15:52:20 +00:00
|
|
|
AND NOT p0.path LIKE '/System/%'
|
|
|
|
AND NOT exception_key IN (
|
|
|
|
'0,com.apple.MobileSoftwareUpdate.CryptegraftService,/private/var/db/softwareupdate/SplunkHistory',
|
|
|
|
'0,snapd,/var/lib/snapd',
|
2023-06-12 14:10:57 +00:00
|
|
|
'120,gnome-shell,/run/user/120',
|
2024-07-02 01:56:28 +00:00
|
|
|
'500,kwin_wayland_wrapper,/run/user/1000',
|
2023-06-07 13:55:17 +00:00
|
|
|
'200,NRDUpdated,/private~/SplunkHistory',
|
2023-06-01 15:52:20 +00:00
|
|
|
'200,softwareupdated,/private~/SplunkHistory',
|
2023-06-07 13:55:17 +00:00
|
|
|
'500,Adobe Premiere Pro 2023,~/Library/Caches/Adobe/Premiere Pro/23.0/SentryIO-db',
|
2023-06-01 15:52:20 +00:00
|
|
|
'500,Beeper,~/Library/Application Support/Beeper/EventStore',
|
|
|
|
'500,bridge-gui,~/Library/Application Support/protonmail/bridge-v3/sentry_cache',
|
|
|
|
'500,bridge-gui,~/Library/Caches/protonmail/bridge-v3',
|
|
|
|
'500,bridge,~/Library/Application Support/protonmail/bridge-v3/sentry_cache',
|
|
|
|
'500,bridge,~/Library/Caches/protonmail/bridge-v3',
|
|
|
|
'500,buildkitd,~/.local/share/buildkit',
|
2023-06-07 13:55:17 +00:00
|
|
|
'500,Clipy,~/Library/Application Support/com.clipy-app.Clipy',
|
2023-06-01 15:52:20 +00:00
|
|
|
'500,com.docker.backend,~/Library/Containers/com.docker.docker',
|
2023-06-07 13:55:17 +00:00
|
|
|
'500,com.docker.build,~/.docker/desktop-build',
|
|
|
|
'500,Craft,~/Library/Containers/com.lukilabs.lukiapp/Data/Library/Application Support/com.lukilabs.lukiapp',
|
|
|
|
'500,Ecamm Live Stream Deck Plugin,~/Library/Application Support/com.elgato.StreamDeck/Sentry',
|
|
|
|
'500,flyctl,~/.fly',
|
2023-07-12 19:00:36 +00:00
|
|
|
'500,Hyprland,/run/user/1000',
|
2023-06-07 13:55:17 +00:00
|
|
|
'127,pipewire,/run/user/127',
|
|
|
|
'500,gnome-shell,/run/user/1000',
|
|
|
|
'120,pipewire,/run/user/120',
|
|
|
|
'500,iMovie,~/Movies/iMovie Library.imovielibrary',
|
|
|
|
'500,Opera,~/Library/Application Support/com.operasoftware.Opera',
|
2023-06-01 15:52:20 +00:00
|
|
|
'500,photolibraryd,~/Library/Photos/Libraries/Syndication.photoslibrary/database',
|
|
|
|
'500,photolibraryd,~/Pictures/Photos Library.photoslibrary/database',
|
2023-06-07 13:55:17 +00:00
|
|
|
'500,pipewire,/run/user/1000',
|
|
|
|
'500,reMarkable,~/Library/Application Support/remarkable/desktop',
|
|
|
|
'500,Stream Deck,~/Library/Application Support/com.elgato.StreamDeck/Sentry',
|
|
|
|
'500,TwitchStudioStreamDeck,~/Library/Application Support/com.elgato.StreamDeck/Sentry'
|
2023-06-01 15:52:20 +00:00
|
|
|
)
|
|
|
|
AND NOT exception_key LIKE '500,com.apple.Virtualization.VirtualMachine,~/%'
|
|
|
|
AND NOT exception_key LIKE '500,iMovie,%.imovielibrary'
|
2023-06-02 23:08:08 +00:00
|
|
|
AND NOT exception_key LIKE '500,go,~/go/pkg/mod/cache/download/%'
|
|
|
|
AND NOT exception_key LIKE '500,remindd,/private/var/folders/%/T/.AddressBookLocks'
|
2023-06-01 15:52:20 +00:00
|
|
|
AND NOT exception_key LIKE '500,com.apple.Virtualization.VirtualMachine,/private/var/folders/%'
|
|
|
|
AND NOT exception_key LIKE '500,lua-language-server,~/%'
|
|
|
|
AND NOT exception_key LIKE '500,ykman-gui,/private/var/folders/%/T'
|
|
|
|
AND NOT exception_key LIKE '500,golangci-lint,/private/var/folders/%/T'
|
|
|
|
AND NOT exception_key LIKE '0,prl_disp_service,/Users/%/Parallels/%.pvm'
|
|
|
|
AND NOT exception_key LIKE '500,iTermServer-%,~/Library/Application Support/iTerm2'
|
|
|
|
AND NOT exception_key LIKE '500,%,/private/var/folders/%/T/Sentry_StreamDeck'
|
|
|
|
AND NOT exception_key LIKE '500,gnome-software,/var/tmp/flatpak-cache-%'
|
2024-04-26 20:14:02 +00:00
|
|
|
AND NOT exception_key LIKE '%,gnome-shell,/run/user/%'
|
|
|
|
AND NOT exception_key LIKE '%,pipewire%,/run/user/%'
|
2023-06-01 15:52:20 +00:00
|
|
|
AND NOT exception_key LIKE '500,com.docker.backend,/private/var/folders/%/go/pkg/mod/cache/%'
|
|
|
|
GROUP BY
|
|
|
|
p0.path,
|
|
|
|
pof.path
|