Practice library / Windows, Active Directory and macOS
Workbook · Easy · 3 hours
macOS Fundamentals
macOS architecture, filesystem, security model (SIP, Gatekeeper), and the command line.
On this page 5 sections
macOS runs on many corporate laptops. An engineer who only knows Windows misses part of the fleet and the attacks that target it. This workbook covers the parts of macOS that matter for security work: the layered filesystem and volumes, System Integrity Protection, Gatekeeper, notarisation, code signing, TCC, the keychain, and the unified log. It also walks through LaunchAgents and LaunchDaemons, the main persistence locations that malware uses on a Mac. Built-in command-line tools read all of this, so no extra agent is needed for a first review. The paired Linux forensics lab shows how similar triage looks on another Unix, which makes macOS findings easier to place.
What You'll Learn
- Navigate the macOS filesystem and shell, and name the volumes, folders and file types that matter
- Explain how Gatekeeper, notarisation, code signing, SIP and TCC work together
- Read the signature, entitlements and quarantine flag of an application with built-in tools
- Find and read LaunchAgents and LaunchDaemons, the main persistence location on macOS
- Query the keychain and the unified log without exposing secrets
- Build a short checklist to review a Mac for unwanted persistence
About This Workbook
Many companies give staff a Mac. Security teams must defend them, and most of the knowledge from Windows and Linux does not transfer in full. macOS is a Unix system (it is certified UNIX 03), so the shell and many commands are familiar. But it has its own file layout, its own service manager (launchd), its own secret store (the keychain) and a strong chain of trust that is built on code signatures.
This workbook teaches the defender's view. You learn where things are, how the platform decides what may run, and where an unwanted program can hide.
Setup. Use a Mac that you own, or a Mac that your employer has given you for this training. Use a test user account, not your daily account. Every command here only reads, except the one small exercise in chapter 3, which creates and removes one harmless file. Do not run these commands on a Mac that belongs to another person, or on a company Mac without permission. macOS is not licensed to run on non-Apple hardware, so do not look for a virtual machine on a PC.
If you have no Mac, read the example output. It shows what each command prints. The commands were written for macOS 13 (Ventura) and later. Output on other versions can differ in small ways.
Read Linux for Beginners first if the commands ls, cd, grep and chmod are new to you. This workbook uses them without explanation. For the same topic on the other large platform, read Windows Fundamentals.
Chapter 1 — The Environment
Objectives
- Name the layers of macOS and find the version and the hardware of a Mac
- Read the volume layout and the main folders
- Use the shell, and explain how it differs from Linux
- Describe the app bundle, the package, and the property list
Explanation
Layers. macOS has a kernel called XNU (a mix of Mach and BSD) and a Unix layer called Darwin. On top of that sit system frameworks and the graphical interface. The Unix tools come from BSD, not GNU. This is why some flags differ from Linux: sed -i needs an argument on macOS, ls has no --color, and date takes different options.
Find out what you have. Start every investigation with the version and the hardware.
sw_vers
uname -m
sysctl -n machdep.cpu.brand_stringProductName: macOS
ProductVersion: 14.5
BuildVersion: 23F79
arm64
Apple M2arm64 means Apple silicon. x86_64 means an Intel Mac. The distinction matters: Apple silicon Macs enforce more boot security, and some tools exist only for one architecture.
Volumes. Since macOS 10.15, the system and your data live on two separate APFS volumes. The system volume is read-only and sealed. The data volume is where you and applications write.
diskutil list internal/dev/disk3 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +245.1 GB disk3
Physical Store disk0s2
1: APFS Volume Macintosh HD 11.2 GB disk3s1
2: APFS Snapshot com.apple.os.update-... 11.2 GB disk3s1s1
3: APFS Volume Preboot 5.9 GB disk3s2
4: APFS Volume Recovery 1.1 GB disk3s3
5: APFS Volume Data 98.4 GB disk3s5Macintosh HD is the sealed system. Macintosh HD - Data (shown here as Data) holds /Users, /Applications that you add, and /Library. The two volumes are joined with firmlinks, so the user sees one tree. You cannot write to /System even as root. A change to the system volume must go through a software update.
The main folders.
| Path | Content | Writable by |
|---|---|---|
/System | The operating system | Nobody (sealed) |
/Library | Settings, extensions and agents for all users | Administrators |
~/Library | The same, for one user | That user |
/Applications | Installed apps | Administrators |
/Users | Home folders | Each user |
/usr/bin, /bin | Built-in Unix tools | Nobody (sealed) |
/usr/local or /opt/homebrew | Tools that you install, for example with Homebrew | Administrators |
/private/var, /private/tmp | Logs, caches, temporary files (/var and /tmp link here) | root |
~/Library is hidden in Finder. In the shell, ls -la ~/Library shows it. Much of what a defender needs is in ~/Library and /Library: preferences, caches, support files and launch items.
The shell. The default shell is zsh (since macOS 10.15). Older Macs, and many scripts, use bash 3.2, because Apple does not ship a newer bash for licence reasons.
echo $SHELL
dscl . -read /Users/$USER UserShell/bin/zsh
UserShell: /bin/zshThe first line shows your current shell. The second reads the setting from the directory service. dscl (Directory Service command line) is the macOS replacement for /etc/passwd. A normal Mac does not store users in /etc/passwd. List the local users with dscl . list /Users. The accounts that start with an underscore (for example _www) are service accounts.
zsh reads ~/.zshrc and ~/.zprofile at start. An unwanted program that edits those files runs every time you open a terminal. Keep this in mind for chapter 3.
Bundles and packages. An application is not one file. It is a folder that ends in .app, called a bundle. Finder shows it as one icon.
ls /Applications/Safari.app/Contents
plutil -p /Applications/Safari.app/Contents/Info.plist | head -8Info.plist MacOS Resources _CodeSignature version.plist
{
"BuildMachineOSBuild" => "23F79"
"CFBundleExecutable" => "Safari"
"CFBundleIdentifier" => "com.apple.Safari"
"CFBundleName" => "Safari"
"CFBundlePackageType" => "APPL"
"CFBundleShortVersionString" => "17.5"
"CFBundleVersion" => "19618.2.12.11.6"Info.plist is a property list: the key and value format that macOS uses for settings. The MacOS folder holds the program. _CodeSignature holds the signature that you read in chapter 2. The bundle identifier (com.apple.Safari) is the unique name of the app. Security tools use it more than the file name.
Property lists come in XML or binary form. plutil -p file prints either one in a readable way. plutil -lint file checks that the file is valid. defaults read com.apple.Safari reads the preferences of an app by identifier.
An installer is a .pkg file. pkgutil lists what a package puts on disk, and it can check the signature of a package before you install it.
pkgutil --pkgs | head -3
pkgutil --check-signature ~/Downloads/example.pkgcom.apple.pkg.CLTools_Executables
com.apple.pkg.CLTools_SDK_macOS14
com.apple.pkg.CLTools_macOS_SDK
Package "example.pkg":
Status: signed by a developer certificate issued by Apple (Developer ID Installer)
Certificate Chain:
1. Developer ID Installer: Example Corp (ABCDE12345)pkgutil --payload-files file.pkg lists the files that a package will write, without installing it. Do this before you install an unknown package. A package can also run scripts as root at install time, so the file list is not the full picture.
Useful shell commands that are specific to macOS.
| Command | Use |
|---|---|
open file or open -a Safari | Open a file or app like a double-click |
mdfind "kMDItemDisplayName == 'report*'" | Search with Spotlight from the shell |
mdls file | Show the metadata of a file |
pbcopy, pbpaste | Copy to, and paste from, the clipboard |
caffeinate -t 60 | Keep the Mac awake for 60 seconds |
scutil --get ComputerName | Read the computer name |
networksetup -listallnetworkservices | List network interfaces by service name |
softwareupdate -l | List the available updates |
sudo | Run one command as root (admin users only) |
Worked example
You get a Mac from a colleague, and you must write down its basic state for an asset record. Run five commands and note the output.
sw_vers -productVersion
uname -m
scutil --get ComputerName
fdesetup status
softwareupdate -l 2>&1 | head -514.5
arm64
Finance-Mac-07
FileVault is On.
Software Update ToolThe record reads: macOS 14.5, Apple silicon, name Finance-Mac-07, disk encrypted, check updates. FileVault is the full disk encryption of macOS. A laptop with FileVault is Off. is a finding for any company that holds data on laptops. If softwareupdate -l lists a security update, the Mac is behind on patches.
Write each result and its date into your notes. A Mac that you check once and do not record is a Mac that you must check again.
Practice questions
- A command that works on Linux,
sed -i 's/a/b/' file, fails on a Mac. What is the likely reason? - You run
ls /Systemand trysudo touch /System/test. The write fails. Why does root not succeed? - Where is the preference file for a user setting of the app
com.example.notes, and which command prints it? uname -mprintsx86_64. What do you know about the Mac?- What does
pkgutil --payload-filesnot show about a package?
Answers
- The Mac
sedcomes from BSD. With-i, it needs a backup suffix, even an empty one:sed -i '' 's/a/b/' file. /Systemis on the sealed, read-only system volume. Root cannot write to it. Only a signed system update can change it.- In
~/Library/Preferences/com.example.notes.plist. Print it withdefaults read com.example.notesorplutil -p ~/Library/Preferences/com.example.notes.plist. - It is an Intel Mac, not Apple silicon. It has a different boot security design and runs
x86_64programs without translation. - It does not show the install scripts that run as root. A package can change the system through those scripts, so inspect them too.
Chapter 2 — Security Model
Objectives
- Explain the chain of trust: code signing, Gatekeeper and notarisation
- Read a code signature and the quarantine flag
- Say what SIP and TCC protect, and what they do not protect
- Check the status of the main protections
Explanation
Apple designs macOS so that code must prove where it comes from. Several layers work together. No layer is perfect, and each layer has a known way to fail.
Code signing. A developer signs an app with a certificate that Apple issued. The signature covers every file in the bundle. If one file changes, the signature breaks. Two kinds matter:
- Apple-signed: the operating system itself.
- Developer ID: a third-party developer who is registered with Apple.
A program can also have an ad-hoc signature. That is a signature with no certificate. It proves that the file did not change, and it proves nothing about who made it. Apple silicon requires that all native code has at least an ad-hoc signature, so an ad-hoc signature alone is not a sign of trust.
Read a signature with codesign.
codesign -dv --verbose=4 /Applications/Safari.app 2>&1 | head -12Executable=/Applications/Safari.app/Contents/MacOS/Safari
Identifier=com.apple.Safari
Format=app bundle with Mach-O universal (x86_64 arm64e)
CodeDirectory v=20500 size=... flags=0x0(none) hashes=... location=embedded
Signature size=4442
Authority=Software Signing
Authority=Apple Code Signing Certification Authority
Authority=Apple Root CA
TeamIdentifier=not setThe Authority lines show the certificate chain, from the signer up to the root. For a third-party app, the first line reads Authority=Developer ID Application: Example Corp (ABCDE12345). The text in brackets is the Team ID. It identifies the developer. The same Team ID on two different apps means the same developer signed both.
To check that nothing changed since signing, verify the signature.
codesign --verify --deep --strict --verbose=2 /Applications/Safari.app
echo "exit code: $?"/Applications/Safari.app: valid on disk
/Applications/Safari.app: satisfies its Designated Requirement
exit code: 0An exit code of 0 means the signature is valid. A non-zero exit code means the bundle changed or is not signed. Look at a modified app messages like a sealed resource is missing or invalid. They tell you that a file was added, removed or edited after signing.
Entitlements are permissions that are written into the signature. They say what the app may do, for example read the camera or run without a sandbox. List them.
codesign -d --entitlements :- /Applications/Safari.app 2>/dev/null | head -12An app that asks for many entitlements that do not match its job is suspicious. Entitlements such as com.apple.security.cs.disable-library-validation weaken the protection, and defenders look for them.
Quarantine. When a browser, a mail client or a chat app downloads a file, macOS adds the extended attribute com.apple.quarantine to it. Extended attributes are small labels that are stored beside the file.
xattr -l ~/Downloads/example.dmgcom.apple.quarantine: 0083;6650a1b2;Safari;5C2F1E4B-6A1D-4D3C-9E7A-1B2C3D4E5F60The fields are: flags, a time stamp in hex, the app that downloaded the file, and an ID. A file that has this flag is checked the first time it opens. A file that came by another route, for example from a tool like curl, has no flag, and so no check. That is a known gap. Command-line tools that do not set the flag are one reason that some macOS malware avoids browsers.
Gatekeeper. When a quarantined app opens for the first time, Gatekeeper checks it. The app must be signed with a Developer ID and notarised. Notarisation means the developer sent the app to Apple, Apple scanned it automatically for known malicious content, and Apple recorded a ticket. Notarisation is not a review for quality or safety. It is an automatic scan. Ask Gatekeeper what it would do.
spctl --status
spctl --assess --type execute --verbose=4 /Applications/Safari.appassessments enabled
/Applications/Safari.app: accepted
source=Apple SystemFor a third-party app, the source reads Notarized Developer ID. The output rejected with source=no usable signature means the app has no signature that Gatekeeper accepts. spctl --assess makes a decision without opening the app, so it is safe to use on an unknown file.
SIP. System Integrity Protection (also called "rootless") blocks even root from changing protected parts of the system: /System, /usr (except /usr/local), /bin, /sbin, and the processes of Apple. It also stops a debugger from attaching to Apple processes.
csrutil statusSystem Integrity Protection status: enabled.You can turn SIP off only from the Recovery environment, with physical access. A Mac with SIP disabled is an exception that needs a written reason. If you find it in an audit, it is a finding.
TCC. Transparency, Consent and Control controls an app's access to private data: the camera, the microphone, screen recording, the Desktop and Documents folders, contacts and more. The first time an app asks, the user sees a prompt. The decision is stored in a database. The user database is at ~/Library/Application Support/com.apple.TCC/TCC.db. The system database is at /Library/Application Support/com.apple.TCC/TCC.db.
TCC protects the database itself. To read it, the terminal needs the Full Disk Access permission in System Settings, Privacy & Security. Give this permission to a terminal only on a test Mac, and take it back when you finish. A terminal with Full Disk Access can read almost everything, and so can any script that runs in it.
sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db \
"select service, client, auth_value from access;" | head -4kTCCServiceAppleEvents|com.apple.Terminal|2
kTCCServiceScreenCapture|us.zoom.xos|2
kTCCServiceMicrophone|us.zoom.xos|2
kTCCServiceCamera|us.zoom.xos|2auth_value 2 means allowed. 0 means denied. The service kTCCServiceScreenCapture for an app that has no reason to record the screen is a finding. To remove a decision for one app, run tccutil reset ScreenCapture com.example.app.
Summary of the chain.
| Layer | Question it answers | Blind spot |
|---|---|---|
| Code signature | Has the code changed? Who signed it? | A signature does not mean the code is safe |
| Quarantine and Gatekeeper | Does this download come from a known developer? | Files without the quarantine flag skip the check |
| Notarisation | Did Apple scan this for known malware? | An automatic scan misses new or targeted code |
| SIP | Can anything change the system files? | Does not protect your own data |
| TCC | Can this app read private data? | A user can click Allow, and an admin tool can have it already |
Defence in depth means that you use all layers. A user who clicks through every prompt defeats Gatekeeper and TCC at the same time. Training and device management matter as much as the technology.
Worked example
A user reports that an app called PDF Helper (downloaded from a web page) asks for many permissions. You have the file at ~/Downloads/PDF Helper.app on a test Mac. You do not open it. You inspect it. PDF Helper is an example name: use any app that you downloaded from a web page to your test Mac, and expect different output.
APP="$HOME/Downloads/PDF Helper.app"
xattr -l "$APP"
codesign -dv --verbose=4 "$APP" 2>&1 | grep -E "Authority|TeamIdentifier|Signature"
spctl --assess --type execute --verbose=4 "$APP"com.apple.quarantine: 0083;6650b9d0;Safari;8D1F0C22-...
Signature=adhoc
TeamIdentifier=not set
/Users/test/Downloads/PDF Helper.app: rejectedRead the result line by line.
- The quarantine flag is present, so the browser downloaded it.
Signature=adhocandTeamIdentifier=not setmean no developer certificate. Nobody is accountable for this app.rejectedmeans Gatekeeper would block it on a normal Mac.
The decision: do not open it. Delete the app. Tell the user to ask IT for a PDF tool that is approved. If the user already opened it, move to chapter 3 and look for persistence. Record the file hash, with shasum -a 256 "$APP/Contents/MacOS/"*, so that colleagues can search for the same file.
Never run xattr -d com.apple.quarantine or sudo spctl --master-disable to make an unknown app work. These commands remove the protection that you just used. An administrator who does this on a user's Mac must have a written reason.
Practice questions
- An app shows
Signature=adhoc. Is it safe? Explain. - What does notarisation prove, and what does it not prove?
- A file was downloaded with
curl. Does Gatekeeper check it when it opens? Why does this matter? - You are root and run
rm /usr/bin/ls. It fails withOperation not permitted. Which protection stopped you? kTCCServiceMicrophoneis allowed for an app that edits text. What do you do?
Answers
- No proof of safety. An ad-hoc signature only proves that the file was not changed after it was signed. It names no developer and carries no certificate.
- It proves that the developer sent the app to Apple, and that an automatic scan found no known malicious content at that time. It does not prove that the app is good, that the developer is honest, or that the code is free from defects.
- No.
curldoes not set the quarantine flag, so the first-launch check does not run. This is a known gap, and a reason to treat files from the command line with the same caution as files from a browser. - SIP. It stops even root from changing protected system paths. The system volume is also sealed.
- Ask why. A text editor has no reason to record sound. Remove the permission with
tccutil reset Microphone <bundle id>, check the signature of the app, and report it if the signature is not from a known developer.
Chapter 3 — Administration
Objectives
- Read and explain
launchd, LaunchAgents and LaunchDaemons - List every persistence location and review each one
- Use the unified log to answer a question about the past
- Query the keychain safely and know what it protects
- Describe how a company manages Macs with MDM profiles
Explanation
launchd. launchd is process 1 on macOS. It starts every service and is the replacement for init, cron and systemd in one. A job is described by a property list. There are two kinds.
- A LaunchDaemon runs as root (or another system user) at boot. It has no user interface.
- A LaunchAgent runs as a logged-in user, at login. It can show windows.
Both start at a trigger: at load, at an interval, at a time, when a path changes, or when another service asks. A job can ask to be restarted always (KeepAlive). This is what makes launchd the first place that malware, adware and legitimate software all use to stay on the Mac.
The folders. Each folder tells you who put the job there.
| Folder | Kind | Runs for | Written by |
|---|---|---|---|
/System/Library/LaunchDaemons | Daemon | All | Apple (sealed) |
/System/Library/LaunchAgents | Agent | All users | Apple (sealed) |
/Library/LaunchDaemons | Daemon | All | Administrator or installer |
/Library/LaunchAgents | Agent | All users | Administrator or installer |
~/Library/LaunchAgents | Agent | One user | That user, or any program that runs as that user |
The last row is the important one for an attacker: a normal user can write to ~/Library/LaunchAgents with no admin password. So the same row is the first row that a defender checks. The folders under /System are sealed, so only the three folders under /Library and ~/Library need review.
ls -la ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons/Library/LaunchAgents:
-rw-r--r-- 1 root wheel 589 Mar 12 09:10 com.microsoft.update.agent.plist
-rw-r--r-- 1 root wheel 742 Feb 2 14:22 com.zoom.us.ZoomDaemon.plist
/Library/LaunchDaemons:
-rw-r--r-- 1 root wheel 611 Mar 12 09:10 com.microsoft.autoupdate.helper.plistRead a job. Print a job file with plutil -p.
plutil -p /Library/LaunchDaemons/com.microsoft.autoupdate.helper.plist{
"Label" => "com.microsoft.autoupdate.helper"
"MachServices" => {
"com.microsoft.autoupdate.helper" => 1
}
"ProgramArguments" => [
0 => "/Library/PrivilegedHelperTools/com.microsoft.autoupdate.helper"
]
}Four keys tell most of the story:
Label: the unique name of the job. By convention it is a reverse domain name.ProgramArguments(orProgram): the program and arguments that run. This is the most important key. Check that the file exists, and check its signature withcodesignfrom chapter 2.RunAtLoad: if true, the job starts when it loads.KeepAlive: if true,launchdrestarts the job each time it stops.
Red flags: a label that imitates a known vendor but has a spelling error, a program in /tmp or in a hidden folder (name starts with a dot), a program that is not signed, a plist that was created recently with no matching install, and a ProgramArguments that starts a shell with -c and a long encoded string.
See what is loaded. The plist files on disk are the intent. launchctl shows what is running now.
launchctl list | head -5
launchctl print gui/$(id -u) | grep -c "com\."
launchctl print-disabled gui/$(id -u) | head -3PID Status Label
- 0 com.apple.SafariHistoryServiceAgent
412 0 com.apple.homed
- 0 com.apple.mdworker.sharedA - in the PID column means the job is loaded and not running now. The status is the last exit code. A non-zero status is a failure. launchctl print system/<label> and launchctl print gui/<uid>/<label> show the full detail of one job, including the program path and the arguments.
Compare the disk with the memory. A job that runs but whose plist you cannot find was loaded from another path or is hidden, and needs a deeper look.
Other persistence locations. launchd is not the only one. Review these too.
| Location | Why it matters |
|---|---|
| Login Items (System Settings, General, Login Items) | Apps that start at login |
~/.zshrc, ~/.zprofile, /etc/zshrc | Run each time a terminal opens |
crontab -l and /usr/lib/cron/tabs | Old, but still works |
/Library/StartupItems | Very old method |
| Configuration profiles | Can install settings and certificates (see below) |
/Library/PrivilegedHelperTools | Root helpers that an installer left |
| System and kernel extensions | systemextensionsctl list |
| Browser extensions | Outside the OS, but common |
Since macOS 13, a system database tracks background items and shows them in a notice when one is added. You can dump that database with sudo sfltool dumpbtm. The output is long. Look for items with a developer name that you do not know. Notifications of new background items are a useful early alert, so do not hide them.
systemextensionsctl list
crontab -lThe unified log. macOS keeps one central log for the whole system. It is stored in a compact format, so you must read it with log, not with cat.
log show --last 30m --predicate 'process == "launchd" AND eventMessage CONTAINS "com.example"'
log show --last 1h --predicate 'subsystem == "com.apple.securityd"' --style compact | head -5
log stream --predicate 'eventMessage CONTAINS "Gatekeeper"' --level infoA predicate is a filter. The fields you use most are process, subsystem, category and eventMessage. log show reads the past, and log stream follows live events. log show --last 1d on a busy Mac produces a very large output, so always filter with --predicate and set a short time with --last. Use --info and --debug only when needed, because normal reading hides those levels.
Some useful questions for the log:
- Who used
sudo? Predicate:process == "sudo". - Did an app fail Gatekeeper? Predicate:
eventMessage CONTAINS "assessment"for processsyspolicyd. - Who logged in remotely? Predicate:
process == "sshd".
The keychain. The keychain stores passwords, certificates and keys in an encrypted file. Each user has a login keychain. The system has /Library/Keychains/System.keychain. On a modern Mac, the secrets are protected by the login password and, on Apple silicon, by the Secure Enclave. Apps can store items that other apps cannot read without a prompt.
List the keychains and check the items that exist, without printing the secrets.
security list-keychains
security find-identity -v -p codesigning
security find-generic-password -s "example-service" "/Users/test/Library/Keychains/login.keychain-db"
"/Library/Keychains/System.keychain"
1) 8F3A...C21D "Apple Development: test@example.com (ABCDE12345)"
1 valid identities foundsecurity find-generic-password prints the attributes of an item (name, account, dates), not the password. To print the password, you must add -w. macOS then asks for the user's login password in a prompt.
Do not run security dump-keychain -d or security find-generic-password -w on a Mac that is not yours. They try to read secrets. A prompt appears for each item, and an attacker who has the login password can read all of them. On your own test Mac, read only items that you created for this exercise.
What the keychain does and does not protect:
- It protects stored secrets when the Mac is locked or off, because the data is encrypted.
- It does not protect against an attacker who runs as you while you are logged in and who can answer the prompt, or who knows your password.
- It does not protect secrets that you store in plain text files, shell history or environment variables.
For a defender, the rule is: keep secrets in the keychain or a secret manager. Search for plain-text secrets with a tool that is approved by your company.
Management with MDM. A company manages its Macs with MDM (Mobile Device Management), for example Jamf, Kandji, Intune or Mosyle. Macs enrol, and then receive configuration profiles: files that set a policy, such as "FileVault must be on", "install this certificate" or "allow this app to use the camera". Profiles are why a company Mac behaves differently from a home Mac.
profiles status -type enrollment
sudo profiles listEnrolled via DEP: Yes
MDM enrollment: Yes (User Approved)A defender checks two things: is the Mac enrolled, and what do the profiles allow. A profile can install a root certificate. A rogue profile with a root certificate would let someone read encrypted web traffic, so unknown profiles are a high-priority finding.
Worked example
You must check one test Mac for unwanted persistence. First you create a harmless item, so that you see what a finding looks like. Then you find it with the checklist, and you remove it. Do this on your own test Mac only. The authorised scope is that one account.
Step 1. Create a harmless LaunchAgent. It writes the date to a file each time you log in. The label uses example so that it is easy to find.
cat > ~/Library/LaunchAgents/com.example.training.plist <<'PLIST'
<?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">
<dict>
<key>Label</key><string>com.example.training</string>
<key>ProgramArguments</key>
<array><string>/bin/sh</string><string>-c</string><string>date >> /tmp/training.log</string></array>
<key>RunAtLoad</key><true/>
</dict>
</plist>
PLIST
plutil -lint ~/Library/LaunchAgents/com.example.training.plist
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.training.plist/Users/test/Library/LaunchAgents/com.example.training.plist: OKStep 2. Confirm that it ran.
cat /tmp/training.log
launchctl list | grep com.exampleTue Nov 19 10:02:41 CET 2026
- 0 com.example.trainingStep 3. Now review as a defender. List the folders, sort by time, and look at anything new.
ls -lt ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons | head -8
plutil -p ~/Library/LaunchAgents/com.example.training.plistYou see a new file in the user folder, with /bin/sh -c in its arguments and a write to /tmp. Each of these is a red flag from the list above. In a real case you would also ask: which program created this file, and when? Find the time in the log.
log show --last 10m --predicate 'process == "launchd" AND eventMessage CONTAINS "com.example.training"' | head -3Step 4. Remove it and prove that it is gone.
launchctl bootout gui/$(id -u)/com.example.training
rm ~/Library/LaunchAgents/com.example.training.plist /tmp/training.log
launchctl list | grep -c com.example0The count of 0 shows that the job is no longer loaded. The order matters: first unload the job, then delete the file. If you only delete the file, the job stays loaded until the next reboot.
A real unwanted job usually runs a file that it hid elsewhere, with a name that looks normal. The method does not change: list, read, check the signature of the program, compare with what is loaded, and look at the log.
Practice questions
- You find
~/Library/LaunchAgents/com.apple.softwareupdated.plist, created yesterday. Why is this suspicious, and what is the first check? - What is the difference between a LaunchAgent and a LaunchDaemon, and which can a normal user install?
launchctl listshows a job with PID-and status78. What does it mean?- Write a
log showcommand that showssudoevents from the last two hours. - Why does
security find-generic-password -s examplenot print a password? - A user's Mac has a configuration profile that you do not know. What do you check first?
Answers
- Names that start with
com.apple.are used by Apple, and Apple's jobs are in the sealed/Systemfolders. A user-folder job with an Apple label imitates a trusted name. First check the program inProgramArguments: does it exist, is it signed, and who is the signer? - A LaunchDaemon runs as root at boot and has no interface. A LaunchAgent runs as a user at login. A normal user can install an agent in
~/Library/LaunchAgents. A daemon in/Library/LaunchDaemonsneeds an administrator. - The job is loaded but not running, and its last exit status was 78. A non-zero status means it failed. Read its plist and the log to find out why.
log show --last 2h --predicate 'process == "sudo"'- The command prints the attributes of the item only. You must add
-wto print the password, and macOS then asks for authorisation. - Open the profile and read which payloads it contains. A root certificate or a network setting is the highest risk. Find out who installed it, and compare with the list of profiles that your MDM should send.
Review
Use this checklist for any Mac that you must review. It maps to the three chapters.
| Check | Command | Good result |
|---|---|---|
| Version and patches | sw_vers, softwareupdate -l | Current version, no pending security update |
| Disk encryption | fdesetup status | FileVault is On. |
| SIP | csrutil status | enabled. |
| Gatekeeper | spctl --status | assessments enabled |
| Signature of an unknown app | codesign -dv --verbose=4, spctl --assess | Developer ID, notarised, known Team ID |
| Launch items | ls -la of the three folders, launchctl list | Only items that you can explain |
| Shell start files | ~/.zshrc, ~/.zprofile | No unknown lines |
| Profiles | profiles status -type enrollment | Enrolled, only expected profiles |
Next, practise the same method on another platform in Windows Fundamentals. For the evidence side of a macOS case, read Digital Forensics & Incident Response and use the method of Linux Forensics, because the Unix tools carry over.
Sign in to track progress and send feedback.