building the ultimate login and signup · 2017. 4. 20. · o protecting passwords in the database o...

59
Building the ultimate login and signup OWASP New Zealand Day 2017 20 April 2017

Upload: others

Post on 04-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Building the ultimate login and

signup

OWASP New Zealand Day 2017

20 April 2017

Page 2: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

$ whoami

PS> $env:username

Matt Cotterell

• Security Engineer @ Fairfax Media (stuff.co.nz and friends)

• Previously Orion Health

• ~5 years professional .NET developer, been dabbling in it for nearly 10 years now!

• Security focus in web tech, particularly around authentication and authorisation flows

@mattcotterellnz

mattcotterellnz

mattcotterellnz

Page 3: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Overview

• Registration

o Get only what you need

o Protecting passwords in the database

o Getting your users to choose good passwords

o Preventing spam accounts

• Before the login

o Password Managers

o Use OS/Browser features

o Password Reset

• During the login

o Securing data in transit

o Session hijacking/fixation

o Dealing with brute forcing attempts

o Protecting your users with two factor authentication

• After they’re logged in

o Open Redirects

o Security Questions

Page 4: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Registration Page

• Identifier (username)• Authentication credential (password)• Other stuff (email, name, phone etc)

Page 5: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Registration Page

Gather only the

information you need

Page 6: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before
Page 7: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before
Page 8: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before
Page 9: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Gather only the information you need, otherwise it is an unnecessary liability

Page 10: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Registration Page

Hash your

passwords (unique

salt, slow algorithm)

Gather only the

information you need

Page 11: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Password Hashing 101

xc3511 -> 3ffa611f12317c42f7847ed69640052c

xc3511 -> 3ffa611f12317c42f7847ed69640052c

xc3511 -> 3ffa611f12317c42f7847ed69640052c

xc3511 -> 3ffa611f12317c42f7847ed69640052c

xc3511 -> 3ffa611f12317c42f7847ed69640052c

xc3511 -> 3ffa611f12317c42f7847ed69640052c

-> 3ffa611f12317c42f7847ed69640052cxc3511

Page 12: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Password Hashing 101 - Take 2

-> beae75e6fc616d3ddda5bf56dd938220

xc3511 + 65d184854bc0aa

-> df1a4e33ba017bf414bbb37545293404

xc3511 + d001ba500ac588

-> afc1996b95d611ba11ae907a329df1b2

xc3511 + bf414bbb37df1a

Page 13: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Password Hashing 101 - Take 2 3

-> b6618740c7a775800e292f74b3cd27c7…

xc3511 + 65d184854bc0aa x 1 iteration

-> fed559ccbc2dd83d10e57133702fa812…

xc3511 + 65d184854bc0aa x 10000 iterations

(~20 µs)

(~200 ms)

Page 14: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Use slow hashes with unique salts

Page 15: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Registration Page

Encourage highly

entropic passwords

Hash your

passwords (unique

salt, slow algorithm)

Gather only the

information you need

Page 16: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Encouraging strong passwords

• Lots of misconceptions about how to choose a password

oBasketball1991!

oqwER43@!

oT!g3r1601

• This isn’t helped by tooling

• This isn’t helped by IT industry leaders

• This isn’t helped by even our own security industry

Page 17: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

https://xkcd.com/936/

Page 18: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Introducing: zxcvbn.js!

• A Javascript library that gives you an extremely easy-to-use password strength meter

• Intelligent, entropy-based strength measurements

oBreaks the password into pieces based off dictionary words, patterns, dates, etc

• Provides recommendations on how to strengthen your passwords as you choose them

• Provides a simple 1 to 5 scoring system as you type

https://github.com/dropbox/zxcvbn

Page 19: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Encourage entropy over patterns, discourage common passwords

Page 20: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Registration Page

Discourage

Automated Signups

Encourage highly

entropic passwords

Hash your

passwords (unique

salt, slow algorithm)

Gather only the

information you need

Page 21: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Preventing spammers from signing up…humans

^

Page 22: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before
Page 23: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Use Google reCAPTCHA, I guess?

asuscreative

Page 24: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Login Page

Page 25: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Before the Login

Let people use

password managers

Page 26: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

<input type=“password” onpaste=“return false;”>

Page 27: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before
Page 28: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before
Page 29: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Do not disable “paste” functionality in password fields

Page 30: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Before the Login

Password Reset

Let people use

password managers

Page 31: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

✉ “Please click https://bank.geek.nz/reset/9cdfb439c7…”

ID Username 🔒 Reset Token Expires

1 mattcotterellnz 9cdfb439c7… 2017-02-28 00:00

$ ./geekbank

🔒 GET https://bank.geek.nz/reset/9cdfb439c7…

🔒 HTTP 200 <change_password.html>

Page 32: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Be careful of social engineering, authenticate user through their email

address

Page 33: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Before the Login

Always use

type=“password” for

password fields

Let people use

password managers

Password Reset

Page 34: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Well, duh? Right?

Page 35: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

*********

May be handled differently in the browser’s memory

Changes behaviour in some situations (such as autocomplete)

Browser will warn users if the page is loaded over unsecure HTTP

