2023-01-19 16:39:02 +00:00
|
|
|
-- Suspicious parenting of fetch tools (event-based)
|
|
|
|
--
|
|
|
|
-- refs:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1016/ (System Network Configuration Discovery)
|
|
|
|
--
|
|
|
|
-- tags: transient process state often
|
2023-01-27 13:46:48 +00:00
|
|
|
-- platform: darwin
|
2023-01-20 13:40:08 +00:00
|
|
|
-- interval: 600
|
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,
|
2023-05-16 21:18:39 +00:00
|
|
|
pe.time AS p0_time,
|
2023-01-26 16:40:54 +00:00
|
|
|
pe.euid AS p0_euid,
|
|
|
|
s.authority AS p0_authority,
|
|
|
|
-- Parent
|
2023-02-09 22:01:29 +00:00
|
|
|
pe.parent AS p1_pid,
|
2023-01-26 16:40:54 +00:00
|
|
|
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
|
|
|
pe_sig1.authority AS p1_authority,
|
|
|
|
-- Grandparent
|
|
|
|
COALESCE(p1.parent, pe1.parent) AS p2_pid,
|
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,
|
|
|
|
COALESCE(
|
|
|
|
p1_p2_sig.authority,
|
|
|
|
pe1_p2_sig.authority,
|
|
|
|
pe1_pe2_sig.authority
|
|
|
|
) AS p2_authority,
|
2023-01-26 16:40:54 +00:00
|
|
|
-- Exception key
|
2023-02-02 22:58:19 +00:00
|
|
|
REGEX_MATCH (pe.path, '.*/(.*)', 1) || ',' || MIN(pe.euid, 500) || ',' || REGEX_MATCH (COALESCE(p1.path, pe1.path), '.*/(.*)', 1) || ',' || REGEX_MATCH (
|
|
|
|
COALESCE(p1_p2.path, pe1_p2.path, pe1_pe2.path),
|
|
|
|
'.*/(.*)',
|
|
|
|
1
|
|
|
|
) AS exception_key
|
2023-01-19 16:39:02 +00:00
|
|
|
FROM
|
2023-02-02 22:58:19 +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
|
|
|
LEFT JOIN signature s ON pe.path = s.path
|
|
|
|
-- 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
|
|
|
|
LEFT JOIN signature pe_sig1 ON pe1.path = pe_sig1.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
|
|
|
|
LEFT JOIN signature p1_p2_sig ON p1_p2.path = p1_p2_sig.path
|
|
|
|
LEFT JOIN signature pe1_p2_sig ON pe1_p2.path = pe1_p2_sig.path
|
|
|
|
LEFT JOIN signature pe1_pe2_sig ON pe1_pe2.path = pe1_pe2_sig.path
|
2023-01-19 16:39:02 +00:00
|
|
|
WHERE
|
|
|
|
pe.path IN (
|
|
|
|
'/sbin/ifconfig',
|
|
|
|
'/usr/sbin/netstat',
|
2023-07-12 20:45:09 +00:00
|
|
|
'/usr/bin/nscurl',
|
2023-01-19 16:39:02 +00:00
|
|
|
'/sbin/pfctl',
|
|
|
|
'/usr/libexec/ApplicationFirewall/socketfilterfw'
|
|
|
|
)
|
|
|
|
AND uptime.total_seconds > 30
|
2023-01-26 16:40:54 +00:00
|
|
|
AND pe.time > (strftime('%s', 'now') -600)
|
|
|
|
AND pe.cmdline != ''
|
2023-01-20 22:55:48 +00:00
|
|
|
AND pe.cmdline IS NOT NULL
|
2023-01-19 16:39:02 +00:00
|
|
|
AND pe.status == 0
|
|
|
|
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
|
|
|
'kitty',
|
|
|
|
'login',
|
|
|
|
'tmux',
|
|
|
|
'ShellLauncher',
|
2023-01-26 16:40:54 +00:00
|
|
|
'sudo',
|
2023-01-19 16:39:02 +00:00
|
|
|
'tmux:server',
|
|
|
|
'zsh'
|
|
|
|
)
|
|
|
|
)
|
2023-01-26 21:30:14 +00:00
|
|
|
AND NOT exception_key IN (
|
2024-08-12 17:57:35 +00:00
|
|
|
'ifconfig,0,cloud-provider-kind,sudo',
|
2024-01-18 22:15:37 +00:00
|
|
|
'ifconfig,0,pia-daemon,launchd',
|
|
|
|
'ifconfig,0,pia-openvpn,pia-daemon',
|
2024-02-16 22:14:11 +00:00
|
|
|
'ifconfig,500,dotnet,dotnet',
|
2024-08-12 17:57:35 +00:00
|
|
|
'ifconfig,500,dotnet,zsh',
|
2024-08-27 22:40:43 +00:00
|
|
|
'ifconfig,500,Python,Code Helper (Plugin)',
|
2024-08-12 17:57:35 +00:00
|
|
|
'ifconfig,500,zsh,stable',
|
2023-03-03 12:24:42 +00:00
|
|
|
'netstat,0,io.tailscale.ipn.macsys.network-extension,launchd',
|
2024-01-18 22:15:37 +00:00
|
|
|
'netstat,0,metricbeat,elastic-agent',
|
2023-02-08 19:37:09 +00:00
|
|
|
'netstat,0,pia-daemon,launchd',
|
2024-01-18 22:15:37 +00:00
|
|
|
'netstat,500,AccountSubscriber,launchd',
|
|
|
|
'netstat,500,coresymbolicationd,launchd',
|
2024-08-27 22:40:43 +00:00
|
|
|
'netstat,500,IPNExtension,launchd',
|
2024-01-18 22:15:37 +00:00
|
|
|
'pfctl,0,bash,pia-daemon',
|
2024-08-27 22:40:43 +00:00
|
|
|
'pfctl,0,pia-daemon,launchd',
|
|
|
|
'socketfilterfw,0,launcher,launchd'
|
2023-01-26 21:30:14 +00:00
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
AND p1_cmd NOT IN ('/bin/sh /etc/periodic/daily/420.status-network')
|
2023-07-12 21:38:26 +00:00
|
|
|
AND p1_authority != 'Software Signing'
|
2023-01-19 16:39:02 +00:00
|
|
|
GROUP BY
|
|
|
|
pe.pid
|