Skip to content

At boot

StartupItems: Legacy macOS Boot Persistence

How /Library/StartupItems and StartupParameters.plist once ran scripts as root at boot, why modern macOS ignores them, and what one on disk still tells you.

MITRE ATT&CK
T1037.005
Tactics
Persistence, Privilege escalation
Runs
At boot
Set up by
root
Locations
  • /Library/StartupItems/*/*
  • /Library/StartupItems/*/StartupParameters.plist
  • /System/Library/StartupItems/*

How it works

StartupItems are how early Mac OS X started services at boot, before launchd. Each item is a folder holding two things:

  • an executable with the same name as the folder, usually a shell script, run as root with the argument start (and stop or restart on other occasions);
  • StartupParameters.plist, with Description, Provides, Requires, Uses and OrderPreference, which let the boot process order items by their dependencies.

A program called SystemStarter read every item in /System/Library/StartupItems (Apple's) and /Library/StartupItems (everyone else's), sorted them and ran them late in boot. Scripts conventionally began with . /etc/rc.common to get helper functions such as RunService, CheckForNetwork and ConsoleMessage, and defined StartService, StopService and RestartService.

The history matters for anyone reading old write-ups:

ReleaseWhat happened
Mac OS X 10.0–10.3StartupItems are the standard boot mechanism
Mac OS X 10.4 Tigerlaunchd arrives; Apple deprecates StartupItems in favour of LaunchDaemons
Later 10.x releasesSystemStarter keeps running third-party items for compatibility
OS X 10.10 YosemiteSystemStarter is removed; StartupItems no longer run

Current macOS still creates both folders, empty, and nothing reads them. A StartupItem on a modern Mac is therefore not active persistence by itself. It is still evidence: someone followed an old playbook, an old product left it behind, or the folder is being used as a hiding place for a payload that something else starts.

Where it lives

PathWhatWho can write it
/System/Library/StartupItems/Apple's items on old releases; empty todayNobody: sealed system volume
/Library/StartupItems/<Name>/<Name>The item's executable, called with startroot
/Library/StartupItems/<Name>/StartupParameters.plistDescription and orderingroot
/etc/rc.commonHelper functions the scripts source (/etc is /private/etc)root

There is no per-user StartupItems folder.

How attackers use it

On releases that still ran them, a StartupItem gave root at every boot with two small files, which is why ATT&CK still lists the technique. Today the realistic cases are an attacker working from outdated guidance, and an attacker using the folder for camouflage.

A classic item. The script starts a payload staged in a hidden folder:

#!/bin/sh
# /Library/StartupItems/SysUpdate/SysUpdate
. /etc/rc.common

StartService ()
{
    /Users/Shared/.sysupdate/agent &
}

StopService ()
{
    return 0
}

RestartService ()
{
    return 0
}

RunService "$1"
<!-- /Library/StartupItems/SysUpdate/StartupParameters.plist -->
<dict>
  <key>Description</key><string>System Update</string>
  <key>Provides</key><array><string>SysUpdate</string></array>
  <key>OrderPreference</key><string>None</string>
</dict>

The folder as a hiding place. Because few tools and fewer people look inside /Library/StartupItems, a payload stored there and started by a LaunchDaemon keeps working on any release:

<key>ProgramArguments</key>
<array>
  <string>/Library/StartupItems/SysUpdate/SysUpdate</string>
  <string>start</string>
</array>
<key>RunAtLoad</key><true/>

Belt and braces. The same payload planted as a StartupItem, an rc script and a launch daemon covers whichever mechanism the target release honours. On a current Mac only the launch daemon fires, but the other two point straight at it.

How to check a host

On a live Mac, list the folders and everything in them:

ls -leO@ /Library/StartupItems /System/Library/StartupItems
find /Library/StartupItems -type f -exec ls -le@ {} +
plutil -p /Library/StartupItems/*/StartupParameters.plist
file /Library/StartupItems/*/*
stat -f '%SB  %Sm  %N' /Library/StartupItems/*/*        # born / modified
pkgutil --file-info /Library/StartupItems/SysUpdate/SysUpdate
codesign -dv --verbose=4 /Library/StartupItems/SysUpdate/SysUpdate   # when it is a binary
grep -rl 'StartupItems' /Library/LaunchDaemons /Library/LaunchAgents

An empty folder is normal. For anything in it: read the script, follow every path it runs, check those programs' signatures, and look for other jobs that start the same files. The last grep finds launch jobs that use the folder as a hiding place; launchctl print system shows whether one is loaded.

Offline, the collection command archives /Library/StartupItems. Read the scripts and plists, compare file times with the installer receipts and the install history, and check whether a launch daemon, login hook or cron job in the same collection runs the same program. macOS Persistence does that cross-check for you, offline.

What macOS Persistence flags

The tool reads every file directly inside a /Library/StartupItems/<Name>/ folder and reports one entry per file, named after the folder, with the first non-comment lines of its content. StartupParameters.plist itself produces no entry.

  • StartupItem (medium): on every item. Current macOS does not run it; the flag says someone put it there.
  • Command and path heuristics over the whole file, for example Runs from a temporary or shared folder and Runs from a hidden folder (both fire on the script above), Downloads and runs code, Reverse or bind shell and Decodes and runs a payload.
  • Not installed by any package (medium): installer receipts are in the collection and none lists the file. macOS ships the folder empty, so any unpackaged file stands out.
  • Differs from package package (medium): a receipt lists the file and its checksum no longer matches.
  • Changed date (low): the file was modified in the 7 days before the newest file in the collection.
  • program also runs from mechanisms (medium): another mechanism, such as the launch daemon above, starts the same file. Here it reads "/Library/StartupItems/SysUpdate/SysUpdate also runs from LaunchDaemons, StartupItems".

Limits: it does not check that the executable is named after its folder (which SystemStarter required), it does not read files in subfolders such as Resources, and a compiled executable is scanned as text, so only readable strings reach the heuristics. It does not verify signatures, and it reads files, not running state.

Cleaning up

  1. Preserve: copy the item folder with ditto (keeps times and extended attributes), hash every file and every program it starts, and save launchctl print system output if a launch job references it.
  2. Unload any job that starts it: sudo launchctl bootout system/com.example.sysupdate, then remove that job's plist.
  3. Remove the item folder and the payloads it points to (here /Users/Shared/.sysupdate).
  4. Search the same collection or Mac for the payload path and hash in other places: launch agents and daemons, rc files, emond rules, cron, login hooks and shell startup files.
  5. Anything that ran did so as root: rotate credentials and keys stored on the Mac, and check for new accounts or sudo rules.

References

See also

On Mac Forensics

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