osquery-defense-kit/net/unexpected-talkers-linux.sql

350 lines
7.7 KiB
MySQL
Raw Normal View History

SELECT
s.family,
2022-09-22 09:18:03 +00:00
protocol,
s.local_port,
s.remote_port,
s.local_address,
s.remote_address,
p.name,
p.path,
p.cmdline AS child_cmd,
p.cwd,
s.pid,
s.net_namespace,
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,
hash.sha256,
CONCAT (
2022-09-22 09:18:03 +00:00
MIN(s.remote_port, 32768),
",",
protocol,
",",
MIN(p.uid, 500),
",",
p.name
) AS exception_key
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
LEFT JOIN hash ON p.path = hash.path
WHERE
protocol > 0
2022-09-22 09:18:03 +00:00
AND s.remote_port > 0
2022-09-23 17:03:11 +00:00
AND s.remote_address NOT IN ("127.0.0.1", "::ffff:127.0.0.1", "::1")
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:%"
AND s.state != "LISTEN"
2022-09-22 09:18:03 +00:00
-- DNS clients
AND NOT (
remote_port = 53
AND protocol IN (6, 17)
AND p.name IN (
2022-09-23 17:03:11 +00:00
"1password",
"apt",
"apt-get",
"Brackets",
"chainctl",
"chrome",
"chronyd",
"cloud_sql_proxy",
"code",
"containerd",
"controlplane",
"crc",
"curl",
"dig",
"dnf",
"electron",
"firefox",
".firefox-wrappe",
"flameshot",
"gh",
"git-remote-http",
"gitsign",
"gnome-software",
"go",
"grafana-server",
"grype",
"host",
"htop",
"istioctl",
"jcef_helper",
"k6",
"k9s",
"ko",
"kolide-pipeline",
"launcher",
"NetworkManager",
"ngrok",
"nix",
"node",
"nscd",
"obs",
"obs-browser-page",
"obs-ffmpeg-mux",
"obsidian",
"opera",
"pacman",
"ping",
"podman",
"prometheus",
"rootlessport",
"signal-desktop",
"slack",
"slirp4netns",
"snapd",
"snap-store",
"Socket Process",
"spotify",
"ssh",
"steam",
"steamwebhelper",
"syncthing",
"systemd-resolve",
"tailscaled",
".tailscaled-wra",
"terraform",
"terraform-provi",
"tkn",
"traceroute",
"vcluster",
"wget",
"whois",
"xmobar",
"yay",
"zoom"
2022-09-22 09:18:03 +00:00
)
2022-09-21 11:42:51 +00:00
)
2022-09-22 09:18:03 +00:00
-- General exceptions
AND NOT exception_key IN (
2022-09-23 17:03:11 +00:00
"123,17,,",
2022-09-29 19:42:27 +00:00
"123,17,500,chronyd",
"22,6,,", -- shortlived SSH (git push)
2022-09-30 17:47:10 +00:00
"22,6,500,ssh",
"22067,6,500,syncthing",
2022-09-23 17:03:11 +00:00
"27024,6,500,steam",
"3100,6,500,firefox",
"3100,6,500,k6",
"3307,6,500,cloud_sql_proxy",
"4070,6,500,spotify",
"443,17,500,chrome",
"443,17,500,electron",
"443,17,500,jcef_helper",
"443,17,500,slack",
"443,17,500,spotify",
2022-09-30 17:47:10 +00:00
"443,6,0,.tailscaled-wra",
2022-09-29 19:42:27 +00:00
"443,6,0,containerd",
"443,6,0,depmod",
"443,6,0,dirmngr",
2022-09-23 17:03:11 +00:00
"443,6,0,dnf",
"443,6,0,dockerd",
"443,6,0,influxd",
"443,6,0,launcher",
2022-09-29 19:42:27 +00:00
"443,6,0,nix-daemon",
"443,6,0,packagekitd",
2022-09-23 17:03:11 +00:00
"443,6,0,pacman",
"443,6,0,snapd",
"443,6,0,tailscaled",
2022-09-29 19:42:27 +00:00
"443,6,0,yum",
"443,6,105,https", -- /usr/lib/apt/methods/https
2022-09-23 17:03:11 +00:00
"443,6,472,grafana-server",
2022-09-30 17:47:10 +00:00
"443,6,500,___go_build_github_com_anchore_grype,a.out,",
"443,6,500,.firefox-wrappe",
2022-09-23 17:03:11 +00:00
"443,6,500,1password",
"443,6,500,authentik-proxy",
2022-09-29 19:42:27 +00:00
"443,6,500,aws",
2022-09-23 17:03:11 +00:00
"443,6,500,Brackets",
"443,6,500,celery",
"443,6,500,chainctl",
"443,6,500,chrome",
"443,6,500,cloud_sql_proxy",
"443,6,500,code",
"443,6,500,containerd",
"443,6,500,controlplane",
"443,6,500,cosign",
"443,6,500,crane",
2022-09-29 19:42:27 +00:00
"443,6,500,CrBrowserMain",
2022-09-23 17:03:11 +00:00
"443,6,500,crc",
2022-09-29 19:42:27 +00:00
"443,6,500,CrUtilityMain",
2022-09-23 17:03:11 +00:00
"443,6,500,curl",
"443,6,500,Discord",
"443,6,500,electron",
2022-09-30 17:47:10 +00:00
"443,6,500,emacs",
2022-09-23 17:03:11 +00:00
"443,6,500,firefox",
"443,6,500,flameshot",
2022-09-29 19:42:27 +00:00
"443,6,500,geoclue",
2022-09-23 17:03:11 +00:00
"443,6,500,gh",
"443,6,500,git-remote-http",
"443,6,500,gitsign",
"443,6,500,gnome-shell",
"443,6,500,gnome-software",
"443,6,500,go",
"443,6,500,grafana-server",
"443,6,500,grype",
"443,6,500,gunicorn",
2022-09-29 19:42:27 +00:00
"443,6,500,gvfsd-http",
2022-09-23 17:03:11 +00:00
"443,6,500,htop",
2022-09-29 19:42:27 +00:00
"443,6,500,influxd",
2022-09-23 17:03:11 +00:00
"443,6,500,istioctl",
2022-09-29 19:42:27 +00:00
"443,6,500,java",
"443,6,500,jcef_helper",
"443,6,500,jetbrains-toolb",
2022-09-23 17:03:11 +00:00
"443,6,500,k6",
"443,6,500,k9s",
"443,6,500,ko",
"443,6,500,kolide-pipeline",
"443,6,500,kubectl",
"443,6,500,ngrok",
"443,6,500,nix",
"443,6,500,node",
"443,6,500,obs-browser-page",
"443,6,500,obs-ffmpeg-mux",
2022-09-30 17:47:10 +00:00
"443,6,500,obs",
2022-09-23 17:03:11 +00:00
"443,6,500,obsidian",
2022-09-29 19:42:27 +00:00
"443,6,500,pingsender",
2022-09-30 17:47:10 +00:00
"443,6,500,pip",
2022-09-23 17:03:11 +00:00
"443,6,500,podman",
"443,6,500,signal-desktop",
"443,6,500,slack",
"443,6,500,slirp4netns",
"443,6,500,snap-store",
"443,6,500,Socket Process",
"443,6,500,spotify",
"443,6,500,steamwebhelper",
2022-09-29 19:42:27 +00:00
"443,6,500,teams",
"443,6,500,terraform-provi",
2022-09-30 17:47:10 +00:00
"443,6,500,terraform",
2022-09-23 17:03:11 +00:00
"443,6,500,tkn",
2022-09-29 19:42:27 +00:00
"443,6,500,trivy",
2022-09-23 17:03:11 +00:00
"443,6,500,vcluster",
"443,6,500,vim",
2022-09-29 19:42:27 +00:00
"443,6,500,WebKitNetworkPr",
2022-09-23 17:03:11 +00:00
"443,6,500,wget",
2022-09-29 19:42:27 +00:00
"443,6,500,wineserver",
2022-09-30 17:47:10 +00:00
"443,6,500,x11-ssh-askpass",
2022-09-23 17:03:11 +00:00
"443,6,500,xmobar",
"443,6,500,yay",
"443,6,500,zoom",
"5228,6,500,chrome",
"6000,6,500,ssh",
2022-09-29 19:42:27 +00:00
"7903,6,500,syncthing",
2022-09-30 17:47:10 +00:00
"80,6,0,.tailscaled-wra",
2022-09-23 17:03:11 +00:00
"80,6,0,dnf",
"443,6,500,.tox-wrapped",
2022-09-23 17:03:11 +00:00
"80,6,0,NetworkManager",
"80,6,0,pacman",
"80,6,0,tailscaled",
2022-09-29 19:42:27 +00:00
"80,6,0,yum",
"80,6,105,http", -- /usr/lib/apt/methods/http
2022-09-30 17:47:10 +00:00
"80,6,500,.firefox-wrappe",
2022-09-23 17:03:11 +00:00
"80,6,500,curl",
"80,6,500,firefox",
2022-09-29 19:42:27 +00:00
"80,6,500,slack",
"80,6,500,spotify",
2022-09-23 17:03:11 +00:00
"80,6,500,steam",
"80,6,500,steamwebhelper",
"80,6,500,syncthing",
2022-09-30 17:47:10 +00:00
"8006,6,500,chrome",
2022-09-23 17:03:11 +00:00
"8801,17,500,zoom",
"9090,6,500,firefox",
"9090,6,500,k6",
"9090,6,500,prometheus",
"9090,6,500,rootlessport"
2022-09-29 19:42:27 +00:00
2022-09-22 09:18:03 +00:00
)
-- These programs would normally never make an outgoing connection, but thanks to Nix, it can happen.
2022-09-22 17:18:16 +00:00
AND NOT (
remote_address LIKE("151.101.%")
2022-09-22 17:18:16 +00:00
AND remote_port = 443
AND protocol = 6
AND (
parent_path LIKE "%/bin/bash"
OR parent_path LIKE "%/bin/zsh"
OR parent_path LIKE "%/bin/nix"
OR p.path LIKE "/nix/store/%"
2022-09-22 17:18:16 +00:00
)
)
2022-09-29 19:42:27 +00:00
AND NOT p.cmdline LIKE "bash --rcfile /tmp/nix-shell.%"
2022-09-22 09:18:03 +00:00
-- Other more complicated situations
AND NOT (
2022-09-23 17:03:11 +00:00
p.name = "rootlessport"
2022-09-22 09:18:03 +00:00
AND remote_port > 1024
)
AND NOT (
2022-09-23 17:03:11 +00:00
p.name = "syncthing"
2022-09-22 09:18:03 +00:00
AND (
remote_port IN (53, 80, 88, 110, 443, 587, 993, 3306, 7451)
OR remote_port > 1024
2022-09-22 09:18:03 +00:00
)
)
AND NOT (
p.name IN (
2022-09-23 17:03:11 +00:00
"chrome",
"Google Chrome Helper",
"Brave Browser Helper",
"Chromium Helper",
"Opera Helper"
2022-09-22 09:18:03 +00:00
)
AND remote_port IN (
53,
3100,
443,
80,
8006,
9000,
5004,
8009,
8080,
8888,
8443,
5228,
32211,
53,
10001,
3478,
19305,
19306,
19307,
19308,
19309
)
)
AND NOT (
2022-09-23 17:03:11 +00:00
p.name IN ("thunderbird")
2022-09-22 09:18:03 +00:00
AND remote_port IN (53, 143, 443, 587, 465, 585, 993)
)
AND NOT (
2022-09-23 17:03:11 +00:00
p.name IN ("spotify", "Spotify Helper", "Spotify")
2022-09-22 09:18:03 +00:00
AND remote_port IN (53, 443, 8009, 4070, 32211)
)
AND NOT (
remote_port IN (443, 53)
2022-09-23 17:03:11 +00:00
AND p.name LIKE "terraform-provider-%"
2022-09-22 09:18:03 +00:00
)
2022-09-26 18:25:32 +00:00
AND NOT (
remote_port IN (443, 53)
AND p.name LIKE "npm exec %"
)
2022-09-22 09:18:03 +00:00
AND NOT (
remote_port iN (443, 53)
2022-09-23 17:03:11 +00:00
AND p.name LIKE "kubectl.%"
2022-09-22 09:18:03 +00:00
)
AND NOT (
2022-09-23 17:03:11 +00:00
p.cmdline LIKE "%google-cloud-sdk/lib/gcloud.py%"
2022-09-22 09:18:03 +00:00
AND remote_port IN (80, 53, 443)
)
GROUP BY
p.cmdline