Skip to content

Latest commit

ย 

History

History
384 lines (289 loc) ยท 21.5 KB

lec2.md

File metadata and controls

384 lines (289 loc) ยท 21.5 KB

๐Ÿ“Œ Lecture 2 โ€” Threat Modeling: STRIDE, DFDs, and Threagile


๐Ÿ“ Slide 1 โ€“ ๐ŸชŸ The Pre-Mortem That Costs $0

  • ๐Ÿ—๏ธ You can't scan code that doesn't exist yet
  • ๐ŸŽฏ At the design stage, the cheapest bug fix is "we won't build it that way" โ€” but you have to see the bug first
  • ๐ŸŽญ Threat modeling = a structured pre-mortem where you and your team enumerate how your system can be attacked, before you ship the design to anyone with a keyboard
  • ๐Ÿ’ธ Recall Boehm's curve from Lecture 1: the later a defect is found, the dearer it is, and design is the earliest stage there is. Threat modeling is the only control in this course that runs before a line of code exists

๐Ÿ’ฌ "What's your threat model?" โ€” the question that separates a security discussion from a security argument. Without it, "is this secure?" has no answer

๐Ÿค” Think: Lecture 1 covered Equifax, Capital One, Log4Shell. Pick one โ€” what would the design-stage conversation have flagged? (Spoiler: all three.)


๐Ÿ“ Slide 2 โ€“ ๐ŸŽฏ Learning Outcomes

# ๐ŸŽ“ Outcome
1 โœ… Draw a Level-1 Data Flow Diagram (DFD) for a small web app, with trust boundaries
2 โœ… Apply STRIDE to each DFD element and produce a ranked threat list
3 โœ… Recognize when STRIDE is the wrong tool (and which others fit)
4 โœ… Model a system declaratively in Threagile YAML and read the generated risk report
5 โœ… Identify three Threagile risk rules likely to fire on a typical web app

๐Ÿ“ Slide 3 โ€“ ๐Ÿ—บ๏ธ Where Lecture 2 Sits

graph LR
    L1["๐Ÿ›๏ธ L1 Foundations<br/>Why DevSecOps"] --> L2["๐ŸŽฏ L2 Threat<br/>modeling (here)"]
    L2 --> L3["๐Ÿ” L3 Secure<br/>Git"]
    L2 -.feeds.-> L5["๐Ÿงช L5 SAST/<br/>DAST"]
    L2 -.feeds.-> L6["๐Ÿ—๏ธ L6 IaC<br/>scan"]

    style L2 fill:#FF9800,color:#fff
Loading
  • ๐Ÿชœ Building on L1: Lecture 1 mapped breaches to OWASP categories; this lecture explains how to discover those categories on your own system, before any code is written
  • ๐ŸŽฏ Lab 2 alignment: model a sample web architecture in Threagile, then create a secure variant with HTTPS + encrypted DB, and compare the risk reports

๐Ÿ“ Slide 4 โ€“ ๐Ÿ›๏ธ What Threat Modeling Actually Is

Adam Shostack's Threat Modeling: Designing for Security (Wiley, 2014) frames the whole practice as four questions. The 2020 Threat Modeling Manifesto, written by fifteen practitioners including Shostack, adopts the same four:

# โ“ Question ๐Ÿ“ฆ Output
1 What are we building? DFD / architecture sketch
2 What can go wrong? Threat list (STRIDE-driven)
3 What are we going to do about it? Mitigation list, ranked
4 Did we do a good job? Re-review at design changes
  • ๐ŸŽฏ The four questions are framework-agnostic โ€” STRIDE, PASTA, LINDDUN all answer them differently
  • ๐Ÿง  Threat modeling is a team activity, not a deliverable. The output document is a byproduct; the conversation between dev/ops/sec is the value

๐Ÿ“ Slide 5 โ€“ ๐Ÿงฑ Trust Boundaries: The Core Idea

