← Security lab: audit a Pi with Kali

What is listening: finding open ports

Every network service listens on a numbered port. A port scan asks each port whether anything answers, and lists what is open and what service is behind it. Open does not mean broken: it means something is listening. Whether that matters depends on what.

The target is plugged in. What is it offering to the network?

A computer can run many services at once, and each listens on its own port, a numbered door. Port 22 is ssh, 80 is web pages, 21 is ftp and 23 is telnet. A port scan knocks on each door and records which ones open. nmap is the standard tool. This is the same idea as Names and addresses in Security and privacy: the address finds the computer, the port picks the service.

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.

What a scan shows

You scan the target with nmap target. What does the scan list?

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

Try: scan the target

Was your prediction right?

Try it yourselfYour edits are saved in this browser.

Scan the target with nmap target. Which ports are open?

Use the board. This ticks when you get there.

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

Worked example: Reading a scan

Worked exampleBefore each step, say what you think comes next.
  1. nmap -sn 10.0.0.0/24\text{nmap -sn 10.0.0.0/24}which computers are on the lab network? (no ports yet)

Now try it yourself.

The scan shows 23/tcp open telnet. What does that tell you?

Sam reads the scan. Click the line where it first goes wrong.

Which port number is ssh, the way administrators log in?

ModifyChange the problem on purpose and see what happens.

Vary: change one thing

Try it yourselfYour edits are saved in this browser.

Scan only the ssh port on the target: nmap -p 22 target.

Use the board. This ticks when you get there.

Find every computer on the lab network with nmap -sn 10.0.0.0/24.

Use the board. This ticks when you get there.

Scan Kali itself: nmap localhost. What is listening?

Use the board. This ticks when you get there.

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

Practise

A scan shows 22/tcp filtered instead of open. What does that mean?

Which port would you expect a web server on?

Review: you find a weakness on the target. What do you do?

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

Keep the evidence

Then: cat scan1.txt to check it saved. You will scan again after the fixes and compare.

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

A scan prints to the screen. How do you keep it?

Another hint

Use > after a command to save its output in a file.

Another hint

nmap target > scan1.txt

Scan the target and save the result in a file called scan1.txt.

Use the board. This ticks when you get there.

Now you can
Next lesson3. Old versions and plain textA scan can also ask each service for its version. Old versions have known problems that have since been fixed, so an old version is a finding. Some services are risky however new they are: telnet sends everything, including passwords, as readable text.
For teachers

Every network service listens on a numbered port. A port scan asks each port whether anything answers, and lists what is open and what service is behind it. Open does not mean broken: it means something is listening. Whether that matters depends on what. About 40 minutes.

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

Students will be able to

Before class

Try the boards yourself.

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: the pretend nmap supports -sn, -sV (next lesson) and -p, and scans only the target, Kali itself and the lab range. It shows open and filtered only. A real nmap has many more options and is very noisy on a real network: that is why the lab is isolated.

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: netstat or ss -tln (run on the target) list its own open ports, the defender's view of the same thing; masscan and others scan faster, with the same permission rules.

Running the lesson

  1. Predict: wrong answers think a scan sees inside.
  2. Try: ask which ports and services the class found.
  3. Worked example: stop at Sam's mistake and ask what open means.
  4. Vary: ask why Kali has nothing open.
  5. Make: ask what a report is without evidence.

The hard part (on purpose)

Open versus broken. Students expect red alarms; a scan only reports what is listening.

When students get stuck

Stretch and support

Stretch: Find out what the 1000 'most common ports' are and why a default scan only checks those.

Support: A card of ports: 21 ftp, 22 ssh, 23 telnet, 80 web.

Where it leads

Links: Security and privacy › Names and addresses; Networks; next: Old versions and plain text.

What each step is for