Reverse Shell Socket
osquery
Uncover reverse-shell processes
Description
ODK (osquery-defense-kit) is unique in that the queries are designed to be used as part of a production detection & response pipeline. The detection queries are formulated to return zero rows during normal expected behavior, so that they may be configured to generate alerts when rows are returned.
Query
-- 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
SELECT DISTINCT
(p.pid),parent,
p.
p.name,
p.path,
p.cmdline,
p.cwd,
p.root,uid,
p.
p.gid,
p.start_time,
pos.remote_address,
pos.remote_port,
pos.local_address,
pos.local_port,
pp.cmdline,
pp.pathFROM
process_open_files pofJOIN 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
WHERE
IN ('sh', 'bash', 'perl', 'python')
p.name AND pof.pid IS NULL
AND pos.remote_port > 0
AND NOT (
= '/usr/bin/bash'
p.path AND pp.cmdline LIKE 'pacman -S%'
)
tags: SStagSS