Web Security Thierry Sans Securing the web architecture means - - PowerPoint PPT Presentation

web security
SMART_READER_LITE
LIVE PREVIEW

Web Security Thierry Sans Securing the web architecture means - - PowerPoint PPT Presentation

Web Security Thierry Sans Securing the web architecture means securing ... The network The operating system The web server ( Apache for instance) The administration server ( SSH for instance) The database ( Oracle for instance)


slide-1
SLIDE 1

Web Security

Thierry Sans

slide-2
SLIDE 2

Securing the web architecture means securing ...

  • The network
  • The operating system
  • The web server (Apache for instance)
  • The administration server (SSH for instance)
  • The database (Oracle for instance)
  • The web application

Our focus here!

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8

Vulnerability Likelihood source “WhiteHat Website Security Statistics report 2017” from WhiteHat Security

slide-9
SLIDE 9

Most serious vulnerabilities by class source “WhiteHat Website Security Statistics report 2017” from WhiteHat Security

slide-10
SLIDE 10

Insufficient Transport Layer Protection a.k.a the need for HTTPs

slide-11
SLIDE 11

How to steal user’s credentials

➡ Brute force the user’s password or session ID ➡ Steal the user’s password or session ID

slide-12
SLIDE 12

Do you trust the network?

๏ Threat 1 : an attacker can eavesdrop messages sent back and forth

interesting!

slide-13
SLIDE 13

Do you really trust the network?

๏ Threat 2 : an attacker can tamper with messages sent back and

forth

I am example.com!

example.com

slide-14
SLIDE 14

Confidentiality and Integrity

๏ Threat 1 : an attacker can eavesdrop messages sent back and

forth Confidentiality: how do exchange information secretly?

๏ Threat 2 : an attacker can tamper messages sent back and forth

Integrity: How do we exchange information reliably?

slide-15
SLIDE 15

Generic solution - HTTPS

✓ HTTPS = HTTP + TLS ➡ Transport Layer Security (TLS previously known as SSL)

provides

  • confidentiality: end-to-end secure channel
  • integrity: authentication handshake
slide-16
SLIDE 16

Generating and using (self-signed) certificates

who are you? I am example.com

slide-17
SLIDE 17

Self-signed certificates are not trusted by your browser

slide-18
SLIDE 18

Signed Certificate

who are you?

Certificate Authority (CA)

I am example.com

slide-19
SLIDE 19

Your browser trusts many CAs by default

slide-20
SLIDE 20

Real attacks

slide-21
SLIDE 21

Why and when using HTTPS?

HTTPS = HTTP + TLS

➡ TLS provides

  • confidentiality: end-to-end secure channel
  • integrity: authentication handshake

➡ HTTPS protects any data send back and forth including:

  • login and password
  • session ID

✓ HTTPS everywhere

HTTPS must be used during the entire session

slide-22
SLIDE 22

Be careful of mixed content

Mixed-content happens when:

  • 1. an HTTPS page contains elements (ajax, js, image, video,

css ...) served with HTTP

  • 2. an HTTPS page transfers control to another HTTP page

within the same domain ๏ authentication cookie will be sent over HTTP

slide-23
SLIDE 23

Secure cookie flag

✓ The cookie will be sent over HTTPS exclusively ➡ Prevents authentication cookie from leaking in case of mixed-

content

slide-24
SLIDE 24

Do/Don't with HTTPS

  • Always use HTTPS exclusively (in production)
  • Always have a valid and signed certificate (no self-signed cert)
  • Always avoid using absolute URL (mixed-content)
  • Always use secure cookie flag with authentication cookie
slide-25
SLIDE 25

Limitation of HTTPS

slide-26
SLIDE 26

Problem

Server Side Client Side

Web Server Database Web Browser

You have absolutely no control

  • n the client and the network
slide-27
SLIDE 27

Beyond HTTPS - attacking the web application

  • Content Spoofing
  • Cross-Site Scripting
  • Cross-site Request forgery
  • Incomplete mediation
  • Information leakage
  • SQL injection

Frontend Vulnerabilities Backend Vulnerabilities

slide-28
SLIDE 28

Incomplete Mediation

slide-29
SLIDE 29

