ENع
→Threat modelling
الدرس 02 · الأسس

Threat modelling

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

12 دقيقة12 خطوة5 أسئلةBeginner
عن هذا الدرس

Threat modelling is thinking through what could go wrong with a system while you design it, so you can fix problems before attackers find them. Follow the four questions on one small online bakery: draw the system and its trust boundary, name what to protect and from whom, use STRIDE to find six kinds of threat, write each one into a Python threat list with its fix, then decide a response for every threat and check the work.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 2 · تفاعلي
01 / 12

Four questions

Threat modelling means thinking through what could go wrong with a system during design, to fix problems before attackers find them. It follows four questions: what are we working on, what can go wrong, what will we do, did we do enough?

threat model   a careful look at what could go wrong
               with a system, done while designing it
  Q1  What are we working on?
  Q2  What can go wrong?
  Q3  What are we going to do about it?
  Q4  Did we do a good enough job?
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Four questions

    Threat modelling means thinking through what could go wrong with a system during design, to fix problems before attackers find them. It follows four questions: what are we working on, what can go wrong, what will we do, did we do enough?

    threat model   a careful look at what could go wrong
                   with a system, done while designing it
      Q1  What are we working on?
      Q2  What can go wrong?
      Q3  What are we going to do about it?
      Q4  Did we do a good enough job?
  2. Q1: draw the system

    First, draw what you are building. Our example is a small online bakery. A customer (outside the shop) sends orders to the web app (a process), which saves them in a database (a data store). Arrows show the data flows.

    Q1  What are we working on?
    a data flow diagram has four kinds of part:
      external entity   the customer
      process           the web app
      data store        the database
      data flow         orders, queries (the arrows)
  3. What we protect, from whom

    Next, name the assets: customer details, password hashes and orders in the database, and the app staying online. Then ask who might cause harm: criminals after data or money, pranksters, or a careless insider. The attacker block stands for all of them.

    assets      what is worth protecting
      database  customer details, password hashes, orders
      web app   the shop staying online
    who         criminals after data or money
                pranksters, a careless or unhappy insider
  4. The trust boundary

    A trust boundary is where data crosses between places we trust differently. Everything arriving from the internet could come from anyone, the attacker included. Most threats cluster where data crosses this line, so look there first.

    trust boundary   where the level of trust changes
    outside          the internet: customer, attacker
    inside           the web app and its database
    rule             treat every message that crosses
                     as possibly hostile until checked
  5. Q2: STRIDE

    To answer "what can go wrong?", check each part against STRIDE: Spoofing, Tampering, Repudiation, Information disclosure, Denial of service, Elevation of privilege. Each letter breaks one security property, such as integrity or availability.

    Q2  What can go wrong?
      S  Spoofing                breaks authentication
      T  Tampering               breaks integrity
      R  Repudiation             breaks non-repudiation
      I  Information disclosure  breaks confidentiality
      D  Denial of service       breaks availability
      E  Elevation of privilege  breaks authorization
  6. S: spoofing the sign-in

    Spoofing: someone signs in as a customer using a stolen or guessed password. We write the threat into our list, a Python dict, with its fix: multi-factor authentication (MFA), so a password alone is not enough.

    S  spoofing   pretending to be someone else
    where         sign-in, crossing the boundary
    mistake       a password is the only proof
    fix           MFA: a second proof, such as a code
    line 2        "S login": "MFA"
  7. T: tampering with an order

    Tampering: the order's price is changed before it reaches the app, for example by editing the page in the browser. The mistake is trusting a price the browser sends. The fix: the app looks up every price itself.

    T  tampering  changing data without permission
    where         the order data flow
    mistake       trusting a price sent by the browser
    fix           the server sets the price from its list
    line 3        "T price": "own price"
  8. R: "I never ordered that"

    Repudiation: a customer says "I never placed that order" and nobody can prove what happened. The fix is an audit log: the app records who did what and when, and keeps that record safe from changes.

    R  repudiation   denying an action, with no proof
    where            the web app
    mistake          no record of who did what
    fix              an audit log: who, what, when
    line 4           "R deny it": "audit log"
  9. I: a data leak

    Information disclosure: customer details leak from the database or its queries. One fix is least privilege: the app gets only the access it needs, so one bug cannot expose everything. Passwords are stored only as hashes, never as plain text.

    I  information disclosure   data reaches the wrong people
    where       the database and its queries
    mistake     the app may read and change everything
    fix         least privilege: only the access it needs
                store password hashes, never passwords
    line 5      "I leak": "least access"
  10. D and E: floods, admin pages

    Denial of service: a flood of requests makes the shop too busy for real customers; fix it with rate limits. Elevation of privilege: a customer reaches the staff admin page; fix it by checking their role on every request.

    D  denial of service    the shop stops answering
       fix                  rate limits per user
    E  elevation of privilege
                            a customer opens a staff page
       fix                  check the role on every request
    lines 6, 7
  11. Q3: decide what to do

    For each threat you choose a response. Mitigate: add a fix, as we did. Eliminate: remove the risky feature. Transfer: make another party responsible, like a payment provider. Accept: write down why the risk is small enough.

    Q3  What are we going to do about it?
      mitigate    add a control (all six here)
      eliminate   remove the feature that causes it
      transfer    make another party responsible
      accept      record why the risk is acceptable
  12. Q4: check the work

    Finally, check: every threat on the list has a decision, and every fix is tested. Our program prints 6, one entry per threat. A threat model is never finished: run it again whenever the design changes.

    Q4  Did we do a good enough job?
      every threat has a decision?   yes
      every fix tested?              do it
      design changed?                model it again
    $ python threats.py
    6

اختبار يتاح بعد الخطوة الأخيرة.