T1037.002 Google Chronicle · YARA-L

Detect Login Hook in Google Chronicle

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
Technique
T1037 Boot or Logon Initialization Scripts
Sub-technique
T1037.002 Login Hook
Canonical reference
https://attack.mitre.org/techniques/T1037/002/

YARA-L Detection Query

Google Chronicle (YARA-L)
yaral
rule macos_login_hook_persistence_t1037_002 {
  meta:
    author = "Argus Detection Engineering"
    description = "Detects macOS Login Hook persistence via defaults write to loginwindow plist or direct plist modification (T1037.002)"
    severity = "HIGH"
    mitre_attack_tactic = "Persistence"
    mitre_attack_technique = "T1037.002"
    reference = "https://attack.mitre.org/techniques/T1037/002/"
    version = "1.0"

  events:
    (
      $e.metadata.event_type = "PROCESS_LAUNCH" and
      re.regex($e.target.process.file.full_path, `.*\/defaults$`) and
      re.regex($e.target.process.command_line, `com\.apple\.loginwindow`) and
      (
        re.regex($e.target.process.command_line, `LoginHook`) or
        re.regex($e.target.process.command_line, `LogoutHook`)
      )
    )
    or
    (
      $e.metadata.event_type = "FILE_MODIFICATION" and
      $e.target.file.full_path = "/Library/Preferences/com.apple.loginwindow.plist"
    )
    or
    (
      $e.metadata.event_type = "FILE_CREATION" and
      $e.target.file.full_path = "/Library/Preferences/com.apple.loginwindow.plist"
    )

  condition:
    $e
}
high severity high confidence

YARA-L 2.0 rule for Google Chronicle detecting macOS Login Hook persistence (T1037.002). Triggers on three UDM event patterns: PROCESS_LAUNCH of the 'defaults' binary with command-line arguments referencing com.apple.loginwindow and LoginHook/LogoutHook keys, FILE_MODIFICATION of /Library/Preferences/com.apple.loginwindow.plist, and FILE_CREATION of that same plist. Normalizes across Chronicle-ingested macOS endpoint telemetry.

Data Sources

Chronicle macOS endpoint telemetryCrowdStrike Falcon via Chronicle integrationCarbon Black via Chronicle integrationPalo Alto Cortex XDR via Chronicle integration

Required Tables

UDM events (PROCESS_LAUNCH, FILE_MODIFICATION, FILE_CREATION)

False Positives & Tuning

  • Jamf Pro or other MDM platforms executing 'defaults write' against com.apple.loginwindow as part of a configuration profile push or enrollment script that sets unrelated loginwindow keys (e.g., showInputMenu, RetriesUntilHint)
  • Corporate-sanctioned IT scripts that write to loginwindow.plist during system setup or imaging workflows, where the plist path appears in FILE_CREATION events from the restore toolchain
  • macOS system processes (cfprefsd, configd) performing background synchronization of preference domain caches that incidentally touch loginwindow.plist without adversarial intent
Download portable Sigma rule (.yml)

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Unlock Pro Content

Get the full detection package for T1037.002 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections