Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 53 ยท Foundations and Ethics

Thinking Like an Attacker: Threat Modeling

Learn threat modeling: find assets and trust boundaries, apply STRIDE, draw attack trees, score risk as likelihood times impact and read the MITRE ATT&CK matrix.

You cannot defend everything equally, and you cannot test everything at once. Threat modeling is the habit of thinking about a system before it is attacked: what is worth protecting, who might go after it, how they could get in, and which problems deserve attention first. It is cheap (a whiteboard and some honest questions) and it finds design flaws that no scanner can see, because the flaw is in the plan, not in the code.

This lesson gives you a small toolkit: assets and trust boundaries, the STRIDE checklist, attack trees, a simple risk formula, and the MITRE ATT&CK knowledge base. You will end with a program that scores and ranks risks so the "what first?" question has an answer.

Four questions of threat modeling

What are we building? Draw the parts and data flows.
What can go wrong? Use STRIDE as a checklist.
What do we do about it? Fix, reduce, accept or transfer.
Did we do enough? Review and repeat as things change.
1 / 2

Assets, actors and trust boundaries

Start with assets: the things whose loss would hurt. Customer records, password hashes, signing keys, uptime of the checkout page, the company's reputation. An asset is valuable to the owner and to an attacker, and these values often differ: you may see a log file as boring, while an attacker sees the internal hostnames inside it.

Next, list the actors: legitimate users, administrators, partner systems, and threat actors such as opportunistic criminals, disgruntled insiders or competitors. A hobby blog and a bank face different adversaries with different budgets, so their models differ.

Then draw the data flows: browser to web server, server to database, server to payment provider. Wherever data crosses from a less trusted zone into a more trusted one, you have a trust boundary. The internet is outside, your web tier is semi-trusted, the database is inside. Most security bugs live on these boundaries, because that is where code must decide whether to believe what it received.

flowchart LR
    U["User browser<br/>(untrusted)"] -->|HTTPS request| W["Web app"]
    W -->|SQL query| D[("Database")]
    W -->|API call| P["Payment provider<br/>(third party)"]
    subgraph Boundary1["Trust boundary: internet to our network"]
      W
      D
    end

Every arrow that crosses a boundary deserves the question: what if this input is hostile?

A useful rule: never trust input just because it arrives on an internal-looking path. Attackers who gain a foothold on one machine use that machine's trusted position to reach the next.

STRIDE: a checklist for what can go wrong

STRIDE is a mnemonic from Microsoft's early security work. Each letter names a kind of threat and the security property it violates. Go through your diagram element by element and ask each question.

Letter Threat Violates Example Typical defense
S Spoofing Authentication Logging in as someone else Strong auth, MFA, signed tokens
T Tampering Integrity Changing a price in a request Validation, signatures, access control
R Repudiation Non-repudiation "I never deleted that record" Audit logs, timestamps, protected logs
I Information disclosure Confidentiality Verbose errors leak a path Encryption, least data, safe errors
D Denial of service Availability Flooding an endpoint Rate limits, capacity, caching
E Elevation of privilege Authorization A user reaches admin features Least privilege, server-side checks

STRIDE is a prompt, not a proof. You will not apply all six letters to every element (a database does not "spoof"), but running the list stops you from forgetting an entire category. For a login form you might note: spoofing by stolen passwords, tampering with the redirect parameter, disclosure by telling attackers whether the username exists, denial of service by locking accounts out, and elevation by changing a role field in the request.

Attack trees

An attack tree takes one attacker goal as the root and breaks it into the ways to reach it. Branches marked OR are alternatives; branches marked AND must all happen. Writing the tree shows you the cheapest path, and the cheapest path is usually the one real attackers take.

flowchart TD
    G["Goal: read another user's orders"] --> A["OR: guess or steal a session"]
    G --> B["OR: abuse the order API"]
    G --> C["OR: reach the database directly"]
    A --> A1["Phish the user's password"]
    A --> A2["Steal cookie via XSS"]
    B --> B1["Change the order ID in the URL"]
    C --> C1["AND: get network access"]
    C --> C2["AND: obtain database credentials"]

Changing an ID in a URL is far cheaper than the database route, so fix that branch first.

