Unexpected Privilege Escalation_macos
osquery
Find processes that run with a lower effective UID than their parent (state-based)
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
-- Find processes that run with a lower effective UID than their parent (state-based)
--
-- references:
-- * https://attack.mitre.org/techniques/T1548/001/ (Setuid and Setgid)
-- * https://cybersecurity.att.com/blogs/labs-research/shikitega-new-stealthy-malware-targeting-linux
--
-- related:
-- * unexpected-privilege-escalation-events.sql
--
-- tags: transient state process escalation
-- platform: darwin
SELECT
AS p0_auth,
s.authority identifier AS p0_id,
s.uid AS p0_uid,
p0.-- Child
AS p0_pid,
p0.pid AS p0_path,
p0.path AS p0_name,
p0.name AS p0_cmd,
p0.cmdline AS p0_cwd,
p0.cwd AS p0_euid,
p0.euid AS p0_sha256,
p0_hash.sha256 -- Parent
parent AS p1_pid,
p0.AS p1_path,
p1.path AS p1_name,
p1.name mode AS p1_mode,
p1_f.AS p1_euid,
p1.euid AS p1_cmd,
p1.cmdline AS p1_sha256,
p1_hash.sha256 -- Grandparent
parent AS p2_pid,
p1.AS p2_name,
p2.name AS p2_path,
p2.path AS p2_cmd,
p2.cmdline AS p2_sha256
p2_hash.sha256 FROM
processes p0LEFT 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
WHERE
< p0.uid
p0.euid AND p0.path NOT IN (
'',
'/Applications/Parallels Desktop.app/Contents/MacOS/Parallels Service',
'/Applications/VMware Fusion.app/Contents/Library/vmware-vmx',
'/bin/ps',
'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_session_monitor',
'/Library/DropboxHelperTools/Dropbox_u501/dbkextd',
'/usr/bin/login',
'/usr/bin/su',
'/usr/bin/sudo',
'/usr/bin/top',
'/usr/local/bin/doas'
)AND NOT (
LIKE '/var/folders/%/T/CanonOFI_TEMP/Data/Software/Install/UniversalInstaller.app/Contents/Frameworks/UIx.framework/Resources/relay'
p0.path AND s.authority = 'Developer ID Application: Canon Inc. (XE2XNRRXZ5)'
)AND NOT (
= '/Applications/Adguard.app/Contents/MacOS/Adguard'
p0.path AND s.authority = 'Developer ID Application: Adguard Software Limited (TC3Q7MAJXF)'
)
tags: SStagSS