03 / INTEGRITY AND CONFIGURATION · LESSON 10

Compare a trusted baseline

Distinguish added, changed and missing evidence paths using complete keys.

16 min · learn at your pace

Trust is an input assumption

A baseline is useful only when you know how it was created and protected. Hashing a compromised directory and calling it a baseline does not restore trust. In this exercise the reference manifest is explicitly trusted, and the current manifest describes a new observation.

Compare complete paths as keys and digests as values. A path present only in the current manifest is added. A path present in both with different digests is changed. A path present only in the baseline is missing. Unchanged paths do not need a finding in this report.

Two directions matter

Looking only through current files cannot detect deletions. Keep both key sets and evaluate their union, or use a carefully sorted full comparison. Do not confuse an empty manifest with a missing file: a header-only current manifest means every baseline path is absent from this observation.

The input contract guarantees unique paths and valid lowercase SHA-256 fields. A production importer should validate those properties rather than silently allowing the last duplicate to win. Sort findings by the whole path under LC_ALL=C so spaces and Unicode remain data and repeated reports have stable order. None of these changes alone establishes malicious intent.

Try an example.sh
awk -F '\t' 'NR>1 {printf "%s has digest %.12s…\n",$1,$2}' baseline.tsv
YOUR TURN

Put it into practice.

baseline.tsv and current.tsv contain validated unique path<TAB>sha256 records. Print path<TAB>status for added, changed and missing paths; omit unchanged paths. Sort by full path under LC_ALL=C. Header-only manifests are valid. Paths may contain spaces and Unicode but no tabs/newlines.

See an explained solution
One way to solve it.sh
export LC_ALL=C
printf 'path\tstatus\n'
awk -F '\t' 'FILENAME==ARGV[1] {if(FNR>1) old[$1]=$2;next} FNR>1 {now[$1]=$2}
END {for(p in now) {if(!(p in old)) printf "%s\tadded\n",p;else if(now[p]!=old[p]) printf "%s\tchanged\n",p} for(p in old) if(!(p in now)) printf "%s\tmissing\n",p}
' baseline.tsv current.tsv | sort

The two passes cover additions and deletions independently. Exact path keys retain spaces and Unicode, while the final sort makes report order independent of awk array traversal.