You can attach a rough cost or difficulty to each leaf. An attacker is rational about effort: if one branch costs ten minutes and another ten weeks, defending the second while ignoring the first is a poor use of time.

Risk: likelihood times impact

Once you have a list of threats, you need an order. The simplest widely used measure is:

risk = likelihood ร— impact

Score each from 1 (low) to 5 (high). A threat that is likely and harmful scores 25; a rare, harmless one scores 1. This is a rough tool and the numbers are opinions, but forcing the opinions into numbers makes the team compare them honestly. Some teams use frameworks such as DREAD or CVSS (covered in Vulnerability Scanning and Triage); the principle is the same.

Once a risk is ranked, you have four classic responses: mitigate it (add a control), avoid it (remove the feature), transfer it (insurance, a provider), or accept it knowingly and in writing. Accepting a risk is a legitimate decision as long as someone with authority makes it consciously.

MITRE ATT&CK in one page

MITRE ATT&CK is a public knowledge base that catalogues what real attackers have been observed doing. It is organized as a matrix: the columns are tactics (the attacker's goals, such as Initial Access, Execution, Persistence, Privilege Escalation, Defense Evasion, Credential Access, Discovery, Lateral Movement, Collection, Command and Control, Exfiltration and Impact), and each column holds techniques with IDs such as T1566 (Phishing) and sub-techniques beneath them.

Defenders use it as a shared vocabulary: "our logging covers these ten techniques but misses these four." Red teams plan exercises with it, and detection engineers map rules to it. It describes behavior in the real world; it is not a how-to guide and it does not rank which techniques matter for you. Your threat model does that. You will use the ATT&CK vocabulary again in Persistence, Lateral Movement and Detection.

Stand-in: scoring and ranking risks

The model below holds a short threat list for an imaginary web shop, computes likelihood ร— impact, sorts by score and attaches a response label. It is a simple version of the spreadsheet most teams really use.

JS Risk register: score and rank threats

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Try changing the likelihood of T3 to 1 after you "move the admin panel behind a VPN" and watch it drop. That is the whole point: a ranked list tells you which fix buys the most risk reduction. It also shows the formula's weakness: a 5 ร— 1 and a 1 ร— 5 both score 5, but the second (rare and devastating) often deserves more attention than the number suggests. Treat scores as a conversation starter, not a verdict.

Stand-in: STRIDE coverage check

A threat model is only as good as its coverage. This second program records which STRIDE categories the team has considered for each component and reports the gaps.

JS Which STRIDE categories are still missing?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Some gaps are fine: an audit log has little "spoofing" risk of its own. Others are warnings: the order API has no "S" noted, yet it handles authenticated actions, and no "D", although an unbounded endpoint is easy to flood. The program cannot decide which gaps matter; it only makes sure the question is asked.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Where do security bugs most often appear in a data flow diagram?

    Code must decide whether to believe what it receives across a trust boundary, and mistakes in that decision are the root of many vulnerabilities.
  2. 2. In STRIDE, an attacker changes the price field in a request before it reaches the server. Which letter is this?

    Changing data in transit or at rest is tampering, a violation of integrity.
  3. 3. A threat has likelihood 4 and impact 5. With risk = likelihood ร— impact, what is its score?

    4 ร— 5 = 20, which falls in the high band on a 1 to 25 scale.
  4. 4. What is MITRE ATT&CK mainly used for?

    ATT&CK describes real attacker behavior by tactic and technique, so defenders and red teams can talk about coverage consistently.
  5. 5. Accepting a risk is a valid response when...

    Acceptance is a conscious business decision. Ignoring a risk without deciding is not acceptance.

Summary

  • Threat modeling asks what you are building, what can go wrong, what you will do about it and whether that is enough.
  • Assets, actors, data flows and trust boundaries are the raw material; boundaries are where checks must happen.
  • STRIDE (Spoofing, Tampering, Repudiation, Information disclosure, Denial of service, Elevation of privilege) is a checklist of threat types.
  • Attack trees show the cheapest path to a goal, which is usually the path to defend first.
  • Risk scoring (likelihood ร— impact) ranks work; treat scores as discussion aids, and respond by mitigating, avoiding, transferring or accepting.
  • MITRE ATT&CK gives a shared language for attacker behavior.

Next: The Penetration Testing Process.