Missing From Disk Linux
osquery
Processes that do not exist on disk, running in osquery’s namespace
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
-- Processes that do not exist on disk, running in osquery's namespace
--
-- false positives:
-- * none observed
--
-- references:
-- * https://attack.mitre.org/techniques/T1070/004/ (Indicator Removal on Host: File Deletion)
--
-- tags: persistent process state
-- platform: linux
SELECT
p.pid,
p.euid,
p.cmdline,
p.path,
p.cgroup_path,
mnt_namespace,
p.cwd,
p.on_disk,
p.state,file.inode,
AS parent_on_disk,
pp.on_disk AS parent_path,
pp.path AS parent_cmdline,
pp.cmdline AS parent_cwd,
pp.cwd AS parent_sha256
ph.sha256 FROM
processes pLEFT JOIN file ON p.path = file.path
LEFT JOIN process_namespaces ON p.pid = process_namespaces.pid
LEFT JOIN processes pp ON p.parent = pp.pid
LEFT JOIN hash ph ON pp.path = ph.path
WHERE
!= 1
p.on_disk AND p.path != ''
-- use osquery as the reference mount namespace
AND mnt_namespace IN (
SELECT DISTINCT
(mnt_namespace)FROM
process_namespacesJOIN processes ON processes.pid = process_namespaces.pid
WHERE
IN ('osqueryi', 'osqueryd')
processes.name
)-- This is truly a missing program, not just one that has been updated with a new binary.
AND file.inode IS NULL
AND p.path != '/bpfilter_umh'
-- Snap packages?
AND p.path NOT LIKE '/home/%/.cache/yay/1password-cli/pkg/1password-cli/usr/bin/op'
AND p.path NOT LIKE '/tmp/.mount_%'
-- Probably just an upgrade
AND p.path NOT LIKE '/opt/%'
AND p.path NOT LIKE '/usr/bin/%'
AND p.path NOT LIKE '/usr/sbin/%'
tags: SStagSS