TExcelTAD
Home › Ethical Hacking & Penetration Testing Methodology › CVSS v3.1: A Base and Temporal Calculator

CVSS v3.1: A Base and Temporal Calculator

Every finding needs a severity, and "it felt serious" is not a severity. The Common Vulnerability Scoring System (CVSS), maintained by FIRST, turns a vulnerability's properties into a vector string and a score from 0 to 10. Version 4.0 is current (the next lesson), but v3.1 remains the score most databases, scanners and clients still quote, and its closed formula is the best way to understand what a CVSS score measures and what it ignores. This lesson builds a complete v3.1 base and temporal calculator, checks it against well-known vectors, and uses it to answer a tester's real question: which change would lower this score most?

Writing Findings That Get Fixed introduced the base score with a compact function; here the calculator validates vectors, shows the two sub-scores, adds the temporal metrics and runs a sensitivity analysis.

The base metrics

Metric Values (weight) Question
Attack Vector AV Network N (0.85), Adjacent A (0.62), Local L (0.55), Physical P (0.2) from where can it be exploited?
Attack Complexity AC Low L (0.77), High H (0.44) are there conditions outside the attacker's control?
Privileges Required PR None N (0.85), Low L (0.62, or 0.68 if scope changes), High H (0.27, or 0.5 if scope changes) which account does the attacker need first?
User Interaction UI None N (0.85), Required R (0.62) must a victim do something?
Scope S Unchanged U, Changed C does the impact reach beyond the vulnerable component's security authority?
Confidentiality, Integrity, Availability C, I, A High H (0.56), Low L (0.22), None N (0) how much of each is lost?

The formulas

The impact sub-score starts from the combined impact of the three CIA metrics:

ISS=1−(1−C)(1−I)(1−A)\text{ISS} = 1 - (1 - C)(1 - I)(1 - A)
Impact={6.42⋅ISSscope unchanged7.52 (ISS−0.029)−3.25 (ISS−0.02)15scope changed\text{Impact} = \begin{cases} 6.42 \cdot \text{ISS} & \text{scope unchanged} \\ 7.52\,(\text{ISS} - 0.029) - 3.25\,(\text{ISS} - 0.02)^{15} & \text{scope changed} \end{cases}
Exploitability=8.22⋅AV⋅AC⋅PR⋅UI\text{Exploitability} = 8.22 \cdot AV \cdot AC \cdot PR \cdot UI

If the impact is 00 or less, the base score is 00. Otherwise it is Roundup(min⁡(Impact+Exploitability,10))\text{Roundup}(\min(\text{Impact} + \text{Exploitability}, 10)) with scope unchanged, and Roundup(min⁡(1.08 (Impact+Exploitability),10))\text{Roundup}(\min(1.08\,(\text{Impact} + \text{Exploitability}), 10)) with scope changed. Roundup returns the smallest number with one decimal place that is at least its input; the specification defines it on integers (multiply by 100,000 first) so that floating-point noise such as 4.0000000000000014.000000000000001 doesn't round up to 4.14.1.

The optional temporal metrics adjust the base score for the current state of the world: Exploit Code Maturity E (Not Defined X 1, High H 1, Functional F 0.97, Proof-of-Concept P 0.94, Unproven U 0.91), Remediation Level RL (X 1, Unavailable U 1, Workaround W 0.97, Temporary Fix T 0.96, Official Fix O 0.95) and Report Confidence RC (X 1, Confirmed C 1, Reasonable R 0.96, Unknown U 0.92):

Temporal=Roundup(Base⋅E⋅RL⋅RC)\text{Temporal} = \text{Roundup}(\text{Base} \cdot E \cdot RL \cdot RC)

Ratings: 00 None, 0.10.1 to 3.93.9 Low, 4.04.0 to 6.96.9 Medium, 7.07.0 to 8.98.9 High, 9.09.0 to 10.010.0 Critical.

The calculator

python · try it yourself
import math

BASE_W = {
    "AV": {"N": 0.85, "A": 0.62, "L": 0.55, "P": 0.2},
    "AC": {"L": 0.77, "H": 0.44},
    "UI": {"N": 0.85, "R": 0.62},
    "C": {"H": 0.56, "L": 0.22, "N": 0.0}, "I": {"H": 0.56, "L": 0.22, "N": 0.0}, "A": {"H": 0.56, "L": 0.22, "N": 0.0},
}
PR_W = {"U": {"N": 0.85, "L": 0.62, "H": 0.27}, "C": {"N": 0.85, "L": 0.68, "H": 0.5}}
TEMP_W = {"E": {"X": 1, "H": 1, "F": 0.97, "P": 0.94, "U": 0.91},
          "RL": {"X": 1, "U": 1, "W": 0.97, "T": 0.96, "O": 0.95},
          "RC": {"X": 1, "C": 1, "R": 0.96, "U": 0.92}}
BASE = ["AV", "AC", "PR", "UI", "S", "C", "I", "A"]

def roundup(x):
    i = round(x * 100000)
    return i / 100000.0 if i % 10000 == 0 else (math.floor(i / 10000) + 1) / 10.0

def parse(vector):
    head, *parts = vector.split("/")
    if head != "CVSS:3.1":
        raise ValueError("not a CVSS:3.1 vector")
    m = {}
    for p in parts:
        k, _, v = p.partition(":")
        if k in m:
            raise ValueError(f"duplicate metric {k}")
        m[k] = v
    for k in BASE:
        if k not in m:
            raise ValueError(f"missing base metric {k}")
    for k, v in m.items():
        ok = {"S": {"U", "C"}, "PR": set(PR_W["U"])}.get(k) or set(BASE_W.get(k) or TEMP_W.get(k) or [])
        if v not in ok:
            raise ValueError(f"bad value {k}:{v}")
    return m

def scores(vector):
    m = parse(vector)
    w = lambda k: BASE_W[k][m[k]]
    iss = 1 - (1 - w("C")) * (1 - w("I")) * (1 - w("A"))
    changed = m["S"] == "C"
    impact = 7.52 * (iss - 0.029) - 3.25 * (iss - 0.02) ** 15 if changed else 6.42 * iss
    expl = 8.22 * w("AV") * w("AC") * PR_W[m["S"]][m["PR"]] * w("UI")
    if impact <= 0:
        base = 0.0
    else:
        base = roundup(min((1.08 if changed else 1) * (impact + expl), 10))
    t = 1.0
    for k in TEMP_W:
        t *= TEMP_W[k][m.get(k, "X")]
    return base, roundup(base * t), round(impact, 1), round(expl, 1)

def rating(s):
    return "None" if s == 0 else "Low" if s < 4 else "Medium" if s < 7 else "High" if s < 9 else "Critical"

checks = [
    "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
    "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H",
    "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N",
    "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
    "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/E:U/RL:O/RC:C",
    "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N",
]
print(f"{'base':>4} {'temp':>4} {'imp':>4} {'expl':>4}  rating    vector")
for v in checks:
    b, t, i, e = scores(v)
    print(f"{b:>4} {t:>4} {i:>4} {e:>4}  {rating(t):<9} {v[9:]}")
for bad in ["CVSS:3.1/AV:N/AC:L/PR:N/UI:N/C:H/I:H/A:H", "CVSS:3.1/AV:X/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"]:
    try:
        scores(bad)
    except ValueError as err:
        print("rejected:", err)
base temp  imp expl  rating    vector
 9.8  9.8  5.9  3.9  Critical  AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
10.0 10.0  6.0  3.9  Critical  AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
 6.1  6.1  2.7  2.8  Medium    AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
 7.8  7.8  5.9  1.8  High      AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
 9.8  8.5  5.9  3.9  High      AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/E:U/RL:O/RC:C
 0.0  0.0  0.0  3.9  None      AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N
rejected: missing base metric S
rejected: bad value AV:X

The first three rows are reference values every CVSS user knows: 9.8 for unauthenticated network code execution, 10.0 when the scope changes, 6.1 for a classic reflected XSS. The fourth, a local privilege escalation from a low-privileged account, scores 7.8. With E:U/RL:O/RC:C (no known exploit, official fix available, confirmed) the 9.8 becomes a temporal 8.5, and the rating drops from Critical to High. The sub-scores show why a score is what it is: the 9.8 is an impact of 5.9 plus an exploitability of 3.9.

Which change lowers the score most?

A client with a High finding and a limited budget wants to know which mitigation buys the most. Changing one metric at a time and recomputing shows it. The finding is the lab's unauthenticated Jenkins console reachable from the VPN, scored AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H before mitigation.

python · try it yourself
import math
W = {"AV": {"N": 0.85, "A": 0.62, "L": 0.55, "P": 0.2}, "AC": {"L": 0.77, "H": 0.44},
     "PR": {"N": 0.85, "L": 0.62, "H": 0.27}, "UI": {"N": 0.85, "R": 0.62},
     "C": {"H": 0.56, "L": 0.22, "N": 0}, "I": {"H": 0.56, "L": 0.22, "N": 0}, "A": {"H": 0.56, "L": 0.22, "N": 0}}

def roundup(x):
    i = round(x * 100000)
    return i / 100000.0 if i % 10000 == 0 else (math.floor(i / 10000) + 1) / 10.0

def base_u(m):   # scope unchanged only, enough for this finding
    iss = 1 - (1 - W["C"][m["C"]]) * (1 - W["I"][m["I"]]) * (1 - W["A"][m["A"]])
    impact = 6.42 * iss
    expl = 8.22 * W["AV"][m["AV"]] * W["AC"][m["AC"]] * W["PR"][m["PR"]] * W["UI"][m["UI"]]
    return 0.0 if impact <= 0 else roundup(min(impact + expl, 10))

now = dict(AV="N", AC="L", PR="N", UI="N", C="H", I="H", A="H")
options = {
    "require login (PR:N to PR:L)": {"PR": "L"},
    "admin-only login (PR:N to PR:H)": {"PR": "H"},
    "reachable only from jump host console (AV:N to AV:L)": {"AV": "L"},
    "read-only console (I:H to I:N)": {"I": "N"},
}
print(f"now: {base_u(now)}")
for name, change in sorted(options.items(), key=lambda kv: base_u({**now, **kv[1]})):
    print(f"{base_u({**now, **change}):>4}  {name}")
now: 9.8
 7.2  admin-only login (PR:N to PR:H)
 8.4  reachable only from jump host console (AV:N to AV:L)
 8.8  require login (PR:N to PR:L)
 9.1  read-only console (I:H to I:N)

Making the console read-only barely helps (9.1): two high impacts remain. Requiring any login gives 8.8, confining the console to local sessions on a jump host 8.4, and an administrators-only login 7.2, because PR:H cuts the exploitability most. The calculation can't say which is cheapest; it tells the client what each option is worth, and the report recommends a combination (administrator authentication and network restriction).

The calculator lab does the same arithmetic with buttons: every metric with its weight, the vector string, the sub-score bars and each line of the formula. It starts on the Jenkins finding at 9.8 (impact 5.873, exploitability 3.887). Set PR to High and AV to Local together, the combination the report recommends, and the score falls to 6.7, Medium: the exploitability drops to 0.799 while the impact stays 5.873. Set S to Changed on the original vector and you get the 10.0 from the table above.

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:HAttack VectorN .85A .62L .55P .2Attack ComplexityL .77H .44Privileges RequiredN .85L .62H .27User InteractionN .85R .62ScopeUCConfidentialityN 0L .22H .56IntegrityN 0L .22H .56AvailabilityN 0L .22H .56base score9.8Critical047910Impact 5.87max 5.87Exploitability 3.89max 3.89ISS = 1 − (1−0.56)(1−0.56)(1−0.56) = 0.915Impact = 6.42 × ISS = 5.873Exploitability = 8.22 × 0.85 × 0.77 × 0.85 × 0.85 = 3.887Base = Roundup(min((5.873 + 3.887), 10)) = 9.8

How scores go wrong, and how to catch it

  • Scoring the worst case instead of the finding. CVSS scores the vulnerability as it is on this system: if exploitation needs a logged-in user here, PR:L, even if the CVE's database entry says PR:N.
  • Scope misuse. S:C is for impact beyond the vulnerable component's authority (a VM escape, XSS that runs in users' browsers), not for "it's serious".
  • Using the database score as the finding's severity. NVD scores are base scores without context. Record both: "CVSS 3.1 base 9.8 (NVD), assessed 7.2 in this environment because…".
  • Rounding by hand. Use the specification's Roundup; ordinary rounding gives different answers at the boundaries.

