Detect Login Hook in IBM QRadar
Adversaries may use a Login Hook to establish persistence executed upon user logon on macOS. A login hook is a plist file that points to a specific script to execute with root privileges upon user logon. The plist file is located at /Library/Preferences/com.apple.loginwindow.plist and can be modified using the defaults command-line utility. Login hooks (LoginHook key) and logout hooks (LogoutHook key) both require administrator permissions to modify. Adversaries insert a path to a malicious script into the plist, which executes upon the next user login. Only one login and one logout hook can exist on a system at a time. Note: Login hooks were deprecated in macOS 10.11 in favor of Launch Daemons and Launch Agents, but they continue to function on newer systems.
MITRE ATT&CK
- Tactic
- Persistence Privilege Escalation
- Sub-technique
- T1037.002 Login Hook
- Canonical reference
- https://attack.mitre.org/techniques/T1037/002/
QRadar Detection Query
SELECT
DATEFORMAT(starttime, 'YYYY-MM-dd HH:mm:ss') AS EventTime,
sourceip AS SourceIP,
username AS Username,
hostname AS Hostname,
QIDNAME(qid) AS EventName,
LOGSOURCETYPENAME(devicetype) AS LogSourceType,
CATEGORYNAME(category) AS Category,
CASE
WHEN LOWER("UTF8(payload)") LIKE '%loginhook%' THEN 'LoginHook'
WHEN LOWER("UTF8(payload)") LIKE '%logouthook%' THEN 'LogoutHook'
ELSE 'unknown'
END AS HookType,
CASE
WHEN LOWER("UTF8(payload)") LIKE '%defaults%write%loginwindow%' THEN 1
ELSE 0
END AS DefaultsWrite,
CASE
WHEN LOWER("UTF8(payload)") LIKE '%loginwindow.plist%'
AND (LOWER("UTF8(payload)") LIKE '%write%'
OR LOWER("UTF8(payload)") LIKE '%create%'
OR LOWER("UTF8(payload)") LIKE '%truncate%'
OR LOWER("UTF8(payload)") LIKE '%rename%') THEN 1
ELSE 0
END AS PlistDirectWrite,
"UTF8(payload)" AS RawPayload
FROM events
WHERE LOGSOURCETYPENAME(devicetype) IN (
'Apple OS X', 'Syslog', 'Universal DSM', 'macOS Unified Logging'
)
AND (
(LOWER("UTF8(payload)") LIKE '%defaults%' AND LOWER("UTF8(payload)") LIKE '%com.apple.loginwindow%')
OR LOWER("UTF8(payload)") LIKE '%loginhook%'
OR LOWER("UTF8(payload)") LIKE '%logouthook%'
OR (
LOWER("UTF8(payload)") LIKE '%loginwindow.plist%'
AND (
LOWER("UTF8(payload)") LIKE '%write%'
OR LOWER("UTF8(payload)") LIKE '%create%'
OR LOWER("UTF8(payload)") LIKE '%truncate%'
OR LOWER("UTF8(payload)") LIKE '%rename%'
)
)
)
LAST 24 HOURS
ORDER BY starttime DESC Detects macOS Login Hook persistence (T1037.002) in IBM QRadar by querying syslog and macOS unified log events for patterns indicating defaults write to com.apple.loginwindow, presence of LoginHook or LogoutHook strings, or direct write operations against loginwindow.plist. Computes derived fields for hook type classification and suspicion scoring.
Data Sources
Required Tables
False Positives & Tuning
- MDM enrollment scripts using 'defaults write com.apple.loginwindow' to apply legitimate IT policy configurations such as auto-login or screensaver lock settings that happen to appear in the same log stream as hook-related keywords
- Security audit tooling (e.g., osquery, Munki) that reads loginwindow.plist for inventory or compliance checks, generating read-access log entries containing the plist path
- Legitimate administrator shell scripts that invoke 'defaults' against com.apple.loginwindow for unrelated keys (e.g., RetriesUntilHint) whose log entries incidentally match the broad keyword filter
Other platforms for T1037.002
Testing Methodology
Validate this detection against 4 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1Register Malicious Login Hook via defaults write
Expected signal: macOS Unified Log entries for the 'defaults' process with arguments 'write /Library/Preferences/com.apple.loginwindow LoginHook /tmp/argus_login_hook_test.sh'. File modification event for /Library/Preferences/com.apple.loginwindow.plist. Syslog entries showing the defaults command execution. EDR process telemetry showing parent shell spawning defaults binary with loginwindow plist arguments.
- Test 2Register Logout Hook via defaults write
Expected signal: macOS Unified Log entries showing defaults process execution with 'write', 'com.apple.loginwindow', and 'LogoutHook' arguments. File modification timestamp update on /Library/Preferences/com.apple.loginwindow.plist. Syslog entries capturing the command. EDR file write event for the plist file.
- Test 3Direct Plist Modification of loginwindow.plist via PlistBuddy
Expected signal: macOS Unified Log entries for PlistBuddy process (/usr/libexec/PlistBuddy) accessing /Library/Preferences/com.apple.loginwindow.plist. File write/modification event for the plist. EDR file modification telemetry showing PlistBuddy as the modifying process. Note: 'defaults' command will NOT appear in logs for this variant — detections must also cover direct plist modification.
- Test 4Read Existing Login Hook to Identify Persistence (Discovery Phase)
Expected signal: macOS Unified Log entries for 'defaults read' commands targeting com.apple.loginwindow. Multiple defaults process executions in rapid succession (read pattern vs. write pattern). If existing hook script was modified, file modification events for that script. Syslog entries showing defaults process activity.
References (9)
- https://attack.mitre.org/techniques/T1037/002/
- https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CustomLogin.html
- https://developer.apple.com/documentation/devicemanagement/loginwindowscripts
- https://www.sentinelone.com/blog/how-malware-persists-on-macos/
- https://taomm.org/PDFs/vol1/CH%200x02%20Persistence.pdf
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1037.002/T1037.002.md
- https://objective-see.org/blog.html
- https://ss64.com/osx/defaults.html
- https://support.apple.com/en-us/HT203539
Unlock Pro Content
Get the full detection package for T1037.002 including response playbook, investigation guide, and atomic red team tests.