← Teacher guide

Close the doors: harden the target

Fixing means closing what is not needed, updating what is old and tightening the login, in that order of thought: fewer doors, stronger locks. Each fix does one job and none of them does all of them, so you layer them and then check again.

Security lab: audit a Pi with Kali · Fix · about 40 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 8 min · Worked example 10 min · Vary 10 min · Practise and Make 12 min

Before class

Try the boards yourselves.

The gate (read first). This course teaches security as audit and defence: you scan, read and fix a lab computer your class owns. The pretend Kali and target in the lessons are safe anywhere. The real-lab version is different, so it needs your sign-off before anyone starts: school policy and IT's agreement, a written lab agreement every student signs (lab-rules.txt on the board is a model), and a lab that is cut off from every other network: a Pi running Kali and a second Pi or a virtual machine as the target, joined by one switch or one ethernet cable, with no router and no internet. Download the Kali image and any tools once, at home or at IT's request. Scan only the target named on the lab sheet. This course does not teach breaking into anything: it stops at find, understand and fix. It relaxes the 'defensive only' rule of the other courses only in that the real lab uses real scanning tools on a computer the class owns.

Simplifications: key login is described but not set up on the board (a real lab would also create a key pair with ssh-keygen and copy it with ssh-copy-id before turning passwords off, or you lock yourself out: test in a second session first). The pretend firewall tracks allow <port> and enable only. apt reads a pretend local mirror (a real offline lab uses a mirror such as apt-cacher-ng or a USB bundle of .deb files). Make sure students know the lockout risk from System admin: allow ssh before enabling the firewall.

Real lab, if you run one: Kali Linux has a Raspberry Pi image (Pi 4 or Pi 5; the Pi 5 wants its 27 W supply); flash it with Raspberry Pi Imager or the Kali image instructions and boot it with a screen and keyboard, or ssh in. The target can be a second Pi (an older Raspberry Pi OS with a few extra services) or a purpose-made practice target your IT team approves. Start from the same state every time: re-flash, or snapshot a virtual machine. nmap is already on Kali. Give each pair a printed lab sheet naming the target's address, the one account they may use and what they are allowed to change.

Other options: ufw is the friendly firewall (nftables is what is underneath); unattended-upgrades installs security updates automatically; fail2ban blocks repeated failures.

Running the lesson

  1. Predict: wrong answers think a service can be closed in the firewall alone.
  2. Try: ask which door is now closed.
  3. Worked example: stop at Sam and ask what the firewall protects.
  4. Vary: ask which fix covers which finding.
  5. Make: ask what is left that you did not fix.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Treating one fix as enough. Each fix does one job; the layering is the point.

When students get stuck

What you will seeA question to askThe fix
The ssh settings do not seem to apply.Did you restart ssh?sudo systemctl restart ssh.
A student's config file lost lines.Did you use tee without -a?tee replaces the file: write all the lines you want.

Answers to the checks

  1. stop the service: You stop the telnet service on the target. What happens to port 23?
    No longer open. A port is only open while a service listens, so stopping the service closes the door.
  2. Try: close two doors: Stop the two services that are findings at any version: telnet and vsftpd. Use sudo systemctl stop.

    sudo systemctl stop telnet and sudo systemctl stop vsftpd. Add sudo systemctl disable so they stay off after a reboot.
  3. Four fixes, four jobs: Which fix handles 'OpenSSH 7.2 is old'?
    sudo apt update, then sudo apt upgrade
    Upgrade installs the fixed versions. The lab's apt reads the lab's own mirror.
  4. Find the mistake: Sam fixes Apache. Click the line where it first goes wrong.
    line 3
    Line 3: a firewall decides who can reach the door; the old program behind an allowed door is still old. Upgrade it, or take the service away.
  5. What ssh config does: In sshd_config, what does PermitRootLogin no change?
    root can no longer log in over ssh
    Guessers target root, so the account is not allowed in over ssh at all. Admins log in as themselves and use sudo.
  6. Upgrade: Upgrade the old software: update the lists, then upgrade.

    sudo apt update, then sudo apt upgrade.
  7. Tighten ssh: Turn off password login and root login for ssh, and make ssh read the new settings.

    Write PermitRootLogin no and PasswordAuthentication no into /etc/ssh/sshd_config with tee, then sudo systemctl restart ssh.
  8. Filter: Use the firewall so only ssh (22) and web (80) can be reached: allow 22, allow 80, then enable.

    sudo ufw allow 22, sudo ufw allow 80, sudo ufw enable. Allow first, enable second.
  9. Restart: Why must you restart ssh after editing sshd_config?
    It reads its settings only when it starts
    Services read their config at start (the same as Samba).
  10. Firewall limits: The firewall allows port 80. Apache behind it is old. Is the finding fixed?
    No: the old Apache still answers on 80
    A firewall does not fix what is behind an allowed door: the old program is still reachable on 80, so update it.
  11. Review: guessing: Review: 14 failures in two minutes for root. Which fix helps most?
    No root login over ssh, and key login only
    Take away the prize, or make the lock pointless to guess.
  12. harden it: Harden the target: no telnet or ftp open, nothing old, and no password or root login over ssh.

    Stop telnet and vsftpd; apt update and apt upgrade; tee the ssh settings; restart ssh. Four fixes for four findings.

Solutions

One possible solution for each task. Other correct programs are fine.

Vary: change one thing › Upgrade

Open task: any program that does what the step asks.

Vary: change one thing › Tighten ssh

Open task: any program that does what the step asks.

Vary: change one thing › Filter

Open task: any program that does what the step asks.

harden it

Open task: any program that does what the step asks.

Stretch and support

Stretch: Find out how key login works and what must be done before password login is switched off.

Support: A card pairing each finding with its fix.

Exit ticket

Why is upgrading Apache a better fix than just allowing it through the firewall?

The firewall only filters who reaches the door. The old program behind it is still old.

What each step is for

Where it leads

Links: System admin on a Raspberry Pi (services, ufw, users); next: the audit report.