Reviewers catch these by recomputing vectors (which is why the vector, not just the number, goes into the report) and by comparing similar findings across the report for consistency.

Pitfalls

  • Treating CVSS as risk. It measures technical severity. Likelihood of exploitation (see EPSS and KEV) and the asset's value (see prioritisation) are separate inputs.
  • Mixing versions. A v3.1 and a v4.0 score of the same issue differ; always write the version in the vector.
  • The environmental metrics exist (modified base metrics and security requirements CR, IR, AR) but are rarely filled in; when a client gives asset requirements, use them and say so.

Practice

  1. Score CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N (an adjacent-network information leak) with scores(), and name the rating.
  2. Add "C:H to C:L" to the options in the second example and predict, before running, whether it beats "require login".
Answers
  1. ISS = 0.56, impact = 6.42 x 0.56 = 3.595, exploitability = 8.22 x 0.62 x 0.77 x 0.85 x 0.85 = 2.835; sum 6.43, Roundup gives 6.5: Medium. Run scores() to confirm.
  2. With C:L the ISS falls from 0.915 to 0.849 and the impact from 5.87 to 5.45, so the score falls only to 9.4, much less than requiring a login (8.8), which cuts the exploitability. Impact metrics change the score less than you expect while the other two impacts stay High.

Practice problem in 21 languages: CVSS v3.1 Base Score.

Test yourself

What is the CVSS v3.1 base score of AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H?

  1. 10.0
  2. 9.8
  3. 9.1
  4. 8.8

Why does the specification define Roundup on integers?

  1. Speed
  2. To avoid floating-point noise such as 4.000000000000001 rounding up to 4.1
  3. Because scores are integers
  4. To make scores higher

A 9.8 vulnerability has no known exploit and an official fix (E:U/RL:O/RC:C). What is its temporal score?

  1. 9.8
  2. 9.1
  3. 8.5
  4. 7.0

When is Scope Changed (S:C) correct?

  1. Whenever the finding is serious
  2. When the impact reaches components beyond the vulnerable component's security authority, e.g. a VM escape or script running in users' browsers
  3. When several hosts are affected
  4. When the tester is unsure

Which mitigation lowers the Jenkins console's score most in the sensitivity analysis?

  1. Making the console read-only (9.1)
  2. Requiring any login
  3. Restricting it to local sessions on a jump host
  4. An administrators-only login (PR:H)

In the calculator lab, the Jenkins vector gets both PR:H and AV:L. What is the base score?

  1. 7.2 High
  2. 6.7 Medium
  3. 8.4 High
  4. 5.9 Medium