Set-up · 15 minutes
Set up your lab for Security operations basics
- Create the lab folder of the course
- Understand why the data of this course is the same on every machine
- Prove with a check script that the lab is ready
The lab folder as it stands after this lesson. Unzip it in ~/krlab.
More
The zip holds every file that the course has printed up to here. Type the code yourself first: you learn more.
What you need
- The four courses that come before this one. This course uses what they teach and does not teach it again. From "Linux" (Part 1) you need lessons 4 to 6: search text, pick fields with awk, and join commands with pipes. From "Networking hands-on" you need lessons 2 and 5 (addresses and ports) and, as help, lessons 7 and 8 (DNS and HTTP). Lesson 1 of this course explains the HTTP status codes that it uses. From "Python for security work" you need lessons 2 to 5 and lesson 10: collections, functions, files, JSON, CSV, errors and the log analyser. From "Security fundamentals" you need lesson 6: logging, detection and response.
- Python 3.12 or later. Every program of this course uses the standard library only, so you install no package and you need no virtual environment.
- A Linux terminal, or WSL (Windows Subsystem for Linux) on Windows. The lessons use GNU tools (
sha256sum,sed -i,nl). On macOS, install GNU coreutils and GNU sed (gsed), or use a Linux machine. Nosudo, no network and no account. About 20 MB of disk. - One folder for everything. The page of the course offers a zip with the lab files of each lesson, in a folder for each lesson. The programs of later lessons import the programs of earlier lessons, so they must all be in one folder. After you unzip,
sh kr-lab.sh LESSON ~/krlab/security-operationsbuilds that folder as it stands after a lesson (LESSON is the name of a lesson folder in the zip, for example04-triage-an-alert). The folder holds programs and small files, not the generated logs. Runpython3 gen_logs.py,python3 logparse.py data 2026 events.jsonl,python3 gen_winevents.pyandpython3 win_jsonl.py data/win/export.xml win-events.jsonlagain to make them. Or type the files from the lessons.
This course closes the gap between knowing the basics and working in a security operations team. You read Linux and Windows logs, turn them into alerts, triage the alerts of logs and of an endpoint tool, write and test detections in the Sigma format, decide which ones matter, rank the weaknesses that you must fix first, and run an incident from the first alert to the written report. You do all of it on your own computer, on files that the lessons make for you. Nothing in this course touches a real system, and no machine is attacked: the logs describe invented events at invented companies.
The data is fixed. A seed is the starting number of a random number generator: the same seed gives the same numbers every time. The generator programs of this course use a seed and only the function random(), which Python promises to keep stable. So your files are the same as the files in the lessons, and the numbers that the page asks you for are the same on every machine. Each generator prints a short hash of every file that it writes, so that you can compare. A hash is a fingerprint of a file: if one byte changes, the fingerprint changes (lesson 12 uses this for evidence).
The addresses in the logs come from the three ranges that are reserved for examples in documentation: 192.0.2.0/24 (the invented company), 198.51.100.0/24 and 203.0.113.0/24 (the rest of the internet). The names use example.com. No real person, company or system is in the data.
- Customer → web01: web requests
- Attacker → web01: password guesses over ssh
- ws-alice → web01: staff login
The two AI courses that follow, "Detection and incident response for AI" and "AI for security operations", build on this one. This course teaches no machine learning. It teaches the work that those courses assume you can do by hand.
Set it up
1. Make the lab folder
mkdir -p (make directory, with its parents) creates the folder. cd (change directory) moves you into it. pwd (print working directory) shows where you are.
mkdir -p ~/krlab/security-operations
cd ~/krlab/security-operations
pwd/home/you/krlab/security-operationsEvery lesson works in this one folder. The lessons put logs in a subfolder named data, and the programs that you write stay next to it.
2. Look at your tools
python3 --version prints the version of Python. grep, awk, sort and sha256sum are the Linux tools that the lessons use on text and files: you met the first three in "Linux" Part 1, and sha256sum (it prints the SHA-256 hash of a file) comes with every Linux system.
python3 --version
which grep awk sort sha256sumPython 3.14.4
/usr/bin/grep
/usr/bin/awk
/usr/bin/sort
/usr/bin/sha256sumYour version and your paths may differ. The version must be 3.12 or later.
Check your lab
The script labcheck.py checks six things and prints one line for each: the Python version, the folder, the tools, a fixed seed, a fixed hash and the right to write in the folder. New in it: shutil.which looks for a program on your path, random.Random(7) makes a generator with the seed 7, hashlib.sha256 computes the SHA-256 hash of some bytes, and Path.home() is your home folder.
labcheck.py
"""labcheck.py: prove that the lab of "Security operations basics" works. Standard library only."""
import hashlib
import random
import shutil
import sys
from pathlib import Path
results = []
def line(name, ok, detail):
"""Print one line for one requirement and remember the result."""
results.append(ok)
print(("ok " if ok else "FAIL ") + name.ljust(8) + detail)
v = sys.version_info
line("python", v >= (3, 12), f"{v.major}.{v.minor}.{v.micro}")
folder = Path.home() / "krlab" / "security-operations"
line("folder", folder.is_dir(), str(folder))
missing = [tool for tool in ("grep", "awk", "sort", "sha256sum") if not shutil.which(tool)]
line("tools", not missing, "grep awk sort sha256sum found" if not missing else "missing: " + " ".join(missing))
first = round(random.Random(7).random(), 6)
line("seed", first == 0.323833, f"the generator with seed 7 starts with {first}")
digest = hashlib.sha256(b"kalirange").hexdigest()[:12]
line("hash", digest == "344d71bf784c", f"sha256 of the word kalirange starts with {digest}")
try:
probe = folder / ".probe"
probe.write_text("x")
probe.unlink()
writable = True
except OSError:
writable = False
line("write", writable, "you can write in the lab folder")
print(f"lab ready: {sum(results)} of {len(results)}")
sys.exit(0 if all(results) else 1)python3 labcheck.pyok python 3.14.4
ok folder /home/you/krlab/security-operations
ok tools grep awk sort sha256sum found
ok seed the generator with seed 7 starts with 0.323833
ok hash sha256 of the word kalirange starts with 344d71bf784c
ok write you can write in the lab folder
lab ready: 6 of 6Your Python version can differ. The last line must be the same. Type the last line of your own output.
If it fails
Read the first line that starts with FAIL. Fix that one, then run python3 labcheck.py again. The script ends with exit code 1 when a requirement fails.
| The script says | What it means | What to do |
|---|---|---|
FAIL python | Python is older than 3.12. | Install Python 3.12 or later and run the script with that python3. |
FAIL folder | The folder does not exist, or you made it in another place. | Run mkdir -p ~/krlab/security-operations again. The script looks in your home folder. |
FAIL tools | A Linux tool is missing. | On macOS, sha256sum is called shasum -a 256: install GNU coreutils and GNU sed, or use WSL. |
FAIL seed | Your Python gives other numbers for the seed 7. | This should not happen. Update Python, and run the script again. |
FAIL write | You cannot write in the folder. | Check the owner and the permissions of ~/krlab (Linux Part 1, lesson 10). |
lab ready: 5 of 6 | One requirement failed. | Read the FAIL line above it. |