The Shopping Cart Attack

  • rder=(#2956,10,9,90)

Server Trusted Domain Client Trusted Domain

* Notice that Amazon is not vulnerable to this attack

* Thank you for your order! The total is calculated by a script on the client The order is generated based on the request

10

slide-30
SLIDE 30

The backend is the only trusted domain

๏ Data coming from the frontend cannot be trusted ✓ Sensitive operations must be done on the backend

slide-31
SLIDE 31

Information Leakage

slide-32
SLIDE 32

Information Leakage

“AT&T Inc. apologized to Apple Inc. iPad 3G tablet computer users whose e-mail addresses were exposed during a security breach disclosed last week.” source Business Week - June 14 2010 “There’s no hack, no infiltration, and no breach, just a really poorly designed web application that returns e-mail address when ICCID is passed to it.” source Praetorian Prefect - June 9 2010

slide-33
SLIDE 33

Solution

✓ Authentication

  • Who are the authorized users?

✓ Authorization

  • Who can access what and how?
slide-34
SLIDE 34

SQL Injection

slide-35
SLIDE 35

Problem

➡ An attacker can inject SQL/NoSQL code ๏ Retrieve, add, modify, delete information ๏ Bypass authentication

slide-36
SLIDE 36

Checking password

name=Alice&pwd=pass4alice /signin/ signin.html Access Granted!

slide-37
SLIDE 37

SQL Injection

db.run("SELECT * FROM users 
 WHERE USERNAME = '" + username + "'
 AND PASSWORD = '" + password + "'" username: alice
 password: pass4alice blah' OR '1'='1

slide-38
SLIDE 38

NoSQL Injection

db.find({ username: username, 
 password: password }); username: alice
 password: pass4alice {gt: ""}

slide-39
SLIDE 39

Content Spoofing

slide-40
SLIDE 40

comment = “<a href=”myad.com”>Fun stuff ... * Notice that Youtube is not vulnerable to this attack GET /?videoid=527 <html ... GET /?videoid=527 <html ...

Content Spoofing

The page contains the attacker’s ad.

slide-41
SLIDE 41

Problem

➡ An attacker can inject HTML tags in the page ๏ Add illegitimate content to the webpage

(ads most of the time)

slide-42
SLIDE 42

Generic Solution

✓ Data inserted in the DOM must be validated

slide-43
SLIDE 43

Cross-Site Scripting (XSS)

slide-44
SLIDE 44

Cross-Site Scripting Attack (XSS attack)

name=CMU “Hello CMU!”

“Hello <script language="javascript">alert(“XSS attack”);</script>!” name=<script language="javascript">alert(“XSS attack”);</script>

slide-45
SLIDE 45

XSS Attack = Javascript Code Injection

slide-46
SLIDE 46

Problem

➡ An attacker can inject arbitrary javascript code

in the page that will be executed by the browser

๏ Inject illegitimate content in the page

(same as content spoofi ng)

๏ Perform illegitimate HTTP requests through Ajax

(same as a CSRF attack)

๏ Steal Session ID from the cookie ๏ Steal user’s login/password by modifying the page to

forge a perfect scam

slide-47
SLIDE 47

comment = “<script> ... * Notice that Youtube is not vulnerable to this attack login=Alice&password=123456 GET /?videoid=527 <html ... GET /?videoid=527 <html ...

The script contained in the comments modifies the page to look like the login page!

Forging a perfect scam

slide-48
SLIDE 48

It gets worst - XSS Worms

Spread on social networks

  • Samy targeting MySpace (2005)
  • JTV.worm targeting Justin.tv (2008)
  • Twitter worm targeting Twitter (2010)
slide-49
SLIDE 49

XSS attacks are widespread

slide-50
SLIDE 50

Variations on XSS attacks

  • Reflected XSS

Malicious data sent to the backend are immediately sent back to the frontend to be inserted into the DOM

  • Stored XSS

Malicious data sent to the backend are store in the database and later-on sent back to the frontend to be inserted into the DOM

  • DOM-based attack

Malicious data are manipulated in the frontend (javascript) and inserted into the DOM

slide-51
SLIDE 51

Solution

✓ Data inserted in the DOM must be validated

slide-52
SLIDE 52

HttpOnly cookie flag

✓ The cookie is not readable/writable from the frontend ➡ Prevents the authentication cookie from being leaked when

an XSS attack (cross-site scripting) occurs

slide-53
SLIDE 53

Cross-Site Request Forgery

slide-54
SLIDE 54

Ajax requests across domains

http://B.com http://A.com

The browser does not allow js code from domain A to access resources from B ➡ Only HTTP response is blocked

slide-55
SLIDE 55

Same origin policy

➡ Resources must come from the same domain

(protocol, host, port) Elements under control of the same-origin policy

  • Ajax requests
  • Form actions

Elements not under control of the same-origin policy

  • Javascript scripts
  • CSS
  • Images, video, sound
  • Plugins
slide-56
SLIDE 56

Examples

client server

same protocol, port and host

http://example.com http://example.com http://user:pass@example.com http://example.com

top-level domain

http://example.com http://example.org

host

http://example.com http://other.com

sub-host

http://www.example.com http://example.com

sub-host

http://example.com http://www.example.com

port

http://example.com:3000 http://example.com

protocol

http://example.com https://example.com

slide-57
SLIDE 57

[digression] relaxing the same-origin policy

  • Switch to the superdomain with javascript

www.example.com can be relaxed to example.com

  • iframe
  • JSONP
  • Cross-Origin Resource Sharing (CORS)
slide-58
SLIDE 58

Problem

➡ An attacker can executes unwanted but yet authenticated

actions on a web application by either

  • setting up a malicious website with cross-origin requests
  • or by injecting malicious urls into the page
slide-59
SLIDE 59

GET View/?profileid=53 GET Delete/?profileid=53

??? ......

GET setProfile/?url=Delete/?profileid=53 GET View/?profileid=86 <img src=”Delete/?profileid=53 GET Delete/?profileid=53

Hey Alice, check my profile

id url name 53 www.alice.com/ profilepic Alice 86 www.badwebsite.com/ Delete/?imageid=53 Charlie

www.badwebsite.com

<img src=”www.alice.com/profilepic Done! profileid=86 GET profilepic www.alice.com

slide-60
SLIDE 60

Generic solution - CSRF tokens

✓ Protect legitimate requests with a CSRF token

GET /getFormView response POST request

CSRF Token

POST request

slide-61
SLIDE 61

SameSite cookie flag

✓ The cookie will be not be sent over cross-site requests ➡ Prevents forwarding the authentication cookie over cross-

  • rigin requests (cross-site request forgery)