Unexpected Executable Permissions
osquery
Find processes running that are tied to binaries with unsual permissions. Namely, 0777.
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 running that are tied to binaries with unsual permissions. Namely, 0777.
--
-- references:
-- * https://attack.mitre.org/techniques/T1222/
--
-- false positives:
-- * poorly written software
--
-- platform: posix
-- tags: persistent filesystem state
SELECT
mode,
f.uid,
f.
f.gid,
f.ctime,-- 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_cgroup,
p0.cgroup_path 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 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 file f ON p0.path = f.path
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
LEFT JOIN processes p1 ON p0.parent = p1.pid
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
mode NOT IN (
f.'0500',
'0551',
'0544',
'0555',
'0711',
'0750',
'0755',
'0775',
'0744',
'6755',
'0700',
'2755',
'4511',
'4555',
'4755'
)-- Vendors who are very relaxed about permissions
AND NOT (
IN (
f.path '/Applications/Camera Settings.app/Contents/MacOS/LogitechCamera',
'/Applications/motionVFX/Plugins/mUtility.app/Contents/PlugIns/mUtility XPC Service.pluginkit/Contents/MacOS/mUtility XPC Service',
'/Library/Application Support/Logitech/com.logitech.vc.LogiVCCoreService/LogiVCCoreService.app/Contents/MacOS/LogiVCCoreService'
)AND f.mode = '0777'
AND f.uid > 500
)AND NOT (
= '/Applications/EA app.app/Contents/Applications/EABackgroundService.app/Contents/MacOS/EABackgroundService'
f.path AND f.mode = '0777'
AND f.uid = 0
)AND NOT (
LIKE '/Users/%/.local/bin/%'
f.path AND f.mode = '0777'
AND f.uid > 500
)AND NOT (
LIKE '/Users/%/Library/Application Support/Code/User/globalStorage/grafana.vscode-jsonnet/bin/jsonnet-language-server'
f.path AND f.mode = '0777'
AND f.uid > 500
)AND NOT (
LIKE '/Users/%/.vscode/extensions/sumneko.lua-%-darwin-arm64/server/bin/lua-language-server'
f.path AND f.mode = '0777'
AND f.uid > 500
)AND NOT (
LIKE '/Users/%/Library/Application Support/Zwift/ZwiftApp%'
f.path AND f.mode = '0777'
AND f.uid > 500
)AND NOT (
= '/usr/bin/sudo'
f.path AND f.mode = '4111'
AND f.uid = 0
)AND NOT (
LIKE '/home/%/.local/share/JetBrains/Toolbox/bin/jetbrains-toolbox'
f.path AND f.mode = '0744'
)AND NOT (
LIKE '/Users/%/Applications (Parallels)/%.app/Contents/MacOS/WinAppHelper'
f.path AND f.mode = '0777'
)AND NOT (
LIKE '/opt/homebrew/Cellar/socket_vmnet/%/bin/socket_vmnet'
f.path AND f.mode = '1555'
)AND NOT (
LIKE '/opt/homebrew/Cellar/dnsmasq/%/sbin/dnsmasq'
f.path AND f.mode = '1555'
)AND NOT (
LIKE '/Users/%/Library/Application Support/com.raycast.macos/NodeJS/runtime/%/bin/node'
f.path AND f.mode = '0754'
)AND NOT (
LIKE '%/Elastic/Agent/data/elastic-agent%/elastic-agent'
f.path AND f.mode = '0770'
)AND NOT (
= '/Library/Bitdefender/AVP/product/bin/EndpointSecurityforMac.app/Contents/MacOS/EndpointSecurityforMac'
f.path AND f.mode = '0655'
)AND NOT (
= 'ShortcutDroplet'
p0.name AND f.mode = '0751'
)AND NOT (
= '/home/%/.local/share/AppImage/ZenBrowser.AppImage'
f.path AND f.mode = '0600'
)
tags: SStagSS