2022-10-14 18:19:13 +00:00
|
|
|
-- Uncover reverse-shell processes
|
|
|
|
--
|
|
|
|
-- refs:
|
|
|
|
-- * https://www.invicti.com/blog/web-security/understanding-reverse-shells/
|
|
|
|
-- * https://attack.mitre.org/techniques/T1059/ (Command & Scripting Interpreter)
|
|
|
|
--
|
|
|
|
-- false-positives:
|
|
|
|
-- * none known
|
|
|
|
--
|
|
|
|
-- tags: transient process state often
|
|
|
|
-- platform: posix
|
2022-09-24 15:12:23 +00:00
|
|
|
SELECT DISTINCT
|
2022-10-05 20:15:40 +00:00
|
|
|
(p.pid),
|
|
|
|
p.parent,
|
|
|
|
p.name,
|
|
|
|
p.path,
|
|
|
|
p.cmdline,
|
|
|
|
p.cwd,
|
|
|
|
p.root,
|
|
|
|
p.uid,
|
|
|
|
p.gid,
|
|
|
|
p.start_time,
|
|
|
|
pos.remote_address,
|
|
|
|
pos.remote_port,
|
2023-02-08 15:12:44 +00:00
|
|
|
pos.local_address,
|
|
|
|
pos.local_port,
|
2022-10-05 20:15:40 +00:00
|
|
|
pp.cmdline,
|
|
|
|
pp.path
|
2022-10-12 01:53:36 +00:00
|
|
|
FROM
|
|
|
|
process_open_files pof
|
2022-10-05 20:15:40 +00:00
|
|
|
JOIN process_open_sockets pos USING (pid)
|
|
|
|
LEFT JOIN processes p ON pof.pid = p.pid
|
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
|
|
|
LEFT OUTER JOIN process_open_files ON p.pid = process_open_files.pid
|
2022-09-24 15:12:23 +00:00
|
|
|
WHERE
|
2022-10-05 20:15:40 +00:00
|
|
|
p.name IN ('sh', 'bash', 'perl', 'python')
|
|
|
|
AND pof.pid IS NULL
|
|
|
|
AND pos.remote_port > 0
|
2022-10-12 01:53:36 +00:00
|
|
|
AND NOT (
|
2022-10-13 18:59:32 +00:00
|
|
|
p.path = '/usr/bin/bash'
|
|
|
|
AND pp.cmdline LIKE 'pacman -S%'
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|