Unit 2: Reading and checking files · Lesson 5 of 6 · 18 min

Comparing with a baseline

Use diff and cmp to see exactly how a config drifted, and whether two programs are the same file.

mission

You are
You are measuring configuration drift on web01.
Situation
A hardened SSH config was approved in September and saved to /srv/baseline. Nobody knows if the live file still matches.
Goal
List every setting that differs and check one suspicious program against a known one.
Hand in
The number of drifted settings and what the hidden kthreadd program really is.
01

Run a plain diff

learner@root-lab
diff /etc/ssh/sshd_config /srv/baseline/sshd_config.hardened
6,7c6,7
< PermitRootLogin yes
< PasswordAuthentication yes
---
> PermitRootLogin no
> PasswordAuthentication no
11,14c11,14
< MaxAuthTries 10
< LoginGraceTime 2m
< X11Forwarding yes
< AllowTcpForwarding yes
---
> MaxAuthTries 3
> LoginGraceTime 30s
> X11Forwarding no
> AllowTcpForwarding no

you should see < lines come from the first file, > from the second. 6,7c6,7 means lines 6 to 7 changed.

02

Count the drift

learner@root-lab
diff /etc/ssh/sshd_config /srv/baseline/sshd_config.hardened | grep -c '^<'
6

defender tip diff -u prints the unified format used in code reviews and change tickets. Paste it straight into a finding.

03

Compare two programs byte for byte

cmp stays silent when two files are identical and exits with 0. Matching hashes prove the same thing.

learner@root-lab
cmp /usr/local/lib/.cache/kthreadd /usr/bin/sleep && echo same
same
sha256sum /usr/local/lib/.cache/kthreadd /usr/bin/sleep
4a193eb6f25eecf27bad523cb8a53ec4d40775eb498f44760b19bfc421cc90aa  /usr/local/lib/.cache/kthreadd
4a193eb6f25eecf27bad523cb8a53ec4d40775eb498f44760b19bfc421cc90aa  /usr/bin/sleep

you should see A program named after a kernel thread is a renamed copy of an ordinary system tool. The processes unit finds out who runs it.

CommandWhat it does
diff a bShow changed lines
diff -u a bUnified format for tickets
cmp a bSilent if identical
sha256sum a bSame hash, same content

What a defender takes away

  1. 1diff shows exactly what drifted.
  2. 2A saved baseline turns a guess into evidence.
  3. 3Identical hashes mean identical files, whatever the names say.

Questions

0 of 3 solved

Answer each one from what you find on your lab machine.

  1. Show hint

    Count the lines that start with < in the diff.

  2. Show hint

    Read the > lines.

  3. Show hint

    cmp or compare sha256sum.