← Teacher guide

What guessing looks like in the log

A computer records every login attempt. A long run of failures for one account from one address in a short time is someone guessing passwords. Reading the log is the defender's view of an attack, and the fix is to make guessing harder, not to hope it fails.

Security lab: audit a Pi with Kali · Audit · 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: the log on the board is made up for the lesson (14 failures from one address, one success). The pretend admin can read it with sudo; on a real Pi the first account can read it without. The addresses are private lab addresses. This lesson stays on the defender's side: it reads and counts, and does not teach how guessing is done.

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: fail2ban blocks addresses automatically after repeated failures; journalctl -u ssh is the same story on systems that use the journal; a central log server keeps the record safe from the computer being attacked.

With internet: a server on the open internet is guessed at within minutes, all day, by automated scanners. That is why exposing a server raises the stakes (see System admin on a Raspberry Pi).

Running the lesson

  1. Predict: wrong answers treat failure as success of the defence.
  2. Try: ask which user the failures target.
  3. Worked example: stop at Sam and ask what the 'Accepted' line means a week later.
  4. Vary: ask what the single success might be.
  5. Make: ask what number the report should lead with.

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)

Seeing the pattern rather than the lines. Ask what a real person who forgot a password looks like.

When students get stuck

What you will seeA question to askThe fix
Permission denied reading the log.Did you use sudo?sudo grep ... /var/log/auth.log.
fails.txt is empty or missing.Where is your > ?sudo grep -c ... > fails.txt

Answers to the checks

  1. a run of failures: The log shows 14 'Failed password for root' lines in two minutes, all from 10.0.0.9. What does that most likely mean?
    Someone is guessing passwords. One slip is normal; 14 in two minutes from one address is a pattern.
  2. Try: read the log as the admin: You are on the target as admin. Find the failed logins: sudo grep Failed /var/log/auth.log.

    sudo is needed to read the log. grep Failed prints only the failed attempts.
  3. Counting and comparing: Which pair of facts makes a log pattern look like guessing?
    Many fails, one account, one address, fast
    Volume, repetition and speed. Real users do not fail 14 times in two minutes.
  4. Find the mistake: Sam reads the log. Click the line where it first goes wrong.
    line 2
    Line 2: failures are the warning. Someone is trying, and guessing eventually works against weak passwords. Slow it down: stop root login, use keys, limit attempts.
  5. Slowing guessers: Which change makes guessing a password hardest?
    Use keys instead of passwords, and block root
    Turn off password login, use keys, and block root login. No password to guess means nothing to guess. That is the next lesson's fix.
  6. How many failures?: Count the failed logins: sudo grep -c Failed /var/log/auth.log.

    14 failed attempts.
  7. Who got in?: Find the logins that worked: sudo grep Accepted /var/log/auth.log.

    One login worked, by admin from 10.0.0.7.
  8. Which account?: Count only the failures for root: sudo grep -c "Failed password for root" /var/log/auth.log.

    11 of the 14 were guesses at root, the account every computer has.
  9. Why root: Why do guessers try 'root' first?
    Every Linux has it, and it can do everything
    Everyone knows the name, and the account has every right.
  10. Slowing guessers: Which of these slows a guesser down the most?
    Limit attempts and use keys or long passwords
    Make each guess expensive, or make guessing pointless with keys.
  11. Review: plain text: Review: telnet shows version 2.0 (new). Is it a finding?
    Yes: it sends text in the clear
    Plain text at any version.
  12. count and keep it: Save the number of log lines from 10.0.0.9 into a file called fails.txt in your home folder.

    sudo grep -c 10.0.0.9 /var/log/auth.log > fails.txt. The > is yours, the grep is sudo's: the file lives in your own folder so it works.

Solutions

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

Vary: change one thing › How many failures?

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

Vary: change one thing › Who got in?

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

Vary: change one thing › Which account?

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

count and keep it

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

Stretch and support

Stretch: Find out what fail2ban does and what it cannot protect against.

Support: A card of the three grep commands.

Exit ticket

What pattern in a log says someone is guessing passwords?

Many failed logins for one account from one address in a short time.

What each step is for

Where it leads

Links: Security and privacy › Sign-in and permissions; Cyber safety and privacy › Passwords; next: Close the doors.