2022-10-14 18:19:13 +00:00
|
|
|
-- Pick out exotic processes based on their command-line (events-based)
|
|
|
|
--
|
2022-10-18 14:08:34 +00:00
|
|
|
-- references:
|
|
|
|
-- * https://themittenmac.com/what-does-apt-activity-look-like-on-macos/
|
|
|
|
--
|
2022-10-14 18:19:13 +00:00
|
|
|
-- false positives:
|
|
|
|
-- * possible, but none known
|
|
|
|
--
|
|
|
|
-- tags: transient process events
|
|
|
|
-- platform: linux
|
2023-02-01 21:17:36 +00:00
|
|
|
-- interval: 300
|
2023-06-07 13:55:17 +00:00
|
|
|
SELECT -- Child
|
2023-01-26 16:40:54 +00:00
|
|
|
pe.path AS p0_path,
|
2023-05-16 21:18:39 +00:00
|
|
|
pe.time AS p0_time,
|
2023-01-26 16:40:54 +00:00
|
|
|
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-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-06-07 13:55:17 +00:00
|
|
|
FROM process_events pe,
|
2023-01-20 14:24:24 +00:00
|
|
|
uptime
|
2023-06-07 13:55:17 +00:00
|
|
|
LEFT JOIN processes p ON pe.pid = p.pid -- Parents (via two paths)
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN processes p1 ON pe.parent = p1.pid
|
2023-03-21 18:07:06 +00:00
|
|
|
AND p1.start_time <= pe.time
|
2023-01-26 16:40:54 +00:00
|
|
|
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
|
2023-03-21 18:07:06 +00:00
|
|
|
AND pe1.time <= pe.time
|
2023-02-02 22:58:19 +00:00
|
|
|
AND pe1.cmdline != ''
|
2023-06-07 13:55:17 +00:00
|
|
|
LEFT JOIN hash pe_hash1 ON pe1.path = pe_hash1.path -- Grandparents (via 3 paths)
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN processes p1_p2 ON p1.parent = p1_p2.pid -- Current grandparent via parent processes
|
2023-03-21 18:07:06 +00:00
|
|
|
AND p1_p2.start_time <= p1.start_time
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN processes pe1_p2 ON pe1.parent = pe1_p2.pid -- Current grandparent via parent events
|
2023-03-21 18:07:06 +00:00
|
|
|
AND pe1_p2.start_time <= pe1.time
|
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-06-07 13:55:17 +00:00
|
|
|
WHERE pe.time > (strftime('%s', 'now') -300)
|
2023-01-26 16:40:54 +00:00
|
|
|
AND pe.cmdline != ''
|
2022-09-24 15:12:23 +00:00
|
|
|
AND (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_name IN (
|
2022-09-24 15:12:23 +00:00
|
|
|
'bitspin',
|
|
|
|
'bpftool',
|
|
|
|
'heyoka',
|
|
|
|
'nstx',
|
|
|
|
'dnscat2',
|
|
|
|
'tuns',
|
|
|
|
'iodine',
|
2022-12-15 21:51:58 +00:00
|
|
|
'esxcli',
|
|
|
|
'vim-cmd',
|
2022-11-22 14:21:03 +00:00
|
|
|
'minerd',
|
|
|
|
'cpuminer-multi',
|
|
|
|
'cpuminer',
|
|
|
|
'httpdns',
|
2022-09-24 15:12:23 +00:00
|
|
|
'rshell',
|
|
|
|
'rsh',
|
2022-11-22 14:21:03 +00:00
|
|
|
'xmrig',
|
2022-09-24 15:12:23 +00:00
|
|
|
'incbit',
|
|
|
|
'insmod',
|
|
|
|
'kmod',
|
|
|
|
'lushput',
|
|
|
|
'mkfifo',
|
|
|
|
'msfvenom',
|
|
|
|
'nc',
|
|
|
|
'socat'
|
2023-06-07 13:55:17 +00:00
|
|
|
) -- Chrome Stealer
|
|
|
|
OR p0_cmd LIKE '%chrome%-load-extension%' -- Known attack scripts
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_name LIKE '%pwn%'
|
2023-06-07 13:55:17 +00:00
|
|
|
OR p0_name LIKE '%attack%' -- Unusual behaviors
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%ufw disable%'
|
2023-03-17 10:32:54 +00:00
|
|
|
OR p0_cmd LIKE '%iptables stop'
|
|
|
|
OR p0_cmd LIKE '%setenforce 0'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%iptables -P % ACCEPT%'
|
|
|
|
OR p0_cmd LIKE '%iptables -F%'
|
2023-03-17 10:32:54 +00:00
|
|
|
OR p0_cmd LIKE '%chattr -i%'
|
2023-03-17 10:37:18 +00:00
|
|
|
OR p0_cmd LIKE '%dd if=/dev/%'
|
2023-03-17 10:32:54 +00:00
|
|
|
OR p0_cmd LIKE '%cat /dev/null >%'
|
|
|
|
OR p0_cmd LIKE '%truncate -s0 %'
|
2023-01-09 15:46:30 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
INSTR(p0_cmd, 'history') > 0
|
|
|
|
AND p0_cmd LIKE '%history'
|
2023-02-17 16:57:23 +00:00
|
|
|
AND p0_cmd NOT LIKE 'man %'
|
2023-01-09 15:46:30 +00:00
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%touch%acmr%'
|
|
|
|
OR p0_cmd LIKE '%touch -r%'
|
|
|
|
OR p0_cmd LIKE '%ld.so.preload%'
|
|
|
|
OR p0_cmd LIKE '%urllib.urlopen%'
|
|
|
|
OR p0_cmd LIKE '%nohup%tmp%'
|
|
|
|
OR p0_cmd LIKE '%systemctl stop firewalld%'
|
|
|
|
OR p0_cmd LIKE '%systemctl disable firewalld%'
|
|
|
|
OR p0_cmd LIKE '%pkill -f%'
|
2022-11-18 15:27:43 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd LIKE '%xargs kill -9%'
|
2023-01-18 14:49:56 +00:00
|
|
|
AND pe.euid = 0
|
2022-11-18 15:27:43 +00:00
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%rm -rf /boot%'
|
|
|
|
OR p0_cmd LIKE '%nohup /bin/bash%'
|
|
|
|
OR p0_cmd LIKE '%echo%|%base64 --decode %|%'
|
2023-06-07 13:55:17 +00:00
|
|
|
OR p0_cmd LIKE '%UserKnownHostsFile=/dev/null%' -- Crypto miners
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%monero%'
|
|
|
|
OR p0_cmd LIKE '%nanopool%'
|
|
|
|
OR p0_cmd LIKE '%nicehash%'
|
2023-06-07 13:55:17 +00:00
|
|
|
OR p0_cmd LIKE '%stratum%' -- Random keywords
|
|
|
|
OR p0_cmd LIKE '%ransom%' -- Reverse shells
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%/dev/tcp/%'
|
|
|
|
OR p0_cmd LIKE '%/dev/udp/%'
|
|
|
|
OR p0_cmd LIKE '%fsockopen%'
|
|
|
|
OR p0_cmd LIKE '%openssl%quiet%'
|
|
|
|
OR p0_cmd LIKE '%pty.spawn%'
|
2022-11-17 12:20:19 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd LIKE '%sh -i'
|
|
|
|
AND NOT p1_name IN ('sh', 'java')
|
2022-11-17 12:20:19 +00:00
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%SOCK_STREAM%'
|
|
|
|
OR INSTR(p0_cmd, 'Socket.') > 0
|
2023-01-13 20:24:18 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd LIKE '%tail -f /dev/null%'
|
2023-01-18 14:49:56 +00:00
|
|
|
AND p.cgroup_path NOT LIKE '/system.slice/docker-%'
|
2023-01-13 20:24:18 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
) -- Things that could reasonably happen at boot.
|
|
|
|
AND NOT (
|
2023-01-18 14:49:56 +00:00
|
|
|
pe.path IN ('/usr/bin/kmod', '/bin/kmod')
|
2023-01-26 16:40:54 +00:00
|
|
|
AND p1_path = '/usr/lib/systemd/systemd'
|
|
|
|
AND p1_cmd = '/sbin/init'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
AND NOT (
|
2023-01-18 14:49:56 +00:00
|
|
|
pe.path IN ('/usr/bin/kmod', '/bin/kmod')
|
2023-01-26 16:40:54 +00:00
|
|
|
AND p1_name IN (
|
2022-10-17 23:06:17 +00:00
|
|
|
'firewalld',
|
|
|
|
'mkinitramfs',
|
|
|
|
'systemd',
|
|
|
|
'dockerd',
|
|
|
|
'kube-proxy'
|
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
2023-02-14 13:33:05 +00:00
|
|
|
AND NOT (
|
|
|
|
p0_cmd LIKE '/usr/bin/modprobe %'
|
|
|
|
AND p1_cgroup = '/system.slice/firewalld.service'
|
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
AND NOT (
|
2023-01-18 14:49:56 +00:00
|
|
|
pe.path IN ('/usr/bin/kmod', '/bin/kmod')
|
2022-09-24 15:12:23 +00:00
|
|
|
AND uptime.total_seconds < 15
|
|
|
|
)
|
|
|
|
AND NOT (
|
2023-01-18 14:49:56 +00:00
|
|
|
pe.path = '/usr/bin/mkfifo'
|
2023-02-24 21:30:17 +00:00
|
|
|
AND (
|
|
|
|
p0_cmd LIKE '%/org.gpgtools.log.%/fifo'
|
|
|
|
OR p0_cmd LIKE 'mkfifo -- /private/var/folders/%/T/gitstatus.POWERLEVEL9K.501.%.fifo'
|
|
|
|
OR p0_cmd LIKE 'mkfifo -- /var/folders/%/T//p10k.worker.501.%.fifo'
|
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
2023-03-20 21:05:02 +00:00
|
|
|
AND NOT p0_cmd IN ('lsmod', 'dd if=/dev/stdin conv=unblock cbs=79')
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE 'dirname %history'
|
|
|
|
AND NOT p0_cmd LIKE 'find . -executable -type f -name %grep -l GNU Libtool%touch -r%'
|
|
|
|
AND NOT p0_cmd LIKE 'modinfo -k%'
|
|
|
|
AND NOT p0_cmd LIKE 'modprobe -ab%'
|
|
|
|
AND NOT p0_cmd LIKE 'modprobe --all%'
|
|
|
|
AND NOT p0_cmd LIKE '%modprobe aufs'
|
2023-03-03 12:24:42 +00:00
|
|
|
AND NOT p0_cmd LIKE '%touch -r /tmp/cc%.o %'
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE '%modprobe overlay'
|
2023-02-14 13:33:05 +00:00
|
|
|
AND NOT p0_cmd LIKE '%modprobe nf_nat_netbios_ns'
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE '%modprobe -va%'
|
|
|
|
AND NOT p0_cmd LIKE 'pkill -f cut -c3%'
|
|
|
|
AND NOT p0_cmd LIKE 'tail /%history'
|
2023-03-17 10:32:54 +00:00
|
|
|
AND NOT p0_cmd LIKE '%/usr/bin/cmake%Socket%'
|
2023-03-03 12:24:42 +00:00
|
|
|
AND NOT p0_name IN ('ar', 'cc1', 'compile', 'cmake', 'cc1plus')
|
2023-06-07 13:55:17 +00:00
|
|
|
AND NOT exception_key IN (
|
|
|
|
'bash,500,ninja,bash',
|
|
|
|
'ls,500,zsh,alacritty',
|
|
|
|
'bash,0,bash,containerd-shim-runc-v2'
|
|
|
|
)
|