osquery-defense-kit/detection/execution/exotic-commands.sql

111 lines
2.5 KiB
MySQL
Raw Normal View History

2022-10-14 18:19:32 +00:00
-- Pick out exotic processes based on their command-line (state-based)
--
-- false positives:
-- * possible, but none known
--
-- tags: transient process state
-- platform: posix
SELECT
p.path,
p.name,
p.cmdline AS cmd,
p.cwd,
p.cgroup_path,
2022-10-14 18:19:32 +00:00
p.euid,
p.parent,
pp.name AS parent_name,
pp.cmdline AS parent_cmd,
cp.name AS child_name,
cp.cmdline AS child_cmd,
2022-10-14 18:19:32 +00:00
hash.sha256 AS child_sha256,
phash.sha256 AS parent_sha256
FROM
processes p
LEFT JOIN processes pp ON p.parent = pp.pid
LEFT JOIN processes cp ON p.pid = cp.parent
2022-10-14 18:19:32 +00:00
LEFT JOIN hash ON p.path = hash.path
LEFT JOIN hash AS phash ON pp.path = phash.path
2022-10-14 18:19:32 +00:00
WHERE
-- Known attack scripts
2022-12-16 22:37:32 +00:00
p.name IN (
'bitspin',
'bpftool',
'heyoka',
'nstx',
'dnscat2',
'tuns',
'iodine',
'esxcli',
'vim-cmd',
'minerd',
'cpuminer-multi',
'cpuminer',
'httpdns',
'rshell',
'rsh',
'xmrig',
'incbit',
'insmod',
'kmod',
'lushput',
'mkfifo',
'msfvenom',
'nc',
'socat'
2022-12-16 22:37:32 +00:00
)
2022-10-14 18:19:32 +00:00
OR p.name LIKE '%pwn%'
OR p.name LIKE '%xig%'
OR p.name LIKE '%xmr%'
OR cmd LIKE '%bitspin%'
OR cmd LIKE '%lushput%'
OR cmd LIKE '%incbit%'
OR cmd LIKE '%traitor%'
OR cmd LIKE '%msfvenom%'
-- Unusual behaviors
OR cmd LIKE '%ufw disable%'
2022-10-14 18:19:32 +00:00
OR cmd LIKE '%iptables -P % ACCEPT%'
OR cmd LIKE '%iptables -F%'
OR cmd LIKE '%chattr -ia%'
OR cmd LIKE '%chmod 777 %'
OR cmd LIKE '%bpftool%'
OR cmd LIKE '%touch%acmr%'
OR cmd LIKE '%ld.so.preload%'
OR cmd LIKE '%urllib.urlopen%'
OR cmd LIKE '%nohup%tmp%'
OR cmd LIKE '%set visible of front window to false%'
OR cmd LIKE '%chrome%--load-extension%'
2022-10-21 21:45:43 +00:00
OR (
cmd LIKE '%UserKnownHostsFile=/dev/null%'
AND NOT parent_name = 'limactl'
)
2022-10-14 18:19:32 +00:00
-- Crypto miners
OR cmd LIKE '%c3pool%'
2022-10-14 18:19:32 +00:00
OR cmd LIKE '%cryptonight%'
OR cmd LIKE '%f2pool%'
OR cmd LIKE '%hashrate%'
OR cmd LIKE '%hashvault%'
OR cmd LIKE '%minerd%'
OR cmd LIKE '%monero%'
OR cmd LIKE '%nanopool%'
OR cmd LIKE '%nicehash%'
OR cmd LIKE '%stratum%'
-- Random keywords
OR cmd LIKE '%ransom%'
2022-10-14 18:19:32 +00:00
OR cmd LIKE '%malware%'
OR cmd LIKE '%plant%'
-- Reverse shells
OR cmd LIKE '%/dev/tcp/%'
2022-10-14 18:19:32 +00:00
OR cmd LIKE '%/dev/udp/%'
OR cmd LIKE '%fsockopen%'
OR cmd LIKE '%openssl%quiet%'
OR cmd LIKE '%pty.spawn%'
2022-10-21 21:45:43 +00:00
OR (
cmd LIKE '%sh -i'
AND NOT p.path = '/usr/bin/docker'
AND NOT parent_name IN ('sh', 'java', 'containerd-shim')
AND NOT parent_cmd LIKE '%pipenv shell'
2022-10-21 21:45:43 +00:00
)
2022-10-14 18:19:32 +00:00
OR cmd LIKE '%socat%'
OR cmd LIKE '%SOCK_STREAM%'
OR INSTR(cmd, '%Socket.%') > 0