2023-01-30 19:58:47 +00:00
|
|
|
-- Suspicious parenting of network utilities (event-based)
|
2023-01-19 16:39:02 +00:00
|
|
|
--
|
|
|
|
-- refs:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1016/ (System Network Configuration Discovery)
|
|
|
|
--
|
|
|
|
-- tags: transient process state often
|
|
|
|
-- platform: linux
|
2023-02-01 21:17:36 +00:00
|
|
|
-- interval: 300
|
2023-01-19 16:39:02 +00:00
|
|
|
SELECT
|
2023-01-26 16:40:54 +00:00
|
|
|
-- Child
|
|
|
|
pe.path AS p0_path,
|
|
|
|
REGEX_MATCH (pe.path, '.*/(.*)', 1) AS p0_name,
|
|
|
|
TRIM(pe.cmdline) AS p0_cmd,
|
2023-02-01 18:55:55 +00:00
|
|
|
pe.cwd AS p0_cwd,
|
2023-01-26 16:40:54 +00:00
|
|
|
pe.pid AS p0_pid,
|
|
|
|
p.cgroup_path AS p0_cgroup,
|
|
|
|
-- Parent
|
|
|
|
pe.parent AS p1_pid,
|
|
|
|
p1.cgroup_path AS p1_cgroup,
|
|
|
|
TRIM(COALESCE(p1.cmdline, pe1.cmdline)) AS p1_cmd,
|
|
|
|
COALESCE(p1.path, pe1.path) AS p1_path,
|
|
|
|
COALESCE(p_hash1.sha256, pe_hash1.sha256) AS p1_hash,
|
2023-02-02 22:58:19 +00:00
|
|
|
REGEX_MATCH (COALESCE(p1.path, pe1.path), '.*/(.*)', 1) AS p1_name,
|
2023-01-26 16:40:54 +00:00
|
|
|
-- Grandparent
|
|
|
|
COALESCE(p1.parent, pe1.parent) AS p2_pid,
|
|
|
|
COALESCE(p1_p2.cgroup_path, pe1_p2.cgroup_path) AS p2_cgroup,
|
2023-02-02 22:58:19 +00:00
|
|
|
TRIM(
|
|
|
|
COALESCE(p1_p2.cmdline, pe1_p2.cmdline, pe1_pe2.cmdline)
|
|
|
|
) AS p2_cmd,
|
2023-01-26 16:40:54 +00:00
|
|
|
COALESCE(p1_p2.path, pe1_p2.path, pe1_pe2.path) AS p2_path,
|
2023-02-02 22:58:19 +00:00
|
|
|
COALESCE(
|
|
|
|
p1_p2_hash.path,
|
|
|
|
pe1_p2_hash.path,
|
|
|
|
pe1_pe2_hash.path
|
|
|
|
) AS p2_hash,
|
|
|
|
REGEX_MATCH (
|
|
|
|
COALESCE(p1_p2.path, pe1_p2.path, pe1_pe2.path),
|
|
|
|
'.*/(.*)',
|
|
|
|
1
|
|
|
|
) AS p2_name
|
2023-01-19 16:39:02 +00:00
|
|
|
FROM
|
2023-01-20 14:24:24 +00:00
|
|
|
process_events pe,
|
|
|
|
uptime
|
2023-01-19 16:39:02 +00:00
|
|
|
LEFT JOIN processes p ON pe.pid = p.pid
|
2023-01-26 16:40:54 +00:00
|
|
|
-- Parents (via two paths)
|
|
|
|
LEFT JOIN processes p1 ON pe.parent = p1.pid
|
|
|
|
LEFT JOIN hash p_hash1 ON p1.path = p_hash1.path
|
2023-02-02 22:58:19 +00:00
|
|
|
LEFT JOIN process_events pe1 ON pe.parent = pe1.pid
|
|
|
|
AND pe1.cmdline != ''
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN hash pe_hash1 ON pe1.path = pe_hash1.path
|
|
|
|
-- Grandparents (via 3 paths)
|
|
|
|
LEFT JOIN processes p1_p2 ON p1.parent = p1_p2.pid -- Current grandparent via parent processes
|
|
|
|
LEFT JOIN processes pe1_p2 ON pe1.parent = pe1_p2.pid -- Current grandparent via parent events
|
2023-02-02 22:58:19 +00:00
|
|
|
LEFT JOIN process_events pe1_pe2 ON pe1.parent = pe1_p2.pid
|
|
|
|
AND pe1_pe2.cmdline != '' -- Past grandparent via parent events
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN hash p1_p2_hash ON p1_p2.path = p1_p2_hash.path
|
|
|
|
LEFT JOIN hash pe1_p2_hash ON pe1_p2.path = pe1_p2_hash.path
|
|
|
|
LEFT JOIN hash pe1_pe2_hash ON pe1_pe2.path = pe1_pe2_hash.path
|
2023-01-19 16:39:02 +00:00
|
|
|
WHERE
|
|
|
|
uptime.total_seconds > 30
|
|
|
|
AND pe.path IN (
|
|
|
|
'/usr/bin/ifconfig',
|
|
|
|
'/usr/bin/ip',
|
|
|
|
'/usr/bin/iptables',
|
|
|
|
'/usr/bin/ufw',
|
|
|
|
'/usr/bin/nft',
|
|
|
|
'/bin/ifconfig',
|
|
|
|
'/bin/ip',
|
|
|
|
'/bin/iptables',
|
|
|
|
'/bin/ufw',
|
|
|
|
'/bin/nft',
|
|
|
|
'/sbin/ifconfig',
|
|
|
|
'/sbin/ip',
|
|
|
|
'/sbin/iptables',
|
|
|
|
'/sbin/ufw',
|
|
|
|
'/sbin/nft'
|
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
AND pe.cmdline != ''
|
2023-02-01 21:17:36 +00:00
|
|
|
AND pe.time > (strftime('%s', 'now') -300)
|
2023-01-19 16:39:02 +00:00
|
|
|
AND NOT (
|
|
|
|
pe.euid > 500
|
2023-01-26 16:40:54 +00:00
|
|
|
AND p1_name IN ('sh', 'fish', 'zsh', 'bash', 'dash')
|
|
|
|
AND p2_name IN (
|
2023-01-19 16:39:02 +00:00
|
|
|
'alacritty',
|
|
|
|
'gnome-terminal-',
|
|
|
|
'kitty',
|
|
|
|
'login',
|
|
|
|
'roxterm',
|
|
|
|
'tmux',
|
|
|
|
'tmux:server',
|
|
|
|
'wezterm-gui',
|
|
|
|
'zsh'
|
|
|
|
)
|
|
|
|
)
|
2023-05-05 16:44:46 +00:00
|
|
|
AND NOT p1_cmd IN ('/bin/sh /etc/network/if-up.d/avahi-autoipd', '/usr/bin/libvirtd --timeout 120')
|
2023-02-14 13:33:05 +00:00
|
|
|
AND NOT p1_path IN ('/usr/libexec/gvfsd')
|
2023-05-05 16:44:46 +00:00
|
|
|
AND NOT p0_cmd LIKE '%ip route add % dev % metric 1000 scope link'
|
|
|
|
AND NOT p0_cmd LIKE '%ip link set lo netns -1'
|
2023-01-19 16:39:02 +00:00
|
|
|
GROUP BY
|
|
|
|
pe.pid
|