2022-10-12 01:53:36 +00:00
|
|
|
-- Detects unexpected programs opening files in /dev on Linux
|
|
|
|
--
|
|
|
|
-- references:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1056/001/ (Input Capture: Keylogging)
|
|
|
|
--
|
2022-10-13 13:11:17 +00:00
|
|
|
-- platform: darwin
|
2022-10-14 18:26:49 +00:00
|
|
|
-- tags: persistent state sniffer
|
2022-09-24 15:12:23 +00:00
|
|
|
SELECT
|
|
|
|
pof.pid,
|
|
|
|
pof.path AS device,
|
|
|
|
s.authority,
|
|
|
|
s.identifier,
|
|
|
|
CONCAT (
|
|
|
|
IIF(
|
2022-10-13 18:59:32 +00:00
|
|
|
REGEX_MATCH (pof.path, '(/dev/.*)\d+$', 1) != '',
|
|
|
|
REGEX_MATCH (pof.path, '(/dev/.*)\d+', 1),
|
2022-09-24 15:12:23 +00:00
|
|
|
pof.path
|
|
|
|
),
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-09-24 15:12:23 +00:00
|
|
|
REPLACE(
|
2023-02-02 20:33:25 +00:00
|
|
|
p0.path,
|
|
|
|
RTRIM(p0.path, REPLACE(p0.path, '/', '')),
|
2022-10-13 18:59:32 +00:00
|
|
|
''
|
2022-09-24 15:12:23 +00:00
|
|
|
),
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-09-21 01:56:01 +00:00
|
|
|
s.authority,
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-09-24 15:12:23 +00:00
|
|
|
s.identifier
|
2023-02-01 18:55:55 +00:00
|
|
|
) AS exception_key,
|
|
|
|
-- Child
|
2023-02-09 22:01:29 +00:00
|
|
|
p0.pid AS p0_pid,
|
2023-02-01 18:55:55 +00:00
|
|
|
p0.path AS p0_path,
|
|
|
|
p0.name AS p0_name,
|
|
|
|
p0.cmdline AS p0_cmd,
|
|
|
|
p0.cwd AS p0_cwd,
|
|
|
|
p0.euid AS p0_euid,
|
|
|
|
p0_hash.sha256 AS p0_sha256,
|
|
|
|
-- Parent
|
|
|
|
p0.parent AS p1_pid,
|
|
|
|
p1.path AS p1_path,
|
|
|
|
p1.name AS p1_name,
|
|
|
|
p1_f.mode AS p1_mode,
|
|
|
|
p1.euid AS p1_euid,
|
|
|
|
p1.cmdline AS p1_cmd,
|
|
|
|
p1_hash.sha256 AS p1_sha256,
|
|
|
|
-- Grandparent
|
|
|
|
p1.parent AS p2_pid,
|
|
|
|
p2.name AS p2_name,
|
|
|
|
p2.path AS p2_path,
|
|
|
|
p2.cmdline AS p2_cmd,
|
|
|
|
p2_hash.sha256 AS p2_sha256
|
2022-09-24 15:12:23 +00:00
|
|
|
FROM
|
|
|
|
process_open_files pof
|
2023-02-01 18:55:55 +00:00
|
|
|
LEFT JOIN processes p0 ON pof.pid = p0.pid
|
|
|
|
LEFT JOIN signature s ON p0.path = s.path
|
|
|
|
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
|
|
|
|
LEFT JOIN processes p1 ON p0.parent = p1.pid
|
|
|
|
LEFT JOIN file p1_f ON p1.path = p1_f.path
|
|
|
|
LEFT JOIN hash p1_hash ON p1.path = p1_hash.path
|
|
|
|
LEFT JOIN processes p2 ON p1.parent = p2.pid
|
|
|
|
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
|
2022-09-24 15:12:23 +00:00
|
|
|
WHERE
|
2022-10-13 18:59:32 +00:00
|
|
|
pof.path LIKE '/dev/%'
|
2022-09-24 15:12:23 +00:00
|
|
|
AND pof.path NOT IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/null',
|
|
|
|
'/dev/ptmx',
|
|
|
|
'/dev/random',
|
|
|
|
'/dev/tty',
|
|
|
|
'/dev/urandom'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
2022-10-13 18:59:32 +00:00
|
|
|
AND pof.path NOT LIKE '/dev/ttys%'
|
2022-09-24 15:12:23 +00:00
|
|
|
-- Assume SIP
|
2023-02-01 18:55:55 +00:00
|
|
|
AND p0.path NOT LIKE '/System/%'
|
|
|
|
AND p0.path NOT LIKE '/usr/libexec/%'
|
|
|
|
AND p0.path NOT LIKE '/usr/sbin/%'
|
2022-09-24 15:12:23 +00:00
|
|
|
AND exception_key NOT IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/afsc_type,revisiond,Software Signing,com.apple.revisiond',
|
2024-01-09 00:07:57 +00:00
|
|
|
'/dev/auditpipe,ir_agent,Developer ID Application: Rapid7 LLC (UL6CGN7MAL),ir_agent',
|
2023-10-24 22:01:36 +00:00
|
|
|
'/dev/auditpipe,osqueryd,Developer ID Application: OSQUERY A Series of LF Projects, LLC (3522FA9PXF),io.osquery.agent',
|
2024-01-09 00:07:57 +00:00
|
|
|
'/dev/auditpipe,osqueryd,Developer ID Application: OSQUERY A Series of LF Projects, LLC (3522FA9PXF),osqueryd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/auditsessions,GSSCred,Software Signing,com.apple.GSSCred',
|
|
|
|
'/dev/auditsessions,TouchBarServer,Software Signing,com.apple.touchbarserver',
|
2023-08-15 22:13:06 +00:00
|
|
|
'/dev/auditsessions,authd,Software Signing,com.apple.authd',
|
|
|
|
'/dev/auditsessions,securityd,Software Signing,com.apple.securityd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/autofs,automountd,Software Signing,com.apple.automountd',
|
|
|
|
'/dev/bpf,airportd,Software Signing,com.apple.airport.airportd',
|
2023-09-01 21:34:36 +00:00
|
|
|
'/dev/console,dbeaver,Developer ID Application: DBeaver Corporation (42B6MDKMW8),org.jkiss.dbeaver.core.product',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/console,kernelmanagerd,Software Signing,com.apple.kernelmanagerd',
|
|
|
|
'/dev/console,launchd,Software Signing,com.apple.xpc.launchd',
|
2023-08-15 22:13:06 +00:00
|
|
|
'/dev/console,launchd_sim,Software Signing,com.apple.xpc.launchd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/cu.BLTH,bluetoothd,Software Signing,com.apple.bluetoothd',
|
2023-08-15 22:13:06 +00:00
|
|
|
'/dev/io,ControlCenter,Software Signing,com.apple.controlcenter',
|
|
|
|
'/dev/io,PerfPowerServices,Software Signing,com.apple.PerfPowerServices',
|
|
|
|
'/dev/io,WiFiAgent,Software Signing,com.apple.wifi.WiFiAgent',
|
|
|
|
'/dev/io,WirelessRadioManagerd,Software Signing,com.apple.WirelessRadioManagerd',
|
|
|
|
'/dev/io,airportd,Software Signing,com.apple.airport.airportd',
|
|
|
|
'/dev/io,symptomsd,Software Signing,com.apple.symptomsd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/io8log,ControlCenter,Software Signing,com.apple.controlcenter',
|
|
|
|
'/dev/io8log,PerfPowerServices,Software Signing,com.apple.PerfPowerServices',
|
2023-08-15 22:13:06 +00:00
|
|
|
'/dev/io8log,WiFiAgent,Software Signing,com.apple.wifi.WiFiAgent',
|
|
|
|
'/dev/io8log,WirelessRadioManagerd,Software Signing,com.apple.WirelessRadioManagerd',
|
|
|
|
'/dev/io8log,airportd,Software Signing,com.apple.airport.airportd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/io8log,symptomsd,Software Signing,com.apple.symptomsd',
|
2023-08-15 22:13:06 +00:00
|
|
|
'/dev/io8logmt,airportd,Software Signing,com.apple.airport.airportd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/io8logtemp,ControlCenter,Software Signing,com.apple.controlcenter',
|
|
|
|
'/dev/io8logtemp,PerfPowerServices,Software Signing,com.apple.PerfPowerServices',
|
|
|
|
'/dev/io8logtemp,WiFiAgent,Software Signing,com.apple.wifi.WiFiAgent',
|
|
|
|
'/dev/io8logtemp,WirelessRadioManagerd,Software Signing,com.apple.WirelessRadioManagerd',
|
2023-08-15 22:13:06 +00:00
|
|
|
'/dev/io8logtemp,airportd,Software Signing,com.apple.airport.airportd',
|
|
|
|
'/dev/io8logtemp,symptomsd,Software Signing,com.apple.symptomsd',
|
2023-07-20 14:56:49 +00:00
|
|
|
'/dev/kbfuse,kbfs,Developer ID Application: Keybase, Inc. (99229SGT5K),kbfs',
|
2023-08-15 22:13:06 +00:00
|
|
|
'/dev/kbfuse,keybase-redirector,Developer ID Application: Keybase, Inc. (99229SGT5K),keybase-redirector',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/klog,syslogd,Software Signing,com.apple.syslogd',
|
2023-07-20 14:56:49 +00:00
|
|
|
'/dev/macfuse,gcsfuse,,a.out',
|
2023-02-18 20:02:40 +00:00
|
|
|
'/dev/macfuse,rclone,,a.out',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/oslog,logd,Software Signing,com.apple.logd',
|
2024-01-18 22:15:37 +00:00
|
|
|
'/dev/bpf,BDLDaemon,Developer ID Application: Bitdefender SRL (GUNFMW623Y),com.bitdefender.epsecurity.BDLDaemonApp',
|
2023-07-20 14:56:49 +00:00
|
|
|
'/dev/tty.usbmodem21430,Bazecor Helper (Renderer),,',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/xcpm,PerfPowerServices,Software Signing,com.apple.PerfPowerServices',
|
|
|
|
'/dev/xcpm,systemstats,Software Signing,com.apple.systemstats',
|
|
|
|
'/dev/xcpm,thermald,Software Signing,com.apple.thermald'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
GROUP BY
|
|
|
|
pof.pid
|