Labs / Security Basics / Design review

Lab 1 of 1 · Design review

Threat modelling: four questions before a new app goes live

Review a new loan-desk app before it goes live: draw its data flows, mark trust boundaries, ask STRIDE's six questions and confirm three gaps.

Start this lab 7 steps

The idea

Copperbeech Tool Library lends drills and ladders to its neighbourhood, and on Monday its loan desk moves from a paper book to Lendbook, a program one of the volunteers wrote. Thandi, who chairs the library, has one question for Mirela, who looks after its computers: is it safe? Answer her the way software teams do before a release: draw how the data moves, then ask what can go wrong wherever it changes hands.

A front page is not a design
A front page is not a design
Four commands, one picture
Four commands, one picture
Lendbook's data-flow diagram
Lendbook's data-flow diagram
Six questions, six properties
Six questions, six properties
The path is not an end
The path is not an end
Who came in, not what they did
Who came in, not what they did
Every finding gets a decision
Every finding gets a decision

Steps

  1. Is it safe?

    Mirela can't answer Thandi with a scan for known flaws. A scan finds published flaws in the parts Lendbook is built from. It can't find a safeguard that its design never had.

    Software teams have a method for this moment, called threat modelling: a review of a design before it goes into use. It rests on four questions.

    1. "What are we working on?"
    2. "What can go wrong?"
    3. "What are we going to do about it?"
    4. "Did we do a good enough job?"

    Open Lendbook's front page from frontDesk, the machine at the loan desk.

    frontDesk:~# curl -s http://10.0.12.10/
  2. Question 1: draw what is running

    The honest answer to "what are we working on?" comes from the running machines, not from what anyone remembers building. Four things go into the picture: the programs that run, the places data is kept, the people who use it, and every path data takes between them.

    A program that other machines talk to waits on a port, so a list of waiting ports is a list of the programs that take calls. The lab Ports and sockets: one address, many programs teaches that list.

    Joost, the volunteer who wrote Lendbook, set it up on two machines. List the waiting ports on both. Then read the app's settings, and look in the folder where the data is kept.

    appServer:~# ss -ltnp
    dataServer:~# ss -ltnp
    appServer:~# cat /etc/lendbook/app.conf
    dataServer:~# ls -l /srv/lendbook
  3. Mark where trust changes

    One more kind of line gives the picture its value. Not everyone who touches Lendbook is trusted alike. Four members of staff have their own passwords, and the screen in the public room is used by whoever walks in.

    A trust boundary is a line in the picture with differently trusted people or programs on its two sides. Data that crosses one leaves somebody's control, so every crossing is a place to stop and ask questions.

    Lendbook's file of roles says who is trusted with what. Read it. Then stand where the least trusted user stands: on memberKiosk, search the catalogue, and ask for the members page.

    appServer:~# cat /etc/lendbook/roles.conf
    memberKiosk:~# curl -s "http://10.0.12.10/catalogue?q=drill"
    memberKiosk:~# curl -s http://10.0.12.10/members
  4. Question 2: six questions at every crossing

    "What can go wrong?" is too wide a question. Reviewers narrow it to six, asked at each crossing. Their first letters spell STRIDE.

    • Spoofing: is the caller who it claims to be, and does anything check? Someone at the desk types a colleague's name.
    • Tampering: can data be changed on the way, or where it is kept? A due date is altered.
    • Repudiation: can somebody deny an action because nothing recorded it? "I never closed that loan."
    • Information disclosure: can somebody see what they shouldn't? A visitor reads members' phone numbers.
    • Denial of service: can it be made to stop? The desk can't lend.
    • Elevation of privilege: can somebody do more than their role allows? The kiosk closes a loan.

    Ask the first at the quiet crossing. The data service expects one caller, the app. Call its status page from memberKiosk.

    memberKiosk:~# curl -sS -m 3 http://10.0.12.20:5000/
  5. The path between the two programs

    The same crossing, a different question: can the data be read or changed on the way?

    Every time someone at the desk opens the members page, names and phone numbers travel from dataServer to appServer. On that path the data is outside both programs. Whether another machine on the network could read it or change it there depends on whether the two programs encrypt what they say to each other.

    A web address that starts with https means the conversation is encrypted with TLS, and the caller can check who answers. One that starts with http means plain text. The lab HTTPS and TLS: lock a site and prove who it is teaches how.

    The owner doesn't have to listen on the network to find out. The app's settings say which. Print the line.

    appServer:~# grep data_url /etc/lendbook/app.conf
  6. An action nobody could prove

    The R of STRIDE is the question that gets skipped, because nothing looks broken. Repudiation asks: after an action, does a record say who did it?

    Lendbook had a trial run yesterday evening, with the paper book typed in. Somebody at the desk closed the loan of a cordless drill, T-0449.

    Say the drill is missing. Without a record, every member of staff can say "not me".

    The check needs no new action: the data holds the return, and the log holds what the app wrote that evening.

    On dataServer, print the last line of the loans file. Then read the app's log on appServer.

    dataServer:~# tail -n 1 /srv/lendbook/loans.csv
    appServer:~# cat /var/log/lendbook/app.log
  7. Questions 3 and 4: decide, then check

    A finding isn't finished until somebody decides what happens to it. A decision is one of four.

    • Mitigate: add a safeguard, so it is less likely or does less harm.
    • Avoid: drop the feature or the part that carries the risk.
    • Transfer: hand the cost to somebody else, by contract or insurance.
    • Accept: live with it on purpose, with the reason written down.

    Which finding comes first is a ranking. Mirela scored each one by how likely it is and how bad, as in the lab Risk scoring: turn a pile of findings into a ranked queue. Read her list.

    frontDesk:~# cat /srv/review/register.txt

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab