2022-10-20 11:04:18 +00:00
|
|
|
-- Unexpected programs communicating over non-HTTPS protocols (state-based)
|
|
|
|
--
|
|
|
|
-- This query is a bit awkward and hobbled due to the lack of osquery support
|
|
|
|
-- for looking up binary signatures in Linux.
|
2022-10-13 18:59:32 +00:00
|
|
|
--
|
|
|
|
-- references:
|
2022-10-19 20:56:32 +00:00
|
|
|
-- * https://attack.mitre.org/techniques/T1071/ (C&C, Application Layer Protocol)
|
2022-10-13 18:59:32 +00:00
|
|
|
--
|
2022-10-17 12:43:29 +00:00
|
|
|
-- tags: transient state net rapid
|
2022-10-13 18:59:32 +00:00
|
|
|
-- platform: linux
|
2022-10-20 18:01:34 +00:00
|
|
|
SELECT
|
|
|
|
s.remote_address,
|
2022-11-08 17:59:11 +00:00
|
|
|
s.remote_port,
|
2022-09-22 09:18:03 +00:00
|
|
|
p.name,
|
|
|
|
p.path,
|
|
|
|
p.cmdline AS child_cmd,
|
|
|
|
p.cwd,
|
2022-09-22 17:18:16 +00:00
|
|
|
pp.path AS parent_path,
|
2022-09-22 09:18:03 +00:00
|
|
|
p.parent AS parent_pid,
|
|
|
|
pp.cmdline AS parent_cmd,
|
2022-10-20 11:04:18 +00:00
|
|
|
s.state,
|
2022-09-22 09:18:03 +00:00
|
|
|
hash.sha256,
|
2022-10-20 11:04:18 +00:00
|
|
|
-- This intentionally avoids file.path, as it won't join across mount namespaces
|
2022-09-24 15:12:23 +00:00
|
|
|
CONCAT (
|
2022-09-22 09:18:03 +00:00
|
|
|
MIN(s.remote_port, 32768),
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-10-20 11:04:18 +00:00
|
|
|
s.protocol,
|
|
|
|
',',
|
|
|
|
MIN(p.euid, 500),
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-10-20 11:04:18 +00:00
|
|
|
REPLACE(
|
2022-10-20 17:50:14 +00:00
|
|
|
REPLACE(
|
|
|
|
REGEX_MATCH (p.path, '(/.*?)/', 1),
|
|
|
|
'/nix',
|
|
|
|
'/usr'
|
|
|
|
),
|
|
|
|
'/snap',
|
|
|
|
'/opt'
|
2022-10-20 18:01:34 +00:00
|
|
|
),
|
|
|
|
'/',
|
2022-10-20 13:11:29 +00:00
|
|
|
REGEX_MATCH (p.path, '.*/(.*?)$', 1),
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-10-20 11:04:18 +00:00
|
|
|
MIN(f.uid, 500),
|
|
|
|
'u,',
|
|
|
|
MIN(f.gid, 500),
|
|
|
|
'g,',
|
2022-09-22 09:18:03 +00:00
|
|
|
p.name
|
|
|
|
) AS exception_key
|
2022-10-20 18:01:34 +00:00
|
|
|
FROM
|
|
|
|
process_open_sockets s
|
2022-09-22 09:18:03 +00:00
|
|
|
LEFT JOIN processes p ON s.pid = p.pid
|
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
2022-10-20 11:04:18 +00:00
|
|
|
LEFT JOIN file f ON p.path = f.path
|
2022-09-22 09:18:03 +00:00
|
|
|
LEFT JOIN hash ON p.path = hash.path
|
2022-10-20 18:01:34 +00:00
|
|
|
WHERE
|
|
|
|
protocol > 0
|
2022-10-20 17:50:14 +00:00
|
|
|
AND s.remote_port > 0 -- See unexpected-https-client
|
2022-10-20 11:04:18 +00:00
|
|
|
AND NOT (
|
|
|
|
s.remote_port = 443
|
|
|
|
AND protocol IN (6, 17)
|
2022-10-20 17:50:14 +00:00
|
|
|
) -- See unexpected-dns-traffic
|
2022-10-20 11:04:18 +00:00
|
|
|
AND NOT (
|
|
|
|
s.remote_port = 53
|
|
|
|
AND protocol IN (6, 17)
|
|
|
|
)
|
|
|
|
AND s.remote_address NOT IN (
|
|
|
|
'127.0.0.1',
|
|
|
|
'::ffff:127.0.0.1',
|
|
|
|
'::1',
|
|
|
|
'::',
|
|
|
|
'0.0.0.0'
|
|
|
|
)
|
2022-10-13 18:59:32 +00:00
|
|
|
AND s.remote_address NOT LIKE 'fe80:%'
|
|
|
|
AND s.remote_address NOT LIKE '127.%'
|
|
|
|
AND s.remote_address NOT LIKE '192.168.%'
|
|
|
|
AND s.remote_address NOT LIKE '172.1%'
|
|
|
|
AND s.remote_address NOT LIKE '172.2%'
|
|
|
|
AND s.remote_address NOT LIKE '172.30.%'
|
|
|
|
AND s.remote_address NOT LIKE '172.31.%'
|
|
|
|
AND s.remote_address NOT LIKE '::ffff:172.%'
|
|
|
|
AND s.remote_address NOT LIKE '10.%'
|
|
|
|
AND s.remote_address NOT LIKE '::ffff:10.%'
|
|
|
|
AND s.remote_address NOT LIKE 'fc00:%'
|
2022-10-20 11:04:18 +00:00
|
|
|
AND p.path != ''
|
|
|
|
AND NOT exception_key IN (
|
2022-11-22 14:21:03 +00:00
|
|
|
'123,17,114,/usr/chronyd,0u,0g,chronyd',
|
2022-10-20 11:59:17 +00:00
|
|
|
'123,17,500,/usr/chronyd,0u,0g,chronyd',
|
2022-10-21 15:22:24 +00:00
|
|
|
'143,6,500,/app/thunderbird,u,g,thunderbird',
|
2022-11-23 12:10:03 +00:00
|
|
|
'143,6,500,/usr/thunderbird,0u,0g,thunderbird',
|
2022-10-20 12:04:24 +00:00
|
|
|
'22000,6,500,/usr/syncthing,0u,0g,syncthing',
|
2022-12-16 22:37:32 +00:00
|
|
|
'22,6,0,/usr/ssh,0u,0g,ssh',
|
|
|
|
'22,6,0,/usr/tailscaled,0u,0g,tailscaled',
|
2022-11-22 14:21:03 +00:00
|
|
|
'22,6,500,/home/cargo,500u,500g,cargo',
|
2022-11-03 15:51:54 +00:00
|
|
|
'22,6,500,/usr/cargo,0u,0g,cargo',
|
2022-10-20 17:46:55 +00:00
|
|
|
'22,6,500,/usr/ssh,0u,0g,ssh',
|
2022-11-03 15:51:54 +00:00
|
|
|
'27034,6,500,/home/steam,500u,100g,steam',
|
2022-10-31 21:40:37 +00:00
|
|
|
'27035,6,500,/home/steam,500u,100g,steam',
|
2022-11-03 15:51:54 +00:00
|
|
|
'32768,6,0,/usr/tailscaled,0u,0g,tailscaled',
|
2022-11-08 17:59:11 +00:00
|
|
|
'32768,6,500,/usr/ssh,0u,0g,ssh',
|
2022-11-04 12:07:14 +00:00
|
|
|
'3443,6,500,/opt/chrome,0u,0g,chrome',
|
2022-10-27 14:23:15 +00:00
|
|
|
'3478,6,500,/opt/chrome,0u,0g,chrome',
|
2022-11-22 14:21:03 +00:00
|
|
|
'3478,6,500,/usr/chrome,0u,0g,chrome',
|
2022-11-07 15:03:43 +00:00
|
|
|
'3478,6,500,/usr/firefox,0u,0g,firefox',
|
2022-11-22 14:21:03 +00:00
|
|
|
'4070,6,500,/app/spotify,u,g,spotify',
|
2022-11-08 01:36:37 +00:00
|
|
|
'4070,6,500,/opt/spotify,0u,0g,spotify',
|
2023-01-06 15:18:19 +00:00
|
|
|
'4070,6,500,/opt/spotify,500u,500g,spotify',
|
2022-11-08 17:59:11 +00:00
|
|
|
'4070,6,500,/usr/spotify,0u,0g,spotify',
|
2022-10-30 13:39:10 +00:00
|
|
|
'43,6,500,/usr/whois,0u,0g,whois',
|
2022-12-16 22:37:32 +00:00
|
|
|
'4460,6,114,/usr/chronyd,0u,0g,chronyd',
|
|
|
|
'500,/usr/htop,0u,0g,htop',
|
2022-10-20 12:04:24 +00:00
|
|
|
'5228,6,500,/opt/chrome,0u,0g,chrome',
|
2022-10-20 17:50:14 +00:00
|
|
|
'5228,6,500,/usr/chrome,0u,0g,chrome',
|
2022-11-08 17:59:11 +00:00
|
|
|
'6443,6,500,/usr/kubectl,0u,0g,kubectl',
|
2022-11-08 01:36:37 +00:00
|
|
|
'67,17,0,/usr/NetworkManager,0u,0g,NetworkManager',
|
2022-10-20 12:20:06 +00:00
|
|
|
'8000,6,500,/opt/chrome,0u,0g,chrome',
|
|
|
|
'8000,6,500,/usr/firefox,0u,0g,firefox',
|
2022-10-25 15:39:51 +00:00
|
|
|
'80,6,0,/usr/applydeltarpm,0u,0g,applydeltarpm',
|
2022-12-16 22:37:32 +00:00
|
|
|
'80,6,0,/usr/bash,0u,0g,mkinitcpio',
|
2022-11-28 21:06:07 +00:00
|
|
|
'80,6,0,/usr/bash,0u,0g,sh',
|
2022-12-19 23:06:06 +00:00
|
|
|
'80,6,0,/usr/bash,0u,0g,update-ca-trust',
|
2022-11-28 21:06:07 +00:00
|
|
|
'80,6,0,/usr/gpg,0u,0g,gpg',
|
2022-10-20 17:50:14 +00:00
|
|
|
'80,6,0,/usr/NetworkManager,0u,0g,NetworkManager',
|
2022-10-25 15:39:51 +00:00
|
|
|
'80,6,0,/usr/packagekitd,0u,0g,packagekitd',
|
|
|
|
'80,6,0,/usr/pacman,0u,0g,pacman',
|
2022-10-27 14:38:26 +00:00
|
|
|
'80,6,0,/usr/python3.10,0u,0g,dnf',
|
2022-10-25 15:39:51 +00:00
|
|
|
'80,6,0,/usr/python3.10,0u,0g,yum',
|
2022-12-16 22:37:32 +00:00
|
|
|
'80,6,0,/usr/python3.11,0u,0g,dnf',
|
|
|
|
'80,6,0,/usr/python3.11,0u,0g,yum',
|
2022-10-20 12:04:24 +00:00
|
|
|
'80,6,0,/usr/tailscaled,0u,0g,tailscaled',
|
2022-10-20 12:20:06 +00:00
|
|
|
'80,6,0,/usr/.tailscaled-wrapped,0u,0g,.tailscaled-wra',
|
2022-10-27 14:23:15 +00:00
|
|
|
'80,6,105,/usr/http,0u,0g,http',
|
2022-11-22 14:21:03 +00:00
|
|
|
'80,6,500,/app/spotify,u,g,spotify',
|
2022-10-21 15:22:24 +00:00
|
|
|
'80,6,500,/app/thunderbird,u,g,thunderbird',
|
2022-10-30 14:05:40 +00:00
|
|
|
'80,6,500,/home/steam,500u,100g,steam',
|
2022-11-22 14:21:03 +00:00
|
|
|
'80,6,500,/home/terraform,500u,500g,terraform',
|
2022-12-16 22:37:32 +00:00
|
|
|
'80,6,500,/opt/brave,0u,0g,brave',
|
2022-10-20 12:04:24 +00:00
|
|
|
'80,6,500,/opt/chrome,0u,0g,chrome',
|
2022-10-20 17:50:14 +00:00
|
|
|
'80,6,500,/opt/firefox,0u,0g,firefox',
|
2022-11-22 14:21:03 +00:00
|
|
|
'80,6,500,/opt/spotify,0u,0g,spotify',
|
2022-10-21 15:22:24 +00:00
|
|
|
'80,6,500,/usr/chrome,0u,0g,chrome',
|
2022-10-20 17:12:46 +00:00
|
|
|
'80,6,500,/usr/curl,0u,0g,curl',
|
2022-10-20 12:04:24 +00:00
|
|
|
'80,6,500,/usr/firefox,0u,0g,firefox',
|
2022-10-21 21:44:53 +00:00
|
|
|
'80,6,500,/usr/firefox,0u,0g,.firefox-wrappe',
|
2022-11-03 15:51:54 +00:00
|
|
|
'80,6,500,/usr/gnome-software,0u,0g,gnome-software',
|
2022-10-27 14:38:26 +00:00
|
|
|
'80,6,500,/usr/pacman,0u,0g,pacman',
|
2022-10-30 13:39:10 +00:00
|
|
|
'80,6,500,/usr/python3.10,0u,0g,yum',
|
2022-12-16 22:37:32 +00:00
|
|
|
'80,6,500,/usr/python3.11,0u,0g,abrt-action-ins',
|
2022-10-31 21:40:37 +00:00
|
|
|
'80,6,500,/usr/rpi-imager,0u,0g,rpi-imager',
|
2022-11-22 14:21:03 +00:00
|
|
|
'80,6,500,/usr/thunderbird,0u,0g,thunderbird',
|
2022-10-20 12:04:24 +00:00
|
|
|
'8080,6,500,/opt/chrome,0u,0g,chrome',
|
|
|
|
'8080,6,500,/usr/firefox,0u,0g,firefox',
|
|
|
|
'8443,6,500,/opt/chrome,0u,0g,chrome',
|
2022-10-21 15:22:24 +00:00
|
|
|
'8443,6,500,/usr/firefox,0u,0g,firefox',
|
2022-11-03 15:51:54 +00:00
|
|
|
'8801,17,500,/app/zoom.real,u,g,zoom.real',
|
2022-11-08 01:36:37 +00:00
|
|
|
'8801,17,500,/opt/zoom,0u,0g,zoom',
|
2022-12-19 23:06:06 +00:00
|
|
|
'80,6,500,/usr/signal-desktop,0u,0g,signal-desktop',
|
|
|
|
'80,6,0,/usr/python3.10,0u,0g,dnf-automatic',
|
2023-01-03 13:50:19 +00:00
|
|
|
'22,6,500,/home/terraform,500u,500g,terraform',
|
2022-11-22 14:21:03 +00:00
|
|
|
'993,6,500,/app/thunderbird,u,g,thunderbird',
|
2022-12-16 22:37:32 +00:00
|
|
|
'993,6,500,/usr/evolution,0u,0g,evolution',
|
2023-01-03 13:50:19 +00:00
|
|
|
'80,6,500,/home/steam,500u,500g,steam',
|
2022-11-22 14:21:03 +00:00
|
|
|
'993,6,500,/usr/thunderbird,0u,0g,thunderbird'
|
2022-12-15 15:20:16 +00:00
|
|
|
)
|
2022-12-15 15:25:35 +00:00
|
|
|
AND NOT (
|
|
|
|
p.name = 'java'
|
|
|
|
AND p.cmdline LIKE '/home/%/.local/share/JetBrains/Toolbox/%'
|
|
|
|
AND s.remote_port > 1024
|
|
|
|
AND s.protocol = 6
|
|
|
|
AND p.euid > 500
|
|
|
|
)
|
2022-10-19 21:07:52 +00:00
|
|
|
AND NOT (
|
|
|
|
p.name = 'syncthing'
|
2022-10-20 11:04:18 +00:00
|
|
|
AND f.filename = 'syncthing'
|
|
|
|
AND s.remote_port > 1024
|
|
|
|
AND s.protocol = 6
|
|
|
|
AND p.euid > 500
|
2022-10-18 00:57:56 +00:00
|
|
|
)
|
2022-10-20 18:11:19 +00:00
|
|
|
AND NOT (
|
|
|
|
p.name = 'chrome'
|
|
|
|
AND f.filename = 'chrome'
|
|
|
|
AND s.remote_port > 5000
|
|
|
|
AND s.protocol = 6
|
|
|
|
AND p.euid > 500
|
|
|
|
)
|
2022-10-30 13:39:10 +00:00
|
|
|
-- TODO: Move this to a custom override overlay, as it is extremely obscure (small ISP)
|
|
|
|
AND NOT (
|
2022-11-03 15:51:54 +00:00
|
|
|
exception_key = '32768,6,500,/usr/ssh,0u,0g,ssh'
|
|
|
|
AND s.remote_port = 40022
|
|
|
|
AND s.remote_address = '104.131.84.33' -- gatekeeper.uservers.net
|
2022-10-30 13:39:10 +00:00
|
|
|
)
|
2022-10-20 18:01:34 +00:00
|
|
|
GROUP BY
|
|
|
|
p.cmdline
|