Lesson 10 · 50 minutes
Rank the findings of a small company and decide what to patch first
- Match a list of installed software to a list of vulnerabilities and find the real findings
- Write a ranking function that uses exposure, evidence of exploitation and the value of the asset
- Change the policy and show how the order changes
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
Fernwood Press has eight systems and the fourteen vulnerabilities of lesson 9. The IT team has time to patch two things this week. The team lead asks: "Which two, and why? The finance director says that we should start from the highest CVSS score. Give me the ranking and one line of reason for each of the first five, so that I can answer her." You build the ranking from three kinds of fact: can an attacker reach the system, is the flaw used in attacks, and how much does the system matter.
Recall
Lesson 9: the KEV catalogue and EPSS both say something about exploitation. What does each one say?
KEV records that a flaw is exploited in the wild now. EPSS estimates the probability that it will be exploited in the next 30 days. Use KEV for "now" and EPSS for "next".
Lesson 9: what is the difference between a vulnerability and exposure?
A vulnerability is the weakness in the software. Exposure is whether an attacker can reach it. The same flaw has a large exposure on an internet server and a small one on an isolated machine.
The idea
A finding is one flaw on one system. It exists only when the system runs the product and the version is older than the version that fixes the flaw. The same flaw on three systems is three findings. A patch order ranks the findings by three reasons.
| Reason | Question | Data |
|---|---|---|
| Exposure | Can an attacker reach it? | exposure of the system: internet or internal |
| Evidence | Is it used, or likely to be? | KEV flag, EPSS score |
| Asset value | What do we lose? | criticality, from 1 (small) to 5 (the business stops) |
The CVSS score stays in the ranking as a tie-breaker and as a floor: a flaw with a high score and no evidence still needs a fix, but later. The ranking below is our own policy. It is an example of how to reason, not a standard, and your team sets its own tiers and its own times.
| Tier | Rule | Example time |
|---|---|---|
| 1 | In KEV and the system is on the internet | Days |
| 2 | In KEV, or EPSS of 0.5 or more on the internet | This week |
| 3 | CVSS of 7.0 or more, or EPSS of 0.1 or more | This month |
| 4 | Everything else | The normal patch cycle |
Inside a tier, a system with a higher criticality comes first, then the higher EPSS, then the id, so that the order is always the same.
- Attacker → vpn01: tier 1, KEV, EPSS 0.97
- Attacker → web01: tier 1, KEV, EPSS 0.93
- Attacker → mail01: tier 3, no KEV flaw
- Attacker → db01 (blocked): no route
- Attacker → files01 (blocked): no route
- Inventory → Match: product, version
- Match → Evidence: KEV, EPSS, score
- Evidence → Tier: gives 1 to 4
- Tier → Order: tier, value, EPSS
Worked example
1. Write the inventory
inventory.csv lists the eight systems: an id, the host name, the role, the exposure, the criticality and the kind of data. installed.csv lists the products on each system with their versions. The ids of installed.csv point to the inventory. Both files are invented. The files of lesson 9 (vulns.json, kev.json, epss.csv, vulns.py) must be in the same folder.
cat > inventory.csv <<'EOT'
asset,host,role,exposure,criticality,data
A01,web01,public web server,internet,4,customer
A02,db01,customer database,internal,5,customer
A03,ci01,build server,internal,3,internal
A04,files01,file server,internal,3,internal
A05,wiki01,staff wiki,internal,2,internal
A06,vpn01,vpn gateway,internet,4,internal
A07,mail01,mail relay,internet,3,customer
A08,pool01,editorial workstations,internal,2,internal
EOTcat > installed.csv <<'EOT'
asset,product,version
A01,shopkit,4.2.1
A01,edgeproxy,2.8.0
A02,dbstore,9.4.0
A03,buildrunner,5.1.0
A03,edgeproxy,2.6.3
A04,fileshare,3.0.2
A05,wikilite,1.9.5
A06,vpngate,7.1.0
A07,mailrelay,3.3.1
A07,edgeproxy,2.8.0
A08,docview,11.0.4
EOT2. Compare versions as numbers
A version is a text, and a text sorts letter by letter. Version 4.10.0 is newer than 4.9.0, but the text "4.10.0" sorts before "4.9.0", because the character 1 comes before 9. A tuple is a fixed list of values, and Python compares tuples item by item, so a tuple of numbers sorts right.
python3 -c "
print('4.10.0' < '4.9.0')
print((4, 10, 0) < (4, 9, 0))
"True
FalseThe first line is the wrong answer and the second is the right one. The program turns each version into a tuple: tuple(int(part) for part in text.split(".")).
3. Save the ranking program
findings joins the three sources: for each installed product it looks at each vulnerability of the same product, and keeps those where the installed version is older than fixed_in. tier is the table above. rank sorts with a key that is a tuple of four values; a minus sign in front of a number sorts it from high to low.
patchrank.py
"""patchrank.py: match vulnerabilities to installed software and rank the findings.
python3 patchrank.py [inventory.csv] [installed.csv]
"""
import csv
import sys
from vulns import load
def read_csv(path):
with open(path, newline="") as src:
return list(csv.DictReader(src))
def version(text):
"""'4.2.1' becomes (4, 2, 1), so that versions compare as numbers: 4.10.0 is newer than 4.9.0."""
return tuple(int(part) for part in text.split("."))
def findings(inventory, installed, vulns):
"""A finding is one installed product whose version is older than the version that fixes a vulnerability."""
hosts = {row["asset"]: row for row in inventory}
found = []
for item in installed:
for v in vulns:
if v["product"] == item["product"] and version(item["version"]) < version(v["fixed_in"]):
asset = hosts[item["asset"]]
found.append({"asset": asset["asset"], "host": asset["host"], "exposure": asset["exposure"],
"criticality": int(asset["criticality"]), "id": v["id"], "cvss": v["cvss"],
"kev": v["kev"], "epss": v["epss"], "product": item["product"],
"have": item["version"], "fix": v["fixed_in"]})
return found
def tier(f):
"""1 is fix now, 4 is fix in the normal cycle. This is our own policy, not a standard."""
exposed = f["exposure"] == "internet"
if f["kev"] and exposed:
return 1
if f["kev"] or (f["epss"] >= 0.5 and exposed):
return 2
if f["cvss"] >= 7.0 or f["epss"] >= 0.1:
return 3
return 4
def rank(found):
"""Order by tier, then by the value of the asset, then by the chance of exploitation, then by id."""
return sorted(found, key=lambda f: (tier(f), -f["criticality"], -f["epss"], f["id"]))
if __name__ == "__main__":
inventory = read_csv(sys.argv[1] if len(sys.argv) > 1 else "inventory.csv")
installed = read_csv(sys.argv[2] if len(sys.argv) > 2 else "installed.csv")
ranked = rank(findings(inventory, installed, load()))
for n, f in enumerate(ranked, 1):
print(f"{n:2d} tier {tier(f)} {f['id']} {f['host']:7s} {f['exposure']:8s} crit {f['criticality']} "
f"cvss {f['cvss']:4.1f} {'KEV' if f['kev'] else ' '} epss {f['epss']:.2f} {f['product']} {f['have']} -> {f['fix']}")
print(len(ranked), "findings")4. Run it
python3 patchrank.py 1 tier 1 LAB-2026-0008 vpn01 internet crit 4 cvss 9.8 KEV epss 0.97 vpngate 7.1.0 -> 7.2.1
2 tier 1 LAB-2026-0001 web01 internet crit 4 cvss 9.8 KEV epss 0.93 shopkit 4.2.1 -> 4.3.0
3 tier 2 LAB-2026-0006 files01 internal crit 3 cvss 7.5 KEV epss 0.64 fileshare 3.0.2 -> 3.1.0
4 tier 3 LAB-2026-0004 db01 internal crit 5 cvss 9.1 epss 0.12 dbstore 9.4.0 -> 9.5.0
5 tier 3 LAB-2026-0003 web01 internet crit 4 cvss 8.1 epss 0.41 edgeproxy 2.8.0 -> 2.9.0
6 tier 3 LAB-2026-0005 ci01 internal crit 3 cvss 9.8 epss 0.77 buildrunner 5.1.0 -> 5.2.0
7 tier 3 LAB-2026-0013 ci01 internal crit 3 cvss 9.3 epss 0.55 buildrunner 5.1.0 -> 5.1.2
8 tier 3 LAB-2026-0003 ci01 internal crit 3 cvss 8.1 epss 0.41 edgeproxy 2.6.3 -> 2.9.0
9 tier 3 LAB-2026-0003 mail01 internet crit 3 cvss 8.1 epss 0.41 edgeproxy 2.8.0 -> 2.9.0
10 tier 3 LAB-2026-0009 mail01 internet crit 3 cvss 7.5 epss 0.05 mailrelay 3.3.1 -> 3.4.0
11 tier 3 LAB-2026-0010 pool01 internal crit 2 cvss 7.8 epss 0.30 docview 11.0.4 -> 11.1.0
12 tier 4 LAB-2026-0011 web01 internet crit 4 cvss 6.5 epss 0.01 shopkit 4.2.1 -> 4.4.0
13 tier 4 LAB-2026-0007 wiki01 internal crit 2 cvss 5.4 epss 0.02 wikilite 1.9.5 -> 2.0.0
13 findingsThirteen findings. The first two are tier 1: the VPN gateway and the web server, both on the internet, both with a flaw that is in the catalogue. These are the two things to patch this week.
5. Read the order, and what is not in it
Rank 3 is an internal file server. It comes before a database with a score of 9.1 because its flaw is in the catalogue (and its entry says that ransomware groups use it), so it is tier 2, while the database flaw is only tier 3. Inside tier 3 the database (criticality 5) comes before the build server (criticality 3), although the build server has a higher score and a higher EPSS: the policy puts asset value before EPSS, and you can argue for another choice. That argument is the point of having a policy in code.
Which vulnerabilities produce no finding at all? Three of the fourteen.
python3 - <<'PYEND'
from patchrank import findings, read_csv
from vulns import load
rows = load()
found = {f["id"] for f in findings(read_csv("inventory.csv"), read_csv("installed.csv"), rows)}
print(sorted(r["id"] + " " + r["product"] for r in rows if r["id"] not in found))
PYEND['LAB-2026-0002 shopkit', 'LAB-2026-0012 vpngate', 'LAB-2026-0014 printspool']LAB-2026-0002 and LAB-2026-0012 are already fixed in the installed versions, and nobody runs printspool. A feed lists every flaw. Only the flaws that match your inventory are your work.
6. Answer the finance director
Sort the findings by score alone and take the first three.
python3 - <<'PYEND'
from patchrank import findings, read_csv
from vulns import load
found = findings(read_csv("inventory.csv"), read_csv("installed.csv"), load())
for f in sorted(found, key=lambda f: (-f["cvss"], f["id"]))[:3]:
print(f["id"], f["host"], f["exposure"], "cvss", f["cvss"], "KEV" if f["kev"] else "")
PYENDLAB-2026-0001 web01 internet cvss 9.8 KEV
LAB-2026-0005 ci01 internal cvss 9.8
LAB-2026-0008 vpn01 internet cvss 9.8 KEVBy score alone, the second fix would go to an internal build server with no evidence of use, and the VPN gateway, which is on the internet and in the catalogue, would come third. The ranking of this lesson puts the VPN gateway first.
Your turn
The branch office has ten systems. The generator makes inventory2.csv and installed2.csv. The inventory has one more column, shielded: yes means that the system sits behind a control that blocks the attack path, for example a web application firewall or a network without a route from outside. Add this rule to your ranking: a finding on a shielded system moves one tier towards tier 4, and never past it. Use the same vulns.json, kev.json and epss.csv, and write the new code in a copy of patchrank.py.
The finished file: gen_branch.py
gen_branch.py
"""gen_branch.py: write inventory2.csv and installed2.csv, the systems of a small branch office. Run: python3 gen_branch.py"""
import random
r = random.Random(21) # only random() is used: the files are the same on every Python version
def pick(items):
return items[int(r.random() * len(items))]
PRODUCTS = {"shopkit": ["4.1.0", "4.2.1", "4.4.0"], "edgeproxy": ["2.6.3", "2.8.0", "2.9.0"],
"dbstore": ["9.4.0", "9.5.0"], "buildrunner": ["5.1.0", "5.1.2", "5.2.0"],
"fileshare": ["3.0.2", "3.1.0"], "wikilite": ["1.9.5", "2.0.0"], "vpngate": ["7.1.0", "7.2.1"],
"mailrelay": ["3.3.1", "3.4.0"], "docview": ["11.0.4", "11.1.0"], "printspool": ["1.7.0", "1.8.0"]}
ROLES = ["web server", "file server", "database", "mail relay", "gateway", "workstations", "build server"]
with open("inventory2.csv", "w") as inv, open("installed2.csv", "w") as ins:
inv.write("asset,host,role,exposure,criticality,data,shielded\n")
ins.write("asset,product,version\n")
for n in range(1, 11):
asset = f"B{n:02d}"
inv.write(f"{asset},br{n:02d},{pick(ROLES)},{'internet' if r.random() < 0.4 else 'internal'},"
f"{1 + int(r.random() * 5)},{pick(['public', 'internal', 'customer'])},"
f"{'yes' if r.random() < 0.4 else 'no'}\n")
first = pick(sorted(PRODUCTS))
second = pick([p for p in sorted(PRODUCTS) if p != first])
for product in (first, second):
ins.write(f"{asset},{product},{pick(PRODUCTS[product])}\n")
print("wrote inventory2.csv and installed2.csv")python3 gen_branch.pywrote inventory2.csv and installed2.csvCheck yourself
Why does the program compare versions as tuples of numbers and not as text?
Text sorts letter by letter, so "4.10.0" sorts before "4.9.0" and a fix looks older than it is. A tuple of numbers compares the parts as numbers. Real version schemes are harder (letters, release candidates), and a real tool needs a proper version library.
A flaw with a CVSS score of 5.4 is in tier 2 on one system and in tier 4 on another system. How can that be?
Tier depends on the system as well as on the flaw. If the flaw is in the catalogue and the first system is on the internet, it is tier 1 or 2 there. On an isolated system without the evidence, it can be tier 4. The same flaw is not the same risk on two systems.
The ranking puts the criticality of the system before the EPSS score inside a tier. Name one reason to do that and one reason to choose the other way.
For: a flaw on the customer database costs more than a flaw on a build server, even when the second is slightly more likely. Against: EPSS is the measured likelihood, and a very likely flaw on a less important system can be the one that is used first. Write the choice down and review it after an incident.
A system is "shielded" by a firewall rule. Why is moving the finding only one tier safer than ignoring it?
A control can fail, be changed or be walked around, and an attacker who is inside the network is not stopped by a rule at the edge. The flaw is still there. Moving it down one tier recognises the control, and the fix stays on the list.
Field notes
- Keep the inventory honest. A patch order is only as good as the list of what you run. Assets that nobody knows about are never patched, and they are the ones that attackers find first.
- Write down the policy and the reason for every tier, and review the times with the system owners. A tier that nobody can meet is ignored.
- A patch is not the only answer. When a fix cannot go in this week, reduce the exposure: close the port, add the rule, turn off the feature. Record that as a compensating control with an owner and an end date.
- For a flaw that is in the catalogue and was open on an internet system, patching is not the end. Check the logs for the period before the patch, because the attacker may have been there already. Lesson 12 shows how.
- Report in numbers over time: findings by tier, age of the oldest finding in each tier, and how many were fixed in the time that the policy sets.