weird tricks to improve web security 10000000%how 2 pwn websites 1. code injection attacks 2....

37
Weird Tricks to Improve Web Security 10000000% Yan, TXJS 2015

Upload: others

Post on 30-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Weird Tricks to Improve

Web Security 10000000%

Yan, TXJS 2015

Page 2: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

“Security is sooo tedious.”

- Anonymous web developer

Page 3: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

It’s not you, it’s us.(usually)

Page 4: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

We need to make security easy by default.

Page 5: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

how 2 pwn websites

1. Code injection attacks2. Man-in-the-Middle attacks

Not covered here: social engineering, phishing, physical access to devices, browser/OS vulnerabilities, TLS vulnerabilities

Page 6: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Problem #1:User input can cause scripts to be executed on your site that you didn’t intend.

Page 7: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

The Great Tweetdeck XSS of June 2014

Page 8: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access
Page 9: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

// Replace emoji characters in the tweet with <img> tags

var emojified = this.emoji.parse(tweet.nodeValue);

// Make a new div, set innerHTML to the emojified value

newDiv.innerHTML = emojified; // DANGER!!

// DOM surgery to replace the original tweet text with emojified

var i = document.createDocumentFragment();

while (newDiv.hasChildNodes()) {

i.appendChild(newDiv.firstChild);

}

tweet.parentNode.replaceChild(i, tweet); // script executes :(

What happened?

Page 10: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access
Page 11: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access
Page 12: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Content Security Policy

Solution:Tell the browser, “Only allow resources of Type X from Origin Y (and/or disallow inline scripts) on this page.”

Page 13: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Content Security Policy

1. Set your Content Security Policy as an HTTP Header.Content-Security-Policy: img-src *.cdn.example.com; script-src ‘self’ https://apis.google.com2. Profit:

Page 14: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access
Page 15: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access
Page 16: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Setting up CSP

1. Run in report-only mode to determine the minimally-permissive policy for your site

2. Switch to enforce mode after “enough” testing

Page 17: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Github’s CSP header

Page 18: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

CSP + Refer(r)ers

Referrers are annoying.

Page 19: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

OK!!Let’s click on this!

Page 20: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access
Page 21: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Dropbox, May 2014

Page 22: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Google, June 2014

Page 23: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

CSP to the rescue (again)

Set the “referrer” CSP directive to one of:● “no-referrer”● “no-referrer-when-downgrade” (default)● “origin”● “origin-when-cross-origin”● “unsafe-url”

Page 24: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Source: http://caniuse.com/

Page 25: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Why don’t people use CSP?

● Boring name● ???

Page 26: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Solution

BATSHIELD: Back-Acronymed TrustworthySecure Helper Internet-Enabled Lightweight Defense

Page 27: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

HTTPS

Without HTTPS, websites cannot guarantee:● Server authentication● Data confidentiality● Data integrity

Page 28: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

June, 2014

Page 29: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

(╯°□°)╯︵ ┻━┻

:(

June, 2015

Page 30: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Problem #2:Setting up SSL is usually tedious and costs $.

Page 31: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access
Page 32: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Let’s Encrypt

Solution:Start a certificate authority that gives out free certificates.

Page 33: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Let’s Encrypt

. . . And provide a server package that automates domain validation, certificate issuance, SSL configuration, and certificate renewal.

Technical details: https://github.com/letsencrypt/acme-spec/

Page 35: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

Let’s Encrypt

https://letsencrypt.orgLaunching the week of Sept. 14, 2015

Page 36: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

On the Horizon:

● Subresource Integrity● Fixing mixed content● Privacy/security standards for W3C specs● Restricting new web features to HTTPS only● User-to-user encrypted messaging on the

web

Page 37: Weird Tricks to Improve Web Security 10000000%how 2 pwn websites 1. Code injection attacks 2. Man-in-the-Middle attacks Not covered here: social engineering, phishing, physical access

[email protected]@yahoo-inc.comTwitter: @bcrypt