Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Lesson 01 · 35 minutes

Score the risks of your own laptop

After this lesson you can
  • Name the asset, threat, vulnerability, likelihood, impact, risk and control in a real situation
  • Write a risk register as a CSV file
  • Sort the register by risk with a Python script
Lab files of this lesson (4)

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. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.

Scenario

A small dental practice has asked you for help. The owner says: "I have a long list of worries and a small budget. Tell me what to fix first." There is no tool for this job yet. You will first build the method on your own laptop, with a table and a short script, and then use it on the list of the practice.

The idea

Seven words carry the whole subject. Learn them as one chain.

One risk, from asset to control
OutsideYour accountsYour defencesAttackerReused passwordEmail accountPassword manager123OutsideYour accountsYour defencesAttackerReused passwordEmail accountPassword manager123
  1. Attacker → Reused password: the threat tries a leaked password
  2. Reused password → Email account: vulnerability (weakness) opens the asset
  3. Password manager → Reused password: the control gives each site its own

The red tile is the attacker. Arrows 1 and 2 are the attack. Arrow 3 is the control that removes the weakness.

WordMeaningExample
AssetSomething of value that you want to protect.Your photos
ThreatSomething that can cause harm.A disk that fails
VulnerabilityA weakness that lets the threat work.No backup exists
LikelihoodHow probable it is that the threat succeeds.3 of 5
ImpactHow bad the harm is if it happens.5 of 5
RiskLikelihood combined with impact.3 x 5 = 15
ControlAn action that lowers likelihood, impact or both.A weekly copy to another disk

A threat without a vulnerability is not a risk. A vulnerability in something of no value is not a risk. A risk needs all three: an asset, a threat and a weakness.

The scale here is 1 (low) to 5 (high), and risk is the product of the two numbers, so it runs from 1 to 25. The numbers are a judgement, not a measurement. Their value is that they force you to compare, and that two people can argue about a number and find a fact.

A control does not remove a risk. It lowers it. What is left is the residual risk, and someone must decide that it is acceptable.

Controls come in kinds, and job interviews use the names:

KindWhat it doesExample
PreventiveStops the eventFull-disk encryption
DetectiveFinds the event, as it happens or afterAn alert on failed logins (lesson 6)
CorrectiveLimits the harm and restoresA restored backup
AdministrativeA rule or a habit of peopleA policy, training
TechnicalSoftware or hardwareA password manager
PhysicalA thing in the real worldA lock and a cable

The first three say when a control acts. The last three say what it is made of. One control has one name from each group: a lock on a door is preventive and physical.

The script of this lesson labels a risk HIGH from 15, MEDIUM from 8 to 14, and LOW below 8.

Most real incidents use one of three routes. Each route has a vulnerability that you can name and a control that lowers it:

RouteHow it worksA control
PhishingA false mail makes a person open a file or give a password.Mail filtering, training, a second factor
Unpatched softwareA known flaw in old software lets an attacker in.An update plan, automatic updates
Weak or reused passwordOne leaked password opens many accounts.A password manager, a second factor (a second proof, such as a code from a phone: lesson 3)

Worked example

1. Make the lab folder

If you did lesson 0, the folder exists. mkdir -p makes it when it does not, and cd moves you into it.

mkdir -p ~/krlab/security-basics
cd ~/krlab/security-basics

2. Write the risk register

A CSV file (comma-separated values) is a table in plain text: one row per line, one comma between the cells, and the first row holds the column names. The shell command cat > risks.csv <<'EOF' writes every line that follows, up to the line EOF, into the file risks.csv.

Use your own laptop and your own habits, and change the rows to match them. Each row is one asset and one threat.

One row of risks.csv
Photos and documentsassetDisk failsthreatNo backupvulnerability3likelihood5impactWeekly copy to an external diskcontrolPhotos and documentsassetDisk failsthreatNo backupvulnerability3likelihood5impactWeekly copy to an external diskcontrol
cat > risks.csv <<'EOF'
asset,threat,vulnerability,likelihood,impact,control
Photos and documents,Disk fails,No backup,3,5,Weekly copy to an external disk
Laptop,Theft from a bag,Disk is not encrypted,2,5,Full-disk encryption
Email account,Password guessing,Same password on many sites,4,5,Password manager and a second factor
Browser,Malicious download,Old browser version,3,3,Automatic updates
Home Wi-Fi,Neighbour joins the network,Weak Wi-Fi password,2,3,Long passphrase and WPA3 or WPA2
Work notes,Accidental deletion,No version history,3,2,Git repository for notes
EOF

3. Write the script that ranks the rows

Write risk.py. Five parts of it are new:

  • The csv module is in the standard library. csv.DictReader reads a CSV file and gives each row as a dictionary, so you write r["impact"] and not a column number.
  • int() turns the text "5" into the number 5, so that you can multiply.
  • rows.sort(key=..., reverse=True) puts the rows in order. The key says what to sort by, and reverse=True puts the highest first. lambda r: r["risk"] is a one-line function with no name: given a row r, it returns the risk number.
  • In an f-string, {x:>4} right-aligns x in 4 spaces, and {x:<24} left-aligns it in 24. This makes the columns line up.
  • sys.argv is the list of words typed after the program name. sys.argv[1] is the first one, so you can name another file.