flowchart LR
    subgraph TB1 [๐ŸŒ Internet]
        U[๐Ÿ‘ค User]
    end
    subgraph TB2 [โ˜๏ธ DMZ]
        W[๐ŸŒ Web server]
    end
    subgraph TB3 [๐Ÿ”’ Internal]
        A[โš™๏ธ App tier]
        D[(๐Ÿ—„๏ธ DB)]
    end

    U -->|HTTP| W
    W -->|HTTP| A
    A -->|SQL| D

    style TB1 fill:#FFEBEE,color:#000
    style TB2 fill:#FFF3E0,color:#000
    style TB3 fill:#E8F5E9,color:#000
Loading
  • ๐Ÿชช A trust boundary is a line across which data or authority flows between actors of different trust levels
  • ๐Ÿšฆ Every arrow crossing a boundary is a threat candidate. The arrows inside a boundary you can usually ignore (you've already trusted that zone)
  • ๐ŸŽฏ In Lab 2 you'll model exactly this kind of three-zone diagram and let Threagile enumerate the threats per arrow

๐Ÿ“ Slide 6 โ€“ ๐Ÿ“Š DFDs in Five Symbols

๐Ÿ–ผ๏ธ Symbol ๐Ÿท๏ธ Element ๐ŸŽฏ What it represents
โฌ› Square External entity Users, third-party APIs โ€” anything you don't own
โญ• Circle Process Code that does work (your microservice)
๐Ÿ›ข๏ธ Two-line cylinder Data store Databases, queues, file shares
โžก๏ธ Arrow Data flow Direction of data movement
โœ‚๏ธ Dashed line Trust boundary Crosses change trust level
  • ๐Ÿ›๏ธ DFDs come from 1970s structured analysis: the notation was proposed by Larry Constantine and popularised by Tom DeMarco's Structured Analysis and System Specification (Yourdon Press, 1978), two decades before anyone used it for threats
  • ๐Ÿชœ Level 0 = single-circle "context diagram"; Level 1 = subsystems exposed; Level 2+ = per-subsystem internals. For threat modeling, Level 1 is usually the right zoom

๐Ÿ“ Slide 7 โ€“ ๐ŸŽฏ STRIDE โ€” The Core Method

  • ๐Ÿ—“๏ธ Loren Kohnfelder and Praerit Garg, Microsoft, 1 April 1999, in an internal paper called The Threats to Our Products. It was the first method that told engineers how to look for threats instead of listing known ones
  • ๐Ÿ“– Each letter is a threat category mapped to a security property
๐Ÿ”ค Letter ๐Ÿšจ Threat ๐Ÿ›ก๏ธ Property violated ๐Ÿ’ก Example
S Spoofing identity Authentication Attacker logs in as another user via stolen token
T Tampering with data Integrity SQL injection alters records
R Repudiation Non-repudiation User denies they made a transaction; no audit log
I Information disclosure Confidentiality Stack trace leaks DB schema to user
D Denial of service Availability Slowloris exhausts thread pool
E Elevation of privilege Authorization User accesses admin endpoint due to missing check
  • ๐Ÿง  Trick: STRIDE pairs cleanly with CIA + A + NR from Lecture 1. The two frameworks are isomorphic โ€” STRIDE is "which property is at risk?"; CIA is "what does the property protect?"

๐Ÿ“ Slide 8 โ€“ ๐ŸŽฌ STRIDE Applied to One Arrow

A login flow: Browser โ†’ /api/login โ†’ user_db

๐Ÿ”ค STRIDE โ“ Question ๐Ÿ›ก๏ธ Mitigation candidate
S Could an attacker spoof the user's session? TLS, secure cookies, MFA
T Can the request body be tampered in transit? TLS, request signing
R If the user denies logging in, is there proof? Auth audit log, IP + UA capture
I Does the response leak whether the email exists? Generic "invalid credentials" message
D Can someone exhaust the login endpoint? Rate limiting, captcha after N failures
E Can a normal user reach admin login by changing a URL? Server-side role check, not client-side
  • ๐Ÿชœ For one arrow, you get six threat candidates. A typical Level-1 DFD has 5โ€“10 arrows. 30โ€“60 threats is normal โ€” that's why you need ranking, which we'll cover with Threagile

๐Ÿ“ Slide 9 โ€“ ๐ŸŽฒ STRIDE Is Not the Only Game in Town

graph TB
    TM[๐ŸŽฏ Threat modeling methods]
    TM --> ST[STRIDE<br/>Microsoft, 1999<br/>Threat categories]
    TM --> PA[PASTA<br/>UcedaVelez and Morana, 2015<br/>Risk-centric, 7 stages]
    TM --> LI[LINDDUN<br/>KU Leuven, 2011<br/>Privacy-focused]
    TM --> FA[FAIR<br/>Quantitative risk in money]
    TM --> VA[VAST<br/>ThreatModeler<br/>App + Op, scales]

    style ST fill:#4CAF50,color:#fff
    style PA fill:#2196F3,color:#fff
    style LI fill:#9C27B0,color:#fff
    style FA fill:#FF9800,color:#fff
    style VA fill:#F44336,color:#fff
Loading
๐ŸŽฏ Method ๐Ÿชœ Good for ๐Ÿšซ Skip when
STRIDE Most web/API apps (this course) Pure data-processing pipelines
PASTA Risk-based programs, regulated industries You don't have 7 stages of patience
LINDDUN Privacy-sensitive systems (GDPR scope) No personal data
FAIR Talking to execs in dollar terms Engineering-only conversations
VAST Very large estates (100+ services) Single product team
  • ๐Ÿง  In this course we standardize on STRIDE + Threagile โ€” STRIDE because it's the most teachable, Threagile because it makes STRIDE actually executable in a pipeline

๐Ÿ“ Slide 10 โ€“ โš™๏ธ Threagile: STRIDE That Runs in CI

  • ๐Ÿข Created by Christian Schneider; released 4 August 2020 at Black Hat USA Arsenal and DEF CON 28 AppSec Village, MIT licence
  • ๐Ÿน Written in Go; latest release is v0.9.1 (July 2024), which is what Lab 2 pins. The binary inside reports itself as 1.0.0
  • ๐Ÿ“œ You describe the system in a YAML file: assets, communication links, trust boundaries, data assets
  • ๐Ÿค– Threagile runs ~50 built-in risk rules and outputs PDF + Excel + JSON reports with scored risks, mapped to STRIDE
  • ๐Ÿชœ Crucial property: the model is version-controlled, diffable, runnable in CI โ€” you can fail a PR if a new high-severity threat appears
# โœ… Lab 2 runs exactly this. The output directory must exist first
mkdir -p output
docker run --rm -v "$PWD":/app/work threagile/threagile:0.9.1 \
  -model /app/work/threagile-model.yaml \
  -output /app/work/output

๐Ÿ“ Slide 11 โ€“ ๐Ÿ“œ A Threagile Model, Annotated

technical_assets:
  Web Application:
    type: process
    technology: web-application
    usage: business
    machine: container
    encryption: none                       # ๐Ÿšจ will trigger risk
    owner: AppTeam
    confidentiality: confidential
    integrity: important
    availability: important
    multi_tenant: false
    redundant: false
    custom_developed_parts: true
    data_assets_processed: [Customer Records]
    data_assets_stored: []
    communication_links:
      DB Connection:
        target: User Database
        protocol: jdbc                     # ๐Ÿšจ plain JDBC, not jdbc-encrypted
        authentication: credentials
        authorization: technical-user
        usage: business
        data_assets_sent: [Customer Records]
        data_assets_received: [Customer Records]
๐Ÿท๏ธ Key field ๐ŸŽฏ Why it matters
encryption: none Triggers unencrypted-asset risk
protocol: jdbc (not jdbc-encrypted) Triggers unencrypted-communication-link risk
confidentiality: confidential Boosts severity score
  • ๐Ÿง  The lab is exactly this kind of edit-and-rescan cycle โ€” minimal YAML, real reports

๐Ÿ“ Slide 12 โ€“ ๐Ÿงฎ Threagile Rules You'll See in Lab 2

Selected from Threagile's ~50 built-in rules:

๐Ÿšจ Rule ID ๐ŸŽฏ What it detects
unencrypted-communication Link whose protocol is not an encrypted one
unencrypted-asset Asset storing data without encryption
missing-authentication Link into a sensitive asset with no authentication
cross-site-scripting Web frontend able to render untrusted content
server-side-request-forgery Asset making outbound calls on someone else's behalf
missing-vault Secrets with no vault asset anywhere in the model
container-baseimage-backdooring Container built from an unverified base image
missing-build-infrastructure No build pipeline modelled at all
  • ๐Ÿชœ Task 2 in Lab 2 asks you to model a secure variant and diff the reports. On the shipped model the baseline is 23 risks: 4 elevated, 14 medium, 5 low, none critical or high. Encrypting both links and both stores removes exactly three rule classes and lands at 18. Note what that means: hardening the transport removed a fifth of the list, and the rest is design and process work

๐Ÿ“ Slide 13 โ€“ โš–๏ธ Rapid vs Deep Threat Modeling

๐Ÿชœ Mode โฑ๏ธ Time ๐ŸŽฏ Best for
Whiteboard / shostack-4-questions 30 min Sprint planning, new feature design
Threagile YAML 2-4 hours Service-level architecture review
Full PASTA / SAMM-aligned Days Annual program review, regulated systems
  • ๐Ÿชœ The biggest mistake new teams make: trying to do "perfect" threat modeling and then never doing it again. A 30-minute model done quarterly beats a 30-page model done once
  • ๐Ÿง  "The best threat model is the one your team will actually run." โ€” Izar Tarandach, Threat Modeling: A Practical Guide (O'Reilly, 2021)

๐Ÿ“ Slide 14 โ€“ ๐Ÿ›๏ธ The Microsoft Threat Modeling Tool

  • ๐Ÿ†“ Free GUI tool from Microsoft (Windows only, supported on Linux via Wine)

  • ๐Ÿชœ First released in 2003 as part of the Microsoft SDL (Security Development Lifecycle)

  • ๐Ÿ–ผ๏ธ Drag-and-drop DFD editor; auto-generates STRIDE threats per element

  • โš ๏ธ Limitations: GUI-only (no git diff), no CI integration, slow on large systems

  • ๐Ÿ†š Threagile vs MS-TMT trade-off:

    • MS-TMT is friendlier for first-timers and brainstorming
    • Threagile is what fits in DevSecOps because it's text + executable
  • ๐Ÿชœ Use MS-TMT in a workshop to discover threats, then transcribe to Threagile for continuous verification


๐Ÿ“ Slide 15 โ€“ ๐Ÿ”ฌ Case Study: The Trust Boundary Nobody Modelled (2025)

Salesloft Drift, August 2025. Drift is a chat product that integrates with Salesforce. To do its job it holds OAuth access and refresh tokens for its customers' Salesforce tenants.

  • ๐Ÿ—“๏ธ 8-18 August 2025: an attacker tracked as UNC6395 uses stolen Drift OAuth tokens to authenticate to customer Salesforce instances and run bulk SOQL queries through the API
  • ๐ŸŒ Google's threat intelligence team reports more than 700 organisations potentially affected; Salesloft and Salesforce revoke every Drift token and take the integration offline
  • ๐ŸŽฏ What the attacker was after: credentials sitting inside CRM records โ€” AWS keys, Snowflake tokens, passwords
  • ๐Ÿชœ In STRIDE terms: S (a valid token used by the wrong party) and I (bulk disclosure). Nothing was "exploited" in the CVE sense: the integration worked exactly as designed
  • ๐Ÿง  The design-stage question that would have surfaced it: what can this third-party integration's token reach, who can revoke it, and would we see it being used at 3 a.m.? An integration is an arrow crossing a trust boundary, drawn by a vendor rather than by you

๐Ÿค” Think: in Lab 2 the shipped model has exactly one arrow like this โ€” the outbound webhook. What does Threagile say about it?


๐Ÿ“ Slide 16 โ€“ ๐Ÿšจ Case Study: When Nobody Asked "Who Can Reach This?"

Tesla, February 2018. Researchers at RedLock find a Kubernetes administration console belonging to Tesla, running on AWS, with no password on it.

  • ๐Ÿชœ Inside the console: credentials for Tesla's AWS environment, including an S3 bucket with vehicle telemetry
  • โ›๏ธ Attackers were already there, running cryptomining inside a Tesla pod, hiding behind their own mining pool and a Cloudflare-proxied endpoint on a non-standard port
  • ๐Ÿค” In STRIDE terms: S (no authentication at all) plus E (the admin plane is the highest privilege in the cluster)
  • ๐Ÿชœ A thirty-minute session asking "who can reach the admin dashboard, and from where?" surfaces this before the console is ever exposed. This is the cheapest question in the course
  • ๐Ÿง  The general shape: scanners find this only once it is live and reachable. A model finds it while it is still a diagram

๐Ÿ“ Slide 17 โ€“ ๐Ÿง  When You'll Throw the Model Away

  • ๐Ÿชœ Threat models decay as the system changes. Re-run them:
    • โœ… At every major design change (new service, new data flow, new auth scheme)
    • โœ… When the threat landscape shifts (post-Log4Shell: every dep was suddenly a supply-chain concern)
    • โœ… Quarterly, even if nothing changed (the world moves)
  • โš ๏ธ Don't: version-pin a threat model once and forget it. A 3-year-old threat model is roughly as useful as a 3-year-old vuln scan
  • ๐ŸŽฏ In CI: treat the Threagile YAML like any other code artifact โ€” PR review, lint, model-diff in the PR description

๐Ÿ“ Slide 18 โ€“ ๐Ÿชœ Building the Habit in Your Team

  • ๐Ÿงช A pattern that works:
    1. Design doc template has a "Threat Model" section that must be filled before architectural review
    2. Security Champion (from Lecture 1) sits in on the design review and asks STRIDE prompts
    3. Threagile YAML lives in the service repo next to docker-compose.yaml
    4. CI fails the PR if a new high+critical threat appears without a mitigation field
  • ๐Ÿšซ Anti-patterns:
    • Quarterly "threat modeling day" where security team alone does it
    • One model per company, not per service
    • Output is a PDF in SharePoint that nobody opens

๐Ÿ“ Slide 19 โ€“ โญ๏ธ What's Next + What You'll Do

  • ๐Ÿงช Lab 2 (this week):
    • Task 1 (6 pts): run Threagile on the shipped Juice Shop model, rank the risks, map the top five to STRIDE letters
    • Task 2 (4 pts): harden the model, re-run, and account for what the diff did and did not remove
    • Bonus (2 pts): build a second model of the authentication flow from a stub, and find risks the architecture model could not see
  • ๐Ÿš€ Lecture 3 (next week): Secure Git โ€” signed commits, secret scanning, history rewriting. This is where you start implementing the controls that threat models keep recommending
  • ๐ŸŽฏ Threat modeling will feed:
    • Lab 5 (SAST/DAST) โ€” what to focus the scan on
    • Lab 6 (IaC) โ€” which IAM/network risks to prioritize
    • Lab 9 (Runtime) โ€” which behaviors to detect Falco rules for

๐Ÿ“ Slide 20 โ€“ ๐Ÿ“š Resources & Takeaways

Books (one each on threat modeling):

๐Ÿ“– Book โœ๏ธ Why
Threat Modeling: Designing for Security โ€” Adam Shostack (Wiley, 2014) The canonical book; ch. 3 covers STRIDE in depth
Threat Modeling: A Practical Guide for Development Teams โ€” Izar Tarandach & Matthew Coles (O'Reilly, 2021) Modern, agile-aligned; pairs perfectly with Threagile
Securing Systems โ€” Brook Schoenfield (CRC Press, 2015) Architectural risk analysis for senior engineers; harder read

Talks & specs:

Takeaways:

# ๐Ÿง  Insight
1 A design-stage threat is the cheapest threat to fix. Threat modeling is a $0 cost for double-digit ROI.
2 STRIDE pairs with CIA+A+NR โ€” they're two views of the same property set.
3 Trust boundaries are the only arrows you need to scrutinize. Everything in one zone is "trusted by definition."
4 A 30-minute model done quarterly beats a 30-page model done once.
5 Threagile makes threat modeling diffable and runnable in CI โ€” that's how it scales past a single workshop.
6 Hardening a model removes the risks you declared away, not the ones you have to build for. Lab 2 shows a fifth of the list going, and the rest staying.

๐Ÿ’ฌ "All models are wrong, but some are useful." โ€” George Box (1976) โ€” applies to threat models exactly as much as to weather forecasts.


๐Ÿ“š Sources