Can still be styled

Page 36: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

@luke_dot_js

“…‘secure text input’ is way more than just drawing bullets on screen… don’t try to

fake it…” - @jnadeau

Page 37: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

During the Login

Secure data in transit

Page 38: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

M

I

T

M

M

I

T

M

🔒 POST https://bank.geek.nz/Account/Login <data>

🔒 HTTP 302 <account.html>

$ ./geekbankHTTP 200 <login.html>

GET http://bank.geek.nz/Account/Login

HTTP 200 <login_nohttps.html>HTTP 200 <login.html>

POST http://bank.geek.nz/Account/Login <data>

Page 39: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Use HTTPS everywhere, and not just when sending sensitive data

Page 40: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

During the Login

Mitigate session

hijacking/fixationSecure data in transit

Page 41: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

You should totally click “https://bank.geek.nz/

(s(eW91IGhhdmUgdG9vIG11Y2ggdGltZSBv

biB5b3VyIGhhbmRz))/Account/FreeMoney/”

🔒 POST https://bank.geek.nz/(s(...))/Account/Login <data>

🔒 HTTP 302 </(s(...))/Account/FreeMoney>

🔒 GET https://bank.geek.nz/(s(...))/Account/FreeMoney

🔒 HTTP 401 </(s(...))/Account/Login>…

GET https://bank.geek.nz/(s(eW91IGhhd

mUgdG9vIG11Y2ggdGltZSBvbiB5b3VyI

GhhbmRz))/Account/StealMoney/

$ ./geekbank

🔒 GET https://bank.geek.nz/(s(...))/Account/FreeMoney

🔒 HTTP 404 <pagenotfound.html>

Page 42: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

M

I

T

M

🍪$ ./geekbank

GET http://bank.geek.nz/Account/FreeMoney 🍪

Page 43: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Use HTTPS everywhere, and expire session cookies after every login/logout

Page 44: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

During the Login

Rate limit brute force

attempts

Mitigate session

hijacking/fixationSecure data in transit

Page 45: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

$ ./geekbank🔒 POST https://bank.geek.nz/Account/Login <“aaaaa”>🔒 POST https://bank.geek.nz/Account/Login <“aaaab”>🔒 POST https://bank.geek.nz/Account/Login <“aaaac”>🔒 POST https://bank.geek.nz/Account/Login <“aaaad”>🔒 POST https://bank.geek.nz/Account/Login <“aaaae”>🔒 POST https://bank.geek.nz/Account/Login <“aaaaf”>

Page 46: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

[censored]

Page 47: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

$ ./geekbank🔒 POST https://bank.geek.nz/Account/Login <“password”>🔒 POST https://bank.geek.nz/Account/Login <“123456”>🔒 POST https://bank.geek.nz/Account/Login <“qwerty”>🔒 POST https://bank.geek.nz/Account/Login <“dragon”>🔒 POST https://bank.geek.nz/Account/Login <“monkey”>

🔒 POST https://bank.geek.nz/Account/Login <$yourPetsName>

Page 48: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Block IPs, not accounts. Challenge accounts with CAPTCHAs.

Page 49: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

During the Login

Two Factor

Authentication

Rate limit brute force

attempts

Mitigate session

hijacking/fixationSecure data in transit

Page 50: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Factors of Authentication

Knowledge“Something you know”

Possession“Something you have”

Inherence“Something you are”

• U2F Token

(“Security Key”)• TOTP/HOTP token• SIM Card

• RSA SecurID token• Smart Card• Your Phone/Laptop

• Physical Key

• Fingerprint Scan

• Iris Scan• Facial Recognition• DNA

• Voice Recognition

• Password

• PIN

Page 51: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Use two different factors when authenticating your users

Page 52: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

After the Login

Open Redirects

Page 53: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

https://bit.ly/2mqAGDA

Warning: this is a malicious link!

Username: owaspdayPassword: OWASPday2017!Two Factor Token: (blank)

Page 54: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Ensure user-controlled redirects go to a domain you control

Page 55: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

After the Login

Open Redirects Security Questions

Page 56: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Factors of Authentication

Knowledge“Something you know”

Possession“Something you have”

Inherence“Something you are”

• U2F Token

(“Security Key”)• TOTP/HOTP token• SIM Card

• RSA SecurID token• Smart Card• Your Phone/Laptop

• Physical Key

• Fingerprint Scan

• Iris Scan• Facial Recognition• DNA

• Voice Recognition

• Password

• PIN

This does not mean “something you and a bunch of other people“ know!

Page 57: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

“Although your family and friends might know the answers to [your security questions], your access

number and confidential password is the protection you have to keep your banking private from them.”

Page 58: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

Security Questions don’t reliably authenticate an individual, and are easily

predicted

Also, I’m 27 years old, I don’t have a favourite colour.

Page 59: Building the ultimate login and signup · 2017. 4. 20. · o Protecting passwords in the database o Getting your users to choose good passwords o Preventing spam accounts • Before

All that just to allow logins?

•If you have any questions, please feel free to ask!

•I’ll be around during the break…

•…or message me on Twitter!

@mattcotterellnz

mattcotterellnz

mattcotterellnz