Unit 7: Logins, MFA and tokens · Lesson 1 of 7 · 16 min

How a login works

The server never compares your password itself, only a hash of it.

mission

You are
The analyst reviewing the shop's sign-in.
Situation
Before reviewing password storage, you want to know exactly what the sign-in form sends and how the server answers success and failure.
Goal
Compare the responses to a right and a wrong password.
Hand in
The differences between success and failure, header by header.

Checking a password

0/5
browsershop apppassword storePOST user, passwordlook up userhash(password, salt)compare in constant time303 and cookie, or 401

Press play or step through.

01

A wrong password

learner@web-lab
curl -si -d 'user=learner&password=wrong' http://127.0.0.1:8000/login | grep -iE '^(HTTP|set-cookie|cache)'
HTTP/1.1 401 Unauthorized
Cache-Control: no-store

you should see 401, no cookie, and no-store so the page is never cached.

curl
Sends web requests and prints the response. Built into Linux, macOS and Windows 10 and later.
grep
Prints the lines of text that match a pattern. Built into Linux and macOS.
02

A user that does not exist

learner@web-lab
curl -s -d 'user=nobody&password=wrong' http://127.0.0.1:8000/login | grep Wrong
<p>Wrong user or password.</p>
curl -s -d 'user=learner&password=wrong' http://127.0.0.1:8000/login | grep Wrong
<p>Wrong user or password.</p>

you should see Identical messages. Nobody can use the form to find out which accounts exist.

03

The right password

learner@web-lab
curl -si -d @shop-account.txt http://127.0.0.1:8000/login | grep -iE '^(HTTP|location)'
HTTP/1.1 303 See Other
Location: /account

you should see 303 to the account page, plus the session cookies you met earlier.

04

Is the login page cached?

learner@web-lab
curl -sI http://127.0.0.1:8000/login | grep -i cache-control
Cache-Control: no-store

you should see no-store: a shared computer will not keep a copy of the form or its answers.

What a defender takes away

  1. 1Failures should look the same whether the user exists or not.
  2. 2Sign-in responses must never be cached.
  3. 3The server only ever compares hashes.

Questions

0 of 2 solved

Answer each one from what you find on your lab machine.

  1. Show hint

    curl -si ... | grep -ci set-cookie