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
|
2022-11-22 14:21:03 +00:00
|
|
|
-- interval: 30
|
2022-09-24 15:12:23 +00:00
|
|
|
SELECT
|
|
|
|
p.pid,
|
|
|
|
p.path,
|
|
|
|
REPLACE(
|
2022-09-15 13:34:45 +00:00
|
|
|
p.path,
|
2022-09-24 15:12:23 +00:00
|
|
|
RTRIM(p.path, REPLACE(p.path, '/', '')),
|
|
|
|
''
|
|
|
|
) AS basename,
|
|
|
|
-- On macOS there is often a trailing space
|
|
|
|
TRIM(p.cmdline) AS cmd,
|
|
|
|
p.mode,
|
|
|
|
p.cwd,
|
|
|
|
p.euid,
|
|
|
|
p.parent,
|
|
|
|
p.syscall,
|
2022-11-18 15:27:43 +00:00
|
|
|
pp.cgroup_path,
|
2022-09-24 15:12:23 +00:00
|
|
|
hash.sha256,
|
|
|
|
pp.path AS parent_path,
|
|
|
|
pp.name AS parent_name,
|
|
|
|
TRIM(p.cmdline) AS parent_cmd,
|
|
|
|
pp.euid AS parent_euid,
|
|
|
|
phash.sha256 AS parent_sha256
|
|
|
|
FROM
|
|
|
|
uptime,
|
|
|
|
process_events p
|
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
|
|
|
LEFT JOIN hash ON p.path = hash.path
|
2022-10-21 21:39:01 +00:00
|
|
|
LEFT JOIN hash AS phash ON pp.path = phash.path
|
2022-09-24 15:12:23 +00:00
|
|
|
WHERE
|
2022-11-22 14:21:03 +00:00
|
|
|
p.time > (strftime('%s', 'now') -30)
|
2022-09-24 15:12:23 +00:00
|
|
|
AND (
|
|
|
|
basename IN (
|
|
|
|
'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'
|
2022-09-20 21:46:47 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
-- Chrome Stealer
|
|
|
|
OR cmd LIKE '%chrome%-load-extension%'
|
|
|
|
-- Known attack scripts
|
|
|
|
OR basename LIKE '%pwn%'
|
|
|
|
OR basename LIKE '%attack%'
|
|
|
|
-- Unusual behaviors
|
|
|
|
OR cmd LIKE '%ufw disable%'
|
|
|
|
OR cmd LIKE '%iptables -P % ACCEPT%'
|
|
|
|
OR cmd LIKE '%iptables -F%'
|
|
|
|
OR cmd LIKE '%chattr -ia%'
|
2022-10-07 16:46:55 +00:00
|
|
|
OR cmd LIKE '%chmod 777 %'
|
2022-11-08 01:36:37 +00:00
|
|
|
OR cmd LIKE '%history'
|
2022-09-24 15:12:23 +00:00
|
|
|
OR cmd LIKE '%touch%acmr%'
|
2022-10-18 15:32:18 +00:00
|
|
|
OR cmd LIKE '%touch -r%'
|
2022-09-24 15:12:23 +00:00
|
|
|
OR cmd LIKE '%ld.so.preload%'
|
|
|
|
OR cmd LIKE '%urllib.urlopen%'
|
|
|
|
OR cmd LIKE '%nohup%tmp%'
|
2022-10-13 18:59:32 +00:00
|
|
|
OR cmd LIKE '%iptables stop'
|
|
|
|
OR cmd LIKE '%systemctl stop firewalld%'
|
|
|
|
OR cmd LIKE '%systemctl disable firewalld%'
|
|
|
|
OR cmd LIKE '%pkill -f%'
|
2022-11-18 15:27:43 +00:00
|
|
|
OR (
|
|
|
|
cmd LIKE '%xargs kill -9%'
|
|
|
|
AND p.euid = 0
|
|
|
|
)
|
2022-10-13 18:59:32 +00:00
|
|
|
OR cmd LIKE '%rm -rf /boot%'
|
|
|
|
OR cmd LIKE '%nohup /bin/bash%'
|
2022-10-13 22:31:59 +00:00
|
|
|
OR cmd LIKE '%echo%|%base64 --decode %|%'
|
2022-10-18 14:08:34 +00:00
|
|
|
OR cmd LIKE '%UserKnownHostsFile=/dev/null%'
|
2022-09-24 15:12:23 +00:00
|
|
|
-- Crypto miners
|
|
|
|
OR cmd LIKE '%monero%'
|
|
|
|
OR cmd LIKE '%nanopool%'
|
|
|
|
OR cmd LIKE '%nicehash%'
|
|
|
|
OR cmd LIKE '%stratum%'
|
|
|
|
-- Random keywords
|
|
|
|
OR cmd LIKE '%ransom%'
|
|
|
|
-- Reverse shells
|
|
|
|
OR cmd LIKE '%/dev/tcp/%'
|
|
|
|
OR cmd LIKE '%/dev/udp/%'
|
|
|
|
OR cmd LIKE '%fsockopen%'
|
|
|
|
OR cmd LIKE '%openssl%quiet%'
|
|
|
|
OR cmd LIKE '%pty.spawn%'
|
2022-11-17 12:20:19 +00:00
|
|
|
OR (
|
|
|
|
cmd LIKE '%sh -i'
|
|
|
|
AND NOT parent_name IN ('sh', 'java')
|
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
OR cmd LIKE '%socat%'
|
|
|
|
OR cmd LIKE '%SOCK_STREAM%'
|
2022-12-19 23:06:06 +00:00
|
|
|
OR INSTR(cmd, '%Socket.%') > 0
|
2022-09-24 15:12:23 +00:00
|
|
|
) -- Things that could reasonably happen at boot.
|
|
|
|
AND NOT (
|
|
|
|
p.path IN ('/usr/bin/kmod', '/bin/kmod')
|
|
|
|
AND parent_path = '/usr/lib/systemd/systemd'
|
|
|
|
AND parent_cmd = '/sbin/init'
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
p.path IN ('/usr/bin/kmod', '/bin/kmod')
|
2022-10-17 23:06:17 +00:00
|
|
|
AND parent_name IN (
|
|
|
|
'firewalld',
|
|
|
|
'mkinitramfs',
|
|
|
|
'systemd',
|
|
|
|
'dockerd',
|
|
|
|
'kube-proxy'
|
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
p.path IN ('/usr/bin/kmod', '/bin/kmod')
|
|
|
|
AND uptime.total_seconds < 15
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
p.path = '/usr/bin/mkfifo'
|
|
|
|
AND cmd LIKE '%/org.gpgtools.log.%/fifo'
|
|
|
|
)
|
|
|
|
AND NOT cmd LIKE '%modprobe -va%'
|
|
|
|
AND NOT cmd LIKE 'modprobe -ab%'
|
|
|
|
AND NOT cmd LIKE '%modprobe overlay'
|
|
|
|
AND NOT cmd LIKE '%modprobe aufs'
|
2022-11-03 15:51:54 +00:00
|
|
|
AND NOT cmd LIKE 'modprobe --all%'
|
2022-10-17 23:06:17 +00:00
|
|
|
AND NOT cmd IN ('lsmod')
|
2022-11-16 16:18:45 +00:00
|
|
|
-- Invalid command from someones tmux environment
|
|
|
|
AND NOT cmd LIKE 'pkill -f cut -c3%'
|
2022-11-18 15:27:43 +00:00
|
|
|
AND NOT cmd LIKE 'dirname %history'
|
2022-11-28 21:06:07 +00:00
|
|
|
AND NOT cmd LIKE 'tail /%history'
|
2022-12-02 16:20:18 +00:00
|
|
|
AND NOT cmd LIKE 'find . -executable -type f -name %grep -l GNU Libtool%touch -r%'
|
2023-01-06 15:18:19 +00:00
|
|
|
|
|
|
|
AND NOT basename IN ('cc1')
|