Free lesson · Module 1, lesson 8 of 8

The lab in one command: your first alert

Start the portal, the server and the log pipeline with one command, make three failed logins, and watch them become a log line, a search result and your first alert.

Lessons in this module

Lesson notes

For the student

The whole lab starts with one command, and one wrong password travels through it: the portal writes a JSON line, Alloy ships it, Loki stores it, Grafana finds it, a rule counts it, and the inbox shows the alert. That is the job of a SOC in miniature. Work in ~/cybersecurity-foundations. make up copies .env.example to .env the first time; its passwords are harmless local values for containers on your own laptop.

Up and answering

  • make pull: every image, once (about 3 GB); the only step that needs the network
  • make up: the proxy, the portal, the exam server and the log pipeline (Loki, Grafana, Alloy, the alert inbox), started and waited for
  • make ps: seven containers Up; the portal shows 8000/tcp and no port on the laptop, because only the proxy reaches it
  • curl -s localhost:8080/health prints {"status":"ok"}
  • Ports, all on 127.0.0.1: 8080 the portal, 2222 the exam server's SSH, 3000 Grafana, 9095 the alert inbox; Loki is reached only inside the lab, through Grafana

Three wrong passwords

  • for i in 1 2 3; do curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:8080/login -d "username=test.student&password=guess$i"; done prints 401 three times (or use the browser at http://localhost:8080/login)
  • Each try writes two lines: a request line and a login_failed line with "src_ip":"10.10.10.1" and "reason":"unknown_user" (no account test.student exists; a real user with a wrong password says bad_password)
  • 10.10.10.1 is the gateway of the lab's network campus-lab, where your laptop enters it; an address in a log is the sender as that machine saw it

Search and alert

  • Grafana, http://localhost:3000, Explore, data source Loki, last 15 minutes: {job="portal"} |= "login_failed" returns 3 lines
  • A bare |= "login" returns 6 (each try's request line too); search the event's own name, or {job="portal"} | json | event="login_failed"
  • The rule PortalFailedLogins counts login_failed lines of the last 5 minutes, once a minute, and fires when there are more than 2; Grafana sends it to the inbox after 10 seconds. On the recording it reached the inbox 45 seconds after the third failure; up to about 70 seconds is normal, so allow about two minutes before you look for a fault
  • The inbox at http://localhost:9095 keeps its alerts in a small volume, so make down and make up keep them; a restart only costs time

Every day

  • make up, make ps (first, when something is missing), make logs (Ctrl+C stops following), make down (keeps every volume)

Try it

  • make pull, make up, three wrong passwords, find them in Grafana, see PortalFailedLogins in the inbox, then bash labs/m01/check.sh
  • You should see OK portal, OK logs (3 failed sign-ins in the last hour) and OK alert (PortalFailedLogins firing, received ...) with the time it arrived

Every technique in this course is practised only on the lab machines the course gives you, running on your own laptop.

Lesson quiz

Checked in your browser. Nothing is sent or saved.

5 questions

Question 1 · easy

Something in the lab is missing. Which command do you run first?

Question 2 · medium

On a freshly started lab with no other sign-in attempts, you send four wrong passwords for test.student. In Grafana Explore, over the last 15 minutes, {job="portal"} | json | event="login_failed" returns how many lines?

Question 3 · medium

Your own failed sign-in shows "src_ip":"10.10.10.1", not your Wi-Fi address. Why?

Question 4 · medium

Thirty seconds after your third wrong password, the inbox at localhost:9095 is still empty. What do you do?

Question 5 · hard

You send two wrong passwords at 10:00, then one more at 10:07, and nothing else. Does PortalFailedLogins fire?

Setting up: Docker and the lab on an 8 GB laptopThat was the free module. Tell me when the course opens