risk.py

import csv
import sys

path = sys.argv[1] if len(sys.argv) > 1 else "risks.csv"

with open(path, newline="") as f:
    rows = list(csv.DictReader(f))

for r in rows:
    r["risk"] = int(r["likelihood"]) * int(r["impact"])

rows.sort(key=lambda r: r["risk"], reverse=True)

print(f"{'RISK':>4}  {'L':>1} {'I':>1}  {'ASSET':<24} THREAT")
for r in rows:
    level = "HIGH" if r["risk"] >= 15 else "MEDIUM" if r["risk"] >= 8 else "LOW"
    print(f"{r['risk']:>4}  {r['likelihood']:>1} {r['impact']:>1}  {r['asset']:<24} {r['threat']} [{level}]")

4. Run it

python3 risk.py
RISK  L I  ASSET                    THREAT
  20  4 5  Email account            Password guessing [HIGH]
  15  3 5  Photos and documents     Disk fails [HIGH]
  10  2 5  Laptop                   Theft from a bag [MEDIUM]
   9  3 3  Browser                  Malicious download [MEDIUM]
   6  2 3  Home Wi-Fi               Neighbour joins the network [LOW]
   6  3 2  Work notes               Accidental deletion [LOW]
Risk number of each row
Email account20Photos and documents15Laptop10Browser9Home Wi-Fi6Work notes6Email account20Photos and documents15Laptop10Browser9Home Wi-Fi6Work notes6

The list is now a plan. Work from the top. Your own scores will give a different order, and that is the point: the order says what matters to you.

5. Apply a control and score again

Pick the top row and do its control: set up a password manager and a second factor (lesson 3 builds the code generator of a second factor). The likelihood falls: change it from 4 to 1 and run the script again. sed -i 's/old/new/' file replaces text inside a file. A ^ at the start of the old text means the start of a line, so only the line that begins with that text changes. head -3 prints only the first three lines, and the sign | (pipe) gives the output of one command to the next.

sed -i 's/^Email account,Password guessing,Same password on many sites,4,5/Email account,Password guessing,Same password on many sites,1,5/' risks.csv
python3 risk.py | head -3
RISK  L I  ASSET                    THREAT
  15  3 5  Photos and documents     Disk fails [HIGH]
  10  2 5  Laptop                   Theft from a bag [MEDIUM]

The email row is now 5 and has dropped down the list. The disk is the next job. Keep the file: lesson 8 uses the same way of thinking.

Your turn

Now help the practice. The owner gave you this list of worries. Save it as office.csv in ~/krlab/security-basics (as in lesson 0, step 2). There are no steps here: use risk.py from the worked example, and read its output.

office.csv

asset,threat,vulnerability,likelihood,impact,control
Patient records,Ransomware,Staff open attachments,4,5,Backups and mail filtering
Reception PC,Theft,Door is left open at night,2,3,Lock and cable
Appointment website,Defacement,Old plugin not updated,3,4,Update plan
Office Wi-Fi,Guest joins the staff network,One network for all,3,3,Separate guest network
Phone system,Toll fraud,Default admin password,2,4,Change the password
Paper files,Fire,No copy elsewhere,1,5,Scan and store off site

Ransomware is malware that locks files with encryption and asks for money. Defacement means that an attacker changes what a web page shows. Rank the list. Then pretend that the practice updates the plugin of the website, so that its likelihood falls to 1, and rank the list again on a copy of the file.

Check yourself

A server has an old, unpatched web program, but it holds no data and it is not connected to anything. Is it a risk?

It is a vulnerability, but the impact is close to zero, so the risk is low. A risk needs an asset of value. Note that "holds nothing" must stay true: a later change can give the server value.

A control costs 500 and lowers a risk from 20 to 18. Another costs 50 and lowers a risk from 15 to 5. Which do you do first?

The second. It removes more risk for less money. Compare the fall in risk with the cost, not the size of the starting number.

Two people score the same threat 2 and 5 for likelihood. What do you do?

Ask each one for the evidence. One may know of an earlier incident, or a control that the other cannot see. The numbers are an estimate, and the talk that follows is where you learn the facts.

What is the difference between a threat and a vulnerability?

A threat is what can do the harm (a thief, a failing disk, malware). A vulnerability is the weakness that lets it work (no encryption, no backup). You control vulnerabilities more often than threats.

Field notes

  • A 5 x 5 matrix is a simple, common method, but it hides a trap: the product treats a rare disaster (1 x 5) like a frequent annoyance (5 x 1). Many teams keep impact as a separate column and review every row of high impact, whatever the likelihood.
  • A treated risk has four exits: reduce it (a control), avoid it (stop the activity), transfer it (insurance, a contract) or accept it. Accepting is a decision with a name and a date on it, not a silence.
  • NIST SP 800-30 describes how to run a risk assessment, and NIST SP 800-37 (the Risk Management Framework) shows where it sits in the life of a system. ISO/IEC 27005 is the matching standard for information security risk.
  • Re-score on a calendar and after every change. A register that nobody updates is worse than none, because it gives a false picture of the position.
  • Where you can, replace a guess with data: how many failed logins you see, how often a disk fails in your fleet. Lesson 6 shows how logs give you that data.