← Security lab: audit a Pi with Kali

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.

You have a list of findings. In what order, and how, do you fix them?

Now you are the administrator. For each finding there is a fix: stop what is not needed, upgrade what is old, change the ssh settings, and filter the rest with the firewall. This lesson starts on the target itself, as admin. The commands are the same ones used on any Linux server: systemctl, apt, tee and ufw.

How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

Stop the service

You stop the telnet service on the target. What happens to port 23?

TryTry it on the board and compare the result with your prediction.

Try: close two doors

Was your prediction right?

Try it yourselfYour edits are saved in this browser.

Stop the two services that are findings at any version: telnet and vsftpd. Use sudo systemctl stop.

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: Four fixes, four jobs

Worked exampleBefore each step, say what you think comes next.
  1. sudo systemctl stop telnet\text{sudo systemctl stop telnet}close the door (add disable to keep it off).

Now try it yourself.

Which fix handles 'OpenSSH 7.2 is old'?

Sam fixes Apache. Click the line where it first goes wrong.

In sshd_config, what does PermitRootLogin no change?

ModifyChange the problem on purpose and see what happens.

Vary: change one thing

Try it yourselfYour edits are saved in this browser.

Upgrade the old software: update the lists, then upgrade.

Use the board. This ticks when you get there.

Turn off password login and root login for ssh, and make ssh read the new settings.

Use the board. This ticks when you get there.

Use the firewall so only ssh (22) and web (80) can be reached: allow 22, allow 80, then enable.

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Practise

Why must you restart ssh after editing sshd_config?

The firewall allows port 80. Apache behind it is old. Is the finding fixed?

Review: 14 failures in two minutes for root. Which fix helps most?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Harden it

Then: a fix is not proved until you scan again. That is the challenge.

Try it yourselfYour edits are saved in this browser.
Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

Four findings: telnet and ftp, old versions, ssh password and root login.

Another hint

Stop the two services; sudo apt update and upgrade; write the ssh settings.

Another hint

Then sudo systemctl restart ssh so the new settings apply.

Harden the target: no telnet or ftp open, nothing old, and no password or root login over ssh.

Use the board. This ticks when you get there.

Now you can
Next lesson6. Challenge: audit, fix and prove itA real audit is a cycle: scan to find, fix, then scan again to prove the fix worked, and write down what you did. Your report is the before and after scans, each finding with its fix, and an honest note on what a scan cannot see.
For teachers

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. About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

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.

The hard part (on purpose)

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

When students get stuck

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.

Where it leads

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

What each step is for