First Run Baseline: State, Preferences, Logs, and Loopback Network
Tuesday morning, and two benches disagree. Your Mac says the training app's feature flag is off. The shared bench says it is on. Same app, same build, same steps. Someone clicked something over lunch and nobody wrote it down, and now every test result from yesterday is suspect: did the behavior change, or did the starting state change? You cannot answer from memory. You answer from a baseline: a complete record of a controlled run, taken from a known state, covering the selected observation surfaces. With that record in hand, the argument ends in one comparison. Without it, the argument never ends.
This module takes that record. You will watch the training app run once and capture all four surfaces it touches: the state file it writes, the preferences it sets, the log event it emits, and the network request it can make. Every later module compares against this page. When a license action changes state.json in module 00.5, you will know exactly what changed because you captured the before picture here.
Open the pack from module 00.2:
Concept: A Baseline Is a Before Picture
A baseline is an observation with a promise attached: this is what the target looked like before anything interesting happened. The promise is what makes later comparisons meaningful. A state file read after a test proves nothing by itself. The same file read before the test and after the test, with nothing else running in between, proves exactly what the test changed. Module 00.1 taught the working loop: observe, hypothesize, validate, record. The baseline is the observe step done properly, with the record built in.
Three ideas make baselines work. The first is known state. A run observed on top of leftovers is not a first run, no matter what you call it. If yesterday's experiment left the feature flag on, today's smoke test inherits it, and every conclusion drawn from today's run is wrong in the same direction. So every baseline starts by clearing what the app wrote before, then proving the slate is clear, exactly the habit module 00.2 drilled. The technique below opens with that clearing. Never skip it because the bench "should be" clean. Check.
The second idea is coverage. One surface lies by omission. The state file says the flag is off, but the log says the toggle ran twice, and the disagreement means something the state file alone would never tell you. This module reads four surfaces because the training app writes four surfaces, and the habit generalizes: on an unknown target you enumerate every home it could write to, then read all of them. A surface you did not check is a place the truth can hide.
The third idea is order. Record starting state before the action. Start a live log observer before triggering the action, then read files and preferences afterward. The walkthrough introduces surfaces with separate controlled runs; the toggle exercise correlates a state change with a live capture. A log from a second run is not evidence of the first run.
Concept: The Four Homes of App Traces
These four surfaces cover this training app's baseline. Other apps may use containers, group containers, caches, databases, Keychain items, or custom paths. Some never open a network connection. Use this as a starting checklist rather than an exhaustive storage model.
The first home is the Application Support folder,
~/Library/Application Support/<name>/. Apple gives every app this
conventional location for working state: files, databases, anything the
app needs to remember between launches. Well-behaved apps keep state
there, which means analysts look there first. The training app keeps
exactly one file there, state.json, six fields of compact JSON.
Later targets will keep more, in more formats, but the address is
not necessarily the same directory. When someone asks "where does this app
keep its state", the Support folder is the first answer, before any
tool runs.
The second home is the preferences system. macOS gives every app a
lightweight settings store called a preferences domain, named after
the app's bundle identifier, here com.macseclabs.trainingapp. Apps
read and write settings through a system daemon named cfprefsd
instead of managing files by hand. That indirection has a consequence
you must learn now: the daemon caches values in memory, so the file
on disk and the daemon's answer can briefly disagree. You read
preferences with defaults, selecting the same domain as the app.
Different suites or in-process caches can produce a different view. You read the backing file, an XML
or binary property list under ~/Library/Preferences/, with
plutil, which sees the bytes on disk. Two paths to one store. When
they agree, the store is healthy. When they differ, either the cache
has not settled or something wrote behind the daemon's back, and
telling those apart is a Phase 09 skill this module starts.
The third surface is Unified Logging. The subsystem identifies a logging domain and the category groups events within it. Event types include Default, Info, Debug, Error, and Fault. Persistence depends on type, logging configuration, retention, and collection conditions. Info and Debug messages are not normally persisted by default; they can be persisted when configuration enables it. Historical queries also need the appropriate inclusion options to show these types. The training app uses Info for actions and Error for probe failures. Capture actions live and separately query recent history, recording what each collector actually saw. An absent historical message is a collection limitation to investigate, not an absence-of-activity verdict.
The fourth home is the loopback interface, the network that never leaves your machine. Traffic to 127.0.0.1 travels down the stack and back up without touching a wire, which keeps this listener off external interfaces. Local processes can still connect, so loopback is not authentication or isolation from other users on the same host. The app's probe button talks to 127.0.0.1 port 8765, and the pack ships a small server for that port. The loopback boundary is what makes this course's network testing safe, and checking which address a listener binds, loopback or every interface, is the first question you ask of any unknown server.
One more surface deserves a mention before the tools arrive: the app window itself. Everything in this module runs headless, with flags instead of clicks, because flags repeat exactly and clicks do not. But on your own bench the app opens a real window, and you should know what it holds. Expect a title, a short description, four buttons, and a monospace status readout showing the same six state fields this module reads from disk. Each button maps to one headless path you will drive below:
| Button | Headless equivalent | Action name in state |
|---|---|---|
| Toggle Feature Flag | --headless-action toggle-feature | toggle-feature |
| Simulate License Check | --headless-action simulate-license-check | simulate-license-check |
| Loopback API Probe | --headless-network-probe | loopback-api-probe |
| Open URL Handler | --headless-open-url 'macsectraining://toggle/' | toggle-feature |
The window and the flags reach the same code. Later phases click the buttons where the GUI is the honest surface. This module drives the flags, because explicit inputs make repeated actions easier to compare.
Tool: The Reading Bench
Seven small tools read the four homes. Each one does a single job, each one ships with the system, and together they form the bench every runtime module in this course stands at. Confirm all four you have not yet met are present:
/usr/bin/defaults /usr/bin/plutil /usr/bin/python3 /usr/sbin/lsof
All present, all in system paths. defaults and plutil live in
/usr/bin beside the user toolkit. lsof lives in /usr/sbin,
the system administration directory, because listing every open file
is a privileged kind of looking. Module 00.1 taught the reflex:
confirm a tool exists before you depend on it. Now meet each tool
with its job, its alternates, and its limits.
cat prints a file raw, bytes as they sit on disk. It leads for
state reads because the first look at evidence must be unprocessed:
no pretty printer between you and the truth. Its alternates trade
rawness for comfort. less pages long files without flooding the
scrollback. TextEdit and Quick Look show the same bytes in a window,
which suits a first glance, but neither leaves a reproducible record
of what you saw. Do not use cat on files that are not text. A
binary property list through cat prints garbage and teaches
nothing; that is plutil territory, below.
python3 -m json.tool pretty-prints JSON for human eyes. It leads
because it ships with the system and changes nothing: same fields,
same values, whitespace added. With --sort-keys it also pins the
key order, which the technique uses to tame an encoder that never
promises positions. The alternate is jq, the dedicated
JSON processor, which queries and reshapes instead of merely
printing; reach for it the day you filter a thousand-line response
instead of reading a six-field state file. Do not use a pretty
printer as evidence of format. The raw cat proves the file is one
line of compact JSON. The pretty print proves only that you can
read it.
defaults reads and writes a selected preferences domain. The training
app uses its standard domain and synchronizes after writing. Different
suites, managed settings, or in-process caches can change what an app
sees compared with your particular query. The alternatives inspect
different parts of that storage path. plutil -p reads the
backing file from disk, bypassing the cache, which is the right
reach the moment you suspect the cache is stale. Xcode's property
list editor draws the same file as a clickable tree, which teaches
plist structure faster the first time. Do not use defaults
immediately after deleting a preference file and expect silence.
Cached values can survive direct file deletion. The reset below uses
defaults delete for this domain, then checks values after the run.
file names the kind of anything, as module 00.1 taught. Kind
routes workflow, so the technique runs it on the state file before
reading a byte: one line that decides whether text tools apply. Do
not skip the check on files you think you know. The First Look
applies inside bigger procedures exactly as it applies cold.
/usr/bin/log is the Unified Logging interface: stream watches
live, show queries collected history. It supports scriptable
predicates but does not expose every system action or private field.
Two practical notes before you touch it. Your shell has its own
log builtin, so call /usr/bin/log by full path or you will
query the wrong thing. And the alternate, Console.app, browses the
same events with point and click filters, which helps while learning
what events look like, but the query behind the clicks stays
invisible, so the finding is hard to reproduce. Do not use stream
when you need history. Include --info or --debug when querying
historical messages of those types, and account for retention and
permissions. A query omitting those switches is not a persistence test.
lsof lists open files, and network sockets count as files. It
leads for the "who holds this port" question because one line
answers it: process, user, address. The alternates go deeper, not
wider. nettop watches live per-process traffic, which suits a busy
unknown binary. tcpdump captures packet contents, which suits the
day the question is what crossed the wire instead of who listened.
Wireshark draws those packets as a GUI conversation, which suits
learning protocol shape. Do not use lsof to learn what was said.
It proves the path exists. Contents belong to packet tools, in
Phase 11.
Technique: The Four-Surface Sweep
Name the procedure so you can repeat it cold on any native target. The Four-Surface Sweep has seven steps and a decision after every step. It survives every app change because it is ordered homes, not ordered commands: clear, run, read the files, read the settings, capture the log, prove the network, then sweep once with the collector. The proof below runs the same sweep against a planted change, so learn the steps here and expect to reuse them there.
Step one, clean slate. The build stays, but the app's footprints go, so this run is the first the system has seen:
Training app support state absent
Close the training app first. The commands move its current-user support state and export its preferences into the named backup directory while retaining the built app. The explicit check confirms the support directory is absent; the next run must then recreate the documented initial values.
Step two, the observed run. Run the smoke test as the baseline:
MacSecTrainingApp smoke test complete statePath=/Users/tester01/Library/Application Support/MacSecTrainingApp/state.json lastAction=headless-smoke-test
Same three lines as module 00.2, now read as a baseline instead of a
smoke signal. The statePath line is your next target. If these
lines ever differ from the module 00.2 shape, stop: the bench is not
in the state this sweep assumes, and every read below inherits the
difference.
Step three, read the state file. List what the run created:
state.json
One file. If the listing ever shows more, or nothing, that is a finding before you read a byte: more means the app wrote beyond its known shape, nothing means the run did not land. Kind first, per the First Look:
/Users/tester01/Library/Application Support/MacSecTrainingApp/state.json: JSON data
JSON data, so text tools apply. Your username appears in your path. Bind its path once, then read it raw:
{"lastAction":"headless-smoke-test","licenseStatus":"unverified","featureFlagEnabled":false,"username":"tester01","launchCount":0,"updatedAt":"2026-10-02T22:23:18Z"}One line of compact JSON, six fields. username names who ran it.
licenseStatus starts unverified and featureFlagEnabled starts
false: the app begins locked down. lastAction records what just
ran. launchCount stays zero because only a full GUI launch
increments it, and this run was headless. updatedAt stamps the
write in UTC. Your username and timestamp will differ; the field
names and the starting values must match exactly, or the run was not
clean. The key order will differ too, run to run: the encoder
promises fields, not positions, so compare names and values, never
slots. That volatility is a genuine Mac fact, and the next frame
tames it.
Compact JSON is honest evidence and poor reading. Pretty-print the same file for your eyes, with keys sorted so the order stays put:
{
"featureFlagEnabled": false,
"lastAction": "headless-smoke-test",
"launchCount": 0,
"licenseStatus": "unverified",
"updatedAt": "2026-10-02T22:23:18Z",
"username": "tester01"
}Same six fields, now alphabetical and scannable. The --sort-keys
flag stabilizes the order the encoder never promised. Timestamps and
usernames still vary, so a sorted result is not byte-identical across runs.
Module 00.5 sorts both sides before diffing for exactly this
reason. This file is the app's memory, and Phase 09 teaches the
full map of where apps are allowed to keep such memory: support
folders, containers, group containers, and caches.
Step four, read the settings both ways. First through the daemon:
{
FeatureFlagEnabled = 0;
LastAction = "headless-smoke-test";
LastUpdatedAt = "2026-10-02T15:47:15Z";
}Three keys, mirroring the run: the flag is off, the last action matches the state file. Compare timestamps from your own single run; the app computes them in separate writes, so a second boundary can produce a small difference. Preferences and state tell the same story from two stores, which is common on macOS and worth checking every time: when they disagree, the disagreement is the finding. Behind the daemon sits a real file. Ask what kind it is:
/Users/tester01/Library/Preferences/com.macseclabs.trainingapp.plist: Apple binary property list
Property lists come in two flavors: XML text you can read directly,
and a binary encoding you cannot. The system writes whichever it
prefers, and this one is binary. Never cat a binary plist; read
it with plutil, which prints either flavor the same way:
{
"FeatureFlagEnabled" => false
"LastAction" => "headless-smoke-test"
"LastUpdatedAt" => "2026-10-02T16:23:58Z"
}Same three keys as defaults showed, in plutil spelling. One
honest wrinkle: these reference timestamps came from separate runs.
Compare your own timestamps as well as keys; mismatched captures
cannot establish single-run correlation. Compare the keys, which agree, not the clocks.
In your own pass, every read in this section shows one stamp: the
moment of the step-two run above. Two tools, two paths to one
store: defaults through the daemon, plutil from the file. When
they agree, the store is healthy. Phase 09 opens this system fully;
for the baseline, record that the domain exists, which flavor its
file uses, and what it holds.
Step five, capture the log live. The training app logs each action
at Info level. Capture them live rather than relying on historical
retention. You capture them with
log stream while the action runs. stream runs until stopped, so
this frame starts it in the background, runs the smoke test under
it, stops it, and the transcript lands in a file:
MacSecTrainingApp smoke test complete statePath=/Users/tester01/Library/Application Support/MacSecTrainingApp/state.json lastAction=headless-smoke-test stream stopped
The smoke lines are familiar; stream stopped confirms the capture
ended. The --predicate filtered the whole system firehose down to
this one sender before anything hit the file. If the smoke lines
never appear here, the stream outlived nothing: check that the
binary path is right before blaming the log system. Read the
transcript:
Filtering the log data using "subsystem == "com.macseclabs.trainingapp"" Timestamp Thread Type Activity PID TTL 2026-10-02 10:47:20.419362-0500 0x4db65 Info 0x0 12553 0 MacSecTrainingApp: [com.macseclabs.trainingapp:app] training_action action=headless-smoke-test feature=false license=unverified
Two preamble lines, then the event. Read it left to right: local
timestamp, thread, Info type, process id, then the payload. The
subsystem and category in brackets identify the sender, and
training_action carries the facts: which action ran, the flag
state, the license state. Two readings to lock in. First, the event
clock is local time while the state file stamps UTC: 10:47:20 at
offset -0500 converts to 15:47:20 UTC. This is a separate reference
capture, not the run stamped 22:23 above. Mixed runs and time zones
complicate shared notes, which
is why module 00.4 stamps everything in UTC. Second, the flag reads
false here because this baseline ran on fresh state. Any run that
flips the flag first will show true in the same position. Log
events inherit the state of the run that produced them, which is
why baselines exist. Your timestamp, thread, and PID will differ;
the payload shape must match.
Step six, prove the network path. The app's probe button talks to 127.0.0.1 port 8765, and you prove that path the way an analyst proves any listener: from the outside in. Before starting the pack's probe server, see what the app reports when nobody listens. The listener check confirms the port is unused. If occupied, identify the process and stop only your own known previous lab server:
MacSecTrainingApp network probe complete networkProbe=failed: Could not connect to the server. lastAction=loopback-api-probe
The failure is the expected result. Nobody holds the port, so the
request fails, and the app says so plainly while still recording the
attempt: lastAction flipped to loopback-api-probe even though
nothing answered. Learn two things from this frame. First, the
app's report names the outcome, never the cause: "could not
connect" is consistent with no server, a wrong port, or a firewall,
and only the listener check below tells those apart. Second, failed
attempts still write state, so a baseline taken around failures
records attempts, not just successes. Keep this shape in mind. It
is what every silent exfiltration failure looks like from the
inside: an error line where a status line should be.
The failure also emits an Error-level message. Compare recent history with the live capture, explicitly including Info messages:
Historical action matches: 4 network_probe_failed error=Could not connect to the server.
The displayed count is one host observation, not a required value. If your query includes action events, retain them: configuration or collection conditions can make Info messages available historically. If it finds none, the live capture still records the action. Check the saved query output for collection or permissions errors before interpreting a zero count. Error messages are normally persisted, but retention is finite. An Info-level API call is not an invisibility guarantee.
Now start the loopback probe server in the background:
probe server pid 13338
Your PID will differ. Verify the listener from the outside with
lsof before trusting it, giving the server a second to bind:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME Python 13338 tester01 4u IPv4 0x602630ebc47a5b3d 0t0 TCP localhost:ultraseek-http (LISTEN)
One line, and it answers three questions. Who holds the port:
Python, your server's PID, running as you. Where it listens:
localhost, the loopback name, so no other machine can reach it.
Had the name read * instead of localhost, the port would face
the whole network, and that is the first thing you check on any
unknown listener. (ultraseek-http is simply the services-database
name for port 8765; the number is what matters.) If this listing
shows nothing, the server did not start: read $RE03_LOGDIR/probe-server.log
for the traceback before rerunning anything. Now trigger the app's
network probe against it:
MacSecTrainingApp network probe complete networkProbe=status: 200, bytes: 51 lastAction=loopback-api-probe
status: 200, bytes: 51 means the request reached the server and a
small JSON answer came back. Compare with the failure frame above:
same action name, same three-line shape, and the middle line is the
whole difference between success and failure. Read the server's side
of the same exchange, then stop it:
probe_server_listening=127.0.0.1:8765 probe_request=true method=GET path=/macsec-training/status?source=gui
Two lines that close the loop: the server listened on loopback, and one GET arrived at the exact status path. Client, listener, and server log all agree, which is what a complete network observation looks like. Phase 02 will find this same path inside the binary as a string, and Phase 11 makes the exchange rigorous with mock servers and breakpoints; the baseline records that the path exists and works.
Step seven, sweep once into the notes report. You just did runtime triage by hand: a run, its state, its preferences, its log, and its network path. Now sweep both views in one shot, static plus runtime, as one shell group writing your notes file. Every stage is a tool this course teaches; the braces gather their output behind a single redirect. It clears app state first, so the embedded state always starts fresh and the report size stays comparable run to run. Run this sweep at the end of any first look:
Report written to /Users/tester01/macseclabs/notes/first-run-evidence.txt
Check what landed and how it is organized:
-rw-r--r-- 1 tester01 staff 6577 Oct 2 20:53 /Users/tester01/macseclabs/notes/first-run-evidence.txt ## Bundle files ## file ## Info.plist ## codesign ## linked libraries ## first strings ## smoke test ## app state
Eight sections, one file. The byte count is not a correctness check: paths, compiler output, strings, and timestamps can change it. Check the section list and inspect each section for successful tool output. The bundle and smoke sections repeat what this module taught by hand. The identity, signature, libraries, and strings sections preview Phases 01 and 02: read them now for shape, and those phases will teach you to produce each one yourself. A beginner saves the file and moves on. A researcher reads it and extracts the next three hypotheses.
Validate the sweep by checking that each step routed the next. The clean slate made the run a first run. The run produced the state the files step read. The state values matched the settings, the settings matched the log payload, and the network path closed its own loop. If any step got skipped, the pass is incomplete, and the gap goes in your notes as a lead, not as a guess.
Proof of Concept: Catch the Teammate's Change
The scenario from the top of this module ends here. Someone used the shared bench over lunch, the flag reads differently on two Macs, and nobody wrote anything down. You will replay that morning in miniature: take a baseline, plant a change the way a teammate's click would, then check the flag transition in three surfaces. This fragment comparison is not a complete diff of all changed fields. Every comparison file lives in a fresh scratch directory, on lab-owned material, with resets limited to the training app's current-user state.
First, a clean baseline and its saved copy:
MacSecTrainingApp smoke test complete statePath=/Users/tester01/Library/Application Support/MacSecTrainingApp/state.json lastAction=headless-smoke-test
The reset line is the same one the technique opens with, the smoke
is the same three lines, and the copy freezes the before picture
where later frames read it back. The binary runs by absolute path
because this proof works from /tmp, not from the pack. Now plant
the change under a live log, the way the technique taught:
MacSecTrainingApp action complete lastAction=toggle-feature licenseStatus=unverified featureFlagEnabled=true statePath=/Users/tester01/Library/Application Support/MacSecTrainingApp/state.json stream stopped
Five lines, and the flag flipped to true: this is the teammate's click, replayed as a headless action. Note the toggle semantics before continuing: run this frame a second time by itself and the flag flips back to false. The proof replays from the top, reset first, which is why the reset line opens the previous frame. Read the two state files against each other:
"featureFlagEnabled":false "featureFlagEnabled":true
Before false, after true: the planted change, isolated to one
field. The grep -o prints only the matching fragment, so key
order and timestamps cannot muddy the comparison. Module 00.5
teaches full diffing; this fragment check is the quick verdict a
baseline exists to give. Confirm the other two surfaces agree:
1 training_action action=toggle-feature feature=true license=unverified
The daemon answers 1, the log payload reads feature=true, and
both agree with the after file. Three surfaces, one story, zero
interpretation required. The closing lines return you to the pack
and move the planted state aside, leaving the bench as the next module
expects it: the scratch directory keeps the record, so
nothing proven is lost.
Both lenses on the proof. The red teamer learns change detection as tradecraft: baseline before the operation, sweep after, and every drift between the two is either authorized work or a finding about the environment. The malware analyst learns the mirror: triage runs the same sweep on detonation, and the surfaces that moved draw the sample's footprint without reading a single instruction. The opening scenario resolves the same way either direction: the flag dispute ends where the before file says it ends.
Practice: Cold Sweep on a Fresh State
Repeat the technique cold, without rereading the steps. From the pack directory:
- Clear the app state, run the smoke test, and read the state file raw. Say the six field names out loud before reading on.
- Read the
LastActionkey alone through the daemon withdefaults readand one key name. Predict the value before you run it. - Capture a live log stream while running
--headless-action toggle-feature. Predict thefeature=value in the payload before you run it, then check the transcript. - Start the probe server, verify the listener, run the network probe, read the server log, and stop the server. Say each step's purpose out loud as you run it.
- Answer in your notes file: if the state file said the flag was on but the log payload said it was off, which would you trust about the latest run, and what would you check next?
Check yourself: the six fields are lastAction, username,
launchCount, licenseStatus, featureFlagEnabled, and updatedAt.
The single-key read answers headless-smoke-test, or
toggle-feature if you ran step three first. The toggle payload
reads feature=true on a fresh state, because the flag starts
false and the toggle flips it. The server answers 200 with 51
bytes, and the transcript holds one GET at the status path. Trust
the file about the latest write: the log event froze its run's
values at fire time, so a later toggle moves the file without
rewriting history. Check lastAction and updatedAt in the file
against the event's action: if the file names a later run, the two
surfaces never disagreed about the same moment.
Finding
You can state the baseline with confidence. A fresh run writes
six-field JSON state under Application Support starting unverified
and unflagged, sets three matching keys in its preferences domain
backed by a binary plist, emits one training_action log event at
Info level capturable live, and completes a loopback GET that
client, listener, and server all confirm. Failures log at error
level and are normally retained for historical queries; Info retention
requires separate checking. The collector report
in your notes folder holds the static half of the same picture.
You proved the sweep catches a planted change across three
surfaces with one fragment check each.
Module 00.4 turns observations like these into structured notes: one file per exercise, raw stays raw, and every claim names the capture that proves it.
This is one free module of many.
Get every module across all ten phases, with working code and the detection engineering to catch each technique.
Get full access