Lesson 06 · 45 minutes
Collect evidence from your own machine and seal it in a manifest
- Say what makes a record good audit evidence
- Collect a user list and an administrator list from your own machine with a script
- Seal evidence in a manifest and detect a file that changed or went stale
The lab folder as it stands after this lesson. Unzip it in ~/krlab.
More
The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.
Scenario
Jonas, the auditor of the school network, comes back to Brindle Books with a list. "Show me who can log in. Show me who is an administrator. Show me the patch state and the backup log." Ben opens a spreadsheet that he typed last spring. Jonas shakes his head: "Who made this, when, from which system? How do I know that nobody changed it since?" A typed list is a claim. You build the thing that Jonas wants: evidence that comes from the system, says where it came from, and cannot change without a trace.
Recall
Lesson 5: which two gaps does the statement of applicability checker look for first?
A risk with a treatment and no control, and an implemented control with no evidence named. An auditor walks the trace from risk to control to evidence, and those are the two places where it breaks.
Lesson 1: what is the fourth thing that an auditor asks about a rule?
"Show me that people follow it." The first three questions (the rule, the approval, the date) are answered by documents. The fourth needs evidence, which this lesson collects.
The idea
Audit evidence is a record that shows a control at work. A policy says what should happen, and evidence shows what did happen. Good evidence answers six questions.
| Question | Good | Weak |
|---|---|---|
| What does it show? | The accounts that can log in | "Access is fine" |
| From which system? | Read from the system itself | Retyped from memory |
| Who collected it? | A named person | Nobody knows |
| When? | A date, and recent | Undated, or last year |
| Is it complete? | The whole list, or a stated sample | A hand-picked part |
| Is it unchanged? | A hash recorded at collection | An editable file |
"Sampled" needs a word. An auditor cannot read everything, so they test a sample: some rows, chosen by a rule that they control (lesson 11). Your job is to hand over the whole population, so that the auditor can draw the sample. If you choose the rows, you choose the result.
The last row uses an idea from the course "Security operations basics" (lesson 12): you seal a file by writing its SHA-256 hash into a list, a manifest. If one byte changes later, the hash no longer matches. There the sealed files were the logs of an incident. Here they are the proof that your controls work, and the manifest also records the control, the source, the collector and the date.
- Server → Collect script: the script reads, nobody retypes
- Collect script → Evidence file: writes what, which system, who
- Evidence file → Manifest: seal with the date and the hash
- Manifest → Auditor: verify: exists, unchanged, fresh
- Evidence file → Auditor: draws a sample and tests it
A hash proves that a file did not change after sealing. It does not prove that the content was true when it was collected. That is why the source matters: a script that reads the system is harder to bend than a person with a spreadsheet.
Worked example
Work in ~/krlab/security-governance. Two pieces of evidence come from your own machine: the accounts that can log in, and the members of the administrator groups. Reading them needs no special rights. The rules of sudo in /etc/sudoers are readable only by the administrator, so an auditor asks the administrator to export them, and this lab leaves them out.
1. Save the two sample exports
Brindle Books is invented, so its patch report and its backup log cannot come from your machine. The lesson supplies them as fixed files, as Ben would export them from his tools. Make the folder with mkdir -p samples.
samples/patch-state.csv
host,owner,last_patched,pending_security
web-1,Dev,2026-11-12,0
db-1,Ben,2026-11-12,0
laptop-asha,Ben,2026-11-03,1
laptop-ben,Ben,2026-11-15,0
laptop-carys,Ben,2026-10-28,2
laptop-efe,Ben,2026-09-30,5
scanner-1,Hal,2026-06-10,9
scanner-2,Hal,2026-10-25,1samples/backup.log
2026-11-14T02:00:09 nightly db-1 OK files=409
2026-11-15T02:00:11 nightly db-1 OK files=409
2026-11-16T02:00:10 nightly db-1 FAILED disk full
2026-11-17T02:00:12 nightly db-1 OK files=411
2026-11-18T02:00:09 nightly db-1 OK files=411
2026-11-19T02:00:10 nightly db-1 OK files=412
2026-11-20T02:00:11 nightly db-1 OK files=4122. Write the evidence plan
The evidence plan lists every file that the statement of applicability names as evidence, with its control, its source and the person who collects it. Four of the files come in later lessons.
evidence_plan.csv
file,control,source,collected_by
policies/index.csv,C01,Document register in the policy folder,Carys
assets.csv,C02,Asset inventory,Ben
access_decisions.csv,C03,Access review decisions,Carys
evidence/users.txt,C04,Login accounts read from the machine,Ben
evidence/admins.txt,C05,Administrator groups read from the machine,Ben
evidence/backup.log,C06,Log of the nightly backup job on db-1,Ben
restore_test.json,C06,Restore test record,Ben
evidence/patch-state.csv,C07,Patch report of the device management tool,Ben
changes.csv,C08,Change log,Dev
suppliers.csv,C09,Supplier register,Efe3. Write the evidence tool
The tool has three commands. collect reads your machine. pwd.getpwall() returns every account, and grp.getgrall() every group with its listed members. An account counts as a login account here when its number (uid) is 0, the administrator root, or between 1000 and 60000, the range that Linux gives to people, and when its shell is a real one. socket.gethostname() gives the name of the machine and getpass.getuser() your user name. shutil.copy copies a file.
seal hashes each file of the plan that exists and writes the manifest with csv.DictWriter, which writes dictionaries as CSV rows. {**r, "collected": ...} makes a copy of the dictionary r with more keys. verify reports a file that is gone, changed, or older than 90 days. The date of sealing is the fixed date of the course unless you give another. seal makes the folder evidence if it is not there.
evidence.py
"""evidence.py: collect evidence from this machine, seal it in a manifest, and verify the manifest.
python3 evidence.py collect write evidence/users.txt and admins.txt, copy the two samples
python3 evidence.py seal [FOLDER] [DATE] hash the files of FOLDER/evidence_plan.csv into evidence/MANIFEST.csv
python3 evidence.py verify [FOLDER] each sealed file must exist, be unchanged and be fresh
"""
import csv
import getpass
import hashlib
import shutil
import socket
import sys
from pathlib import Path
from grc import TODAY, day, finish, load
MAX_AGE = 90 # days after which evidence is stale
FIELDS = ["file", "control", "source", "collected_by", "collected", "sha256"]
def sha256(path):
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
def collect(out=Path("evidence")):
import grp
import pwd
out.mkdir(exist_ok=True)
head = f"# source: {socket.gethostname()}, read by evidence.py\n# collected_by: {getpass.getuser()}\n"
users = [f"{u.pw_name} uid={u.pw_uid} shell={u.pw_shell}" for u in pwd.getpwall()
if (u.pw_uid == 0 or 1000 <= u.pw_uid < 60000) and not u.pw_shell.endswith(("nologin", "false"))]
admins = [f"{g.gr_name}: {' '.join(sorted(g.gr_mem)) or '(no members listed)'}"
for g in grp.getgrall() if g.gr_name in ("sudo", "wheel", "admin")]
(out / "users.txt").write_text(head + "# what: accounts that can log in\n" + "\n".join(sorted(users)) + "\n")
(out / "admins.txt").write_text(head + "# what: administrator groups\n" + "\n".join(sorted(admins)) + "\n")
for name in ("patch-state.csv", "backup.log"):
shutil.copy(Path("samples") / name, out / name)
print("collected: users.txt, admins.txt, patch-state.csv, backup.log")
def seal(folder, when):
folder, rows = Path(folder), []
(folder / "evidence").mkdir(exist_ok=True)
for r in load(folder / "evidence_plan.csv"):
if (folder / r["file"]).is_file():
rows.append({**r, "collected": str(when), "sha256": sha256(folder / r["file"])})
else:
print("not on file yet:", r["file"])
with open(folder / "evidence" / "MANIFEST.csv", "w", newline="", encoding="utf-8") as f:
out = csv.DictWriter(f, FIELDS, lineterminator="\n")
out.writeheader()
out.writerows(rows)
print("sealed", len(rows), "files on", when)
def problems(folder):
folder, found = Path(folder), []
for r in load(folder / "evidence" / "MANIFEST.csv"):
age = (TODAY - day(r["collected"])).days
if not r["source"] or not r["collected_by"]:
found.append(f"{r['file']}: no source or no collector")
if not (folder / r["file"]).is_file():
found.append(f"{r['file']}: sealed, but the file is gone")
elif sha256(folder / r["file"]) != r["sha256"]:
found.append(f"{r['file']}: changed after it was sealed")
if age > MAX_AGE:
found.append(f"{r['file']}: stale, collected {age} days ago")
return found
if __name__ == "__main__":
command, folder = sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else "."
if command == "collect":
collect()
elif command == "seal":
seal(folder, day(sys.argv[3]) if len(sys.argv) > 3 else TODAY)
else:
finish(problems(folder))4. Collect
head -3 shows the first three lines of the user list: the header that says where the data came from. Then read the whole file with cat evidence/users.txt. It lists root and every person with a login on your machine, so yours differs from every other reader's.
python3 evidence.py collect
head -3 evidence/users.txtcollected: users.txt, admins.txt, patch-state.csv, backup.log
# source: krbox, read by evidence.py
# collected_by: you
# what: accounts that can log inRead evidence/admins.txt too. On Debian and Ubuntu the administrator group is sudo, and on Fedora and macOS it is wheel or admin. Would you expect every name in it? An access review asks that question about each one (lesson 7).
5. Seal
python3 evidence.py seal
cut -c1-80 evidence/MANIFEST.csv | head -3not on file yet: access_decisions.csv
not on file yet: restore_test.json
not on file yet: changes.csv
not on file yet: suppliers.csv
sealed 6 files on 2026-11-21
file,control,source,collected_by,collected,sha256
policies/index.csv,C01,Document register in the policy folder,Carys,2026-11-21,f
assets.csv,C02,Asset inventory,Ben,2026-11-21,2c07b7760aa21a25f75b7a18c249a0ac88cut -c1-80 prints the first 80 characters of each line. Six files are sealed, and four are not on file yet. The hashes of users.txt and admins.txt are your own. The hashes of the two sample files are the same for every reader. One line of the manifest answers the questions of the table above.
6. Verify, then change one line
Somebody "tidies" the backup log, so that the failed night looks good. Verify before and after.
python3 evidence.py verify
sed -i 's/FAILED disk full/OK files=409/' evidence/backup.log
python3 evidence.py verifyproblems: 0
PROBLEM evidence/backup.log: changed after it was sealed
problems: 1The edited log reads better than the true one, and without the manifest nobody would know. Put the true log back and verify again.
cp samples/backup.log evidence/backup.log
python3 evidence.py verifyproblems: 0Your turn
Omar of Marlow Physio sent a manifest of three files. Make the folder marlow/evidence, save the files, and verify the folder marlow. There are no steps.
marlow/evidence/record-access.log
2026-11-09T09:14:02 priya opened record 1042 reason=treatment
2026-11-09T09:40:51 rosa opened record 1042 reason=billing
2026-11-09T11:02:17 sam opened record 0977 reason=treatment
2026-11-10T08:30:44 tess opened record 1042 reason=nonemarlow/evidence/updates.csv
computer,last_update,pending
reception-1,2026-11-08,0
reception-2,2026-11-08,0
reception-3,2026-11-08,0marlow/evidence/MANIFEST.csv
file,control,source,collected_by,collected,sha256
evidence/record-access.log,N02,Access log of the booking system,Omar,2026-07-30,8c9ec3d6606dff5653c2a16079a783ef27501fc28bf8f800c9916e62ddae36fb
evidence/updates.csv,N04,Update report of the reception computers,,2026-11-10,ff080b3914cae3c2c2e6c9418c2cfa3335d78d293638c3fcab213520a0b8fc81
evidence/training.csv,N08,Sign-in sheet of the privacy training,Nadia,2026-10-02,73cb3858a687a8494ca3323053016282f3dad39d42cf62ca4e79dda2aac7d9acThen read record-access.log as an auditor would. One line of it is a finding about the control itself, whatever the manifest says. Write down which line, and why.
Check yourself
Ben exports the patch report, deletes the two worst rows "because those machines are being replaced", and seals the file. The manifest verifies. What went wrong?
The evidence is unchanged since sealing and still not complete. The hash protects the file after collection, and cannot know what was removed before. Hand over the whole population and explain the two machines in a note. An auditor who finds a trimmed list will trust nothing else.
Why does the manifest record the source of each file?
The source says how far the evidence is from the system. "Read from the machine by a script" is strong. "Typed by the administrator" is weak, because a person can err or flatter. The auditor uses the source to decide how much to rely on the file, and to collect it again if needed.
Why is evidence that is 114 days old a problem, when the file itself is unchanged?
Evidence shows the state of a control at one time. A user list from the summer says nothing about who can log in today. The limit of 90 days is the rule of this course. A real programme sets a limit for each control: a daily backup needs fresher proof than a yearly policy review.
Why should you hand the auditor the whole list and not a sample that you chose?
The person who chooses the rows controls the result. An auditor draws the sample from the full population by their own rule, so that every row had a chance to be picked. A sample chosen by the audited team is not independent evidence.
Field notes
- Collect by script, on a schedule, with the same command each time. Evidence that depends on one person remembering is missing in the month that they are ill.
- Keep the manifest away from the evidence, or sign it. A person who can edit a file and its manifest can change both. Version control with protected history is a simple fix.
- Evidence holds personal data: user names, access logs. Collect what the control needs and no more, restrict who reads the folder, and delete it when its retention time ends.
- A screenshot is weak evidence: it is hard to search, can be edited, and often lacks the date and the system. If a tool can only show a screen, capture the whole window with the clock and the address, and record who took it.
- The user list of this lesson shows who can log in, not what each person may do. Full evidence for access control also needs the rights on each system, which lesson 7 reviews.