cs 253: web security 01.pdfnode.js • javascript on the command line • adds built-in functions...

52
CS 253: Web Security 1 Feross Aboukhadijeh

Upload: others

Post on 29-May-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

CS 253: Web Security

1 Feross Aboukhadijeh

Page 2: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Administrative Stuff• Website: cs253.stanford.edu• 5-6 assignments• 7-8 guest lectures• Use Piazza for questions• Share anonymous feedback (use form on website)• Assignment 0 released tonight

2 Feross Aboukhadijeh

Page 3: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

3 Feross Aboukhadijeh

Page 4: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Origins of this course• CS 241: Secure Web Programming• Last taught in 2011 by Dan Boneh and John Mitchell• My favorite class at Stanford• Inspired me to start looking for vulnerabilities• I wanted to bring back the course – that's what CS 253 is!

4 Feross Aboukhadijeh

Page 5: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Some stories

5 Feross Aboukhadijeh

Page 6: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

6 Feross Aboukhadijeh

Page 7: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Every site can store 5 MB1.filldisk.com2.filldisk.com3.filldisk.com4.filldisk.com5.filldisk.com6.filldisk.com7.filldisk.com... and so on ...

7 Feross Aboukhadijeh

Page 8: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

8 Feross Aboukhadijeh

Page 9: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Goal #1The attacker mindset

9 Feross Aboukhadijeh

Page 10: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Goal #2The defender mindset

10 Feross Aboukhadijeh

Page 11: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Extra credit policy• Anyone who finds a web security vulnerability during the quarter

will receive extra credit (1 to 50 points)• YOU MUST USE RESPONSIBLE DISCLOSURE

• If Stanford web app, must use Stanford Bug Bounty program• Do not attack servers you do own, do not destroy data• You are responsible for your own actions• If you are unsure, come speak with us

11 Feross Aboukhadijeh

Page 12: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Why is computer security hard?• Lots of buggy code• Social engineering is very effective• There's money to be made by finding and exploiting vulnerable

systems• Marketplace for vulnerabilities• Marketplace for owned machines / stolen data• Many methods to profit from owned machines / stolen data

12 Feross Aboukhadijeh

Page 13: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Why attack a computer system?• Spam

• Sent from legitimate IP address, less likely to be blocked• Denial of service

• Attack competitors, or seek ransom• Infect visiting users with malware

• Infect one server, use it to infect hundreds of thousands of clients• Data theft

• Steal credentials, credit card numbers, intellectual property

13 Feross Aboukhadijeh

Page 14: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

14 Source: California Breach Notification Report, 2016

Page 15: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Why attack a computer system in 2019?• Mine cryptocurrency• Ransomware• Political motivation

15 Feross Aboukhadijeh

Page 16: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

What is web security?• Browser security

• e.g. Same Origin Policy – Isolate sites from each other, while running in the same browser

16 Feross Aboukhadijeh

Page 17: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

17 Feross Aboukhadijeh

Page 18: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

18 Feross Aboukhadijeh

Page 19: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

What is web security?• Server app security

• Attackers can run arbitrary HTTP clients; can send anything to server

19 Feross Aboukhadijeh

Page 20: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

curl -d '{"user":"Alice", "permission":"admin"}' -H "Content-Type: application/json" -X POST http://example.com/data

20 Feross Aboukhadijeh

Page 21: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

What is web security?• Client app security

• Prevent user from being attacked while using web app locally

21 Feross Aboukhadijeh

Page 22: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

22 Feross Aboukhadijeh

Page 23: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

23 Feross Aboukhadijeh

Page 24: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Creates a new admin user with these credentials:

• Username: wpservices• Password: w0rdpr3ss

24 Feross Aboukhadijeh

Page 25: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

What is web security?• Protect the user

• From social engineering• From trackers, private data being leaked

25 Feross Aboukhadijeh

Page 26: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

26 Feross Aboukhadijeh

Page 27: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

27 Feross Aboukhadijeh

Page 28: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Why is web security hard?• Extremely ambitious goal – Run untrusted code securely• Different sites interacting in the same tab ("mashups")• Low-level features; hardware access• Desire for high performance• APIs were not designed from first principles; evolved• Strict backwards compatibility requirements

• "Don't break the web"28 Feross Aboukhadijeh

Page 29: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

"Modern web applications are built on a tangle of technologies that have been developed over time and then haphazardly pieced together. Every piece of the web application stack, from HTTP requests to browser-side scripts, comes with important yet subtle security consequences. To keep users safe, it is essential for developers to confidently navigate this landscape."

– Tangled Web

29 Feross Aboukhadijeh

Page 30: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

The browser has a seemingly impossible task

Sites – even malicious ones – can:

• Download content from anywhere• Spawn worker processes• Open sockets to a server, or even to another user's browser• Display media in a huge number of formats• Run custom code on the GPU• Save/read data from the filesystem

30 Feross Aboukhadijeh

Page 31: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Differing visions for the web• Simple document viewer?• Powerful application platform?

31 Feross Aboukhadijeh

Page 32: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

The web is robust"It's is all too easy to criticize, lament, and create paranoid scenarios about the 'unsound security foundations' of the web. Truth is, all of that criticism is true, and yet the web has proven to be an incredibly robust platform."

– Ilya Grigorik, Google web performance engineer

32 Feross Aboukhadijeh

Page 33: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Goal #3Learn to architect secure systems

33 Feross Aboukhadijeh

Page 34: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

This course• Part 1: Browser security model, Same origin policy• Part 2: Client security: attacks, defense• Part 3: Server security: attacks, defense, authentication, TLS• Part 4: Writing secure code

34 Feross Aboukhadijeh

Page 35: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

HTML

35 Feross Aboukhadijeh

Page 36: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

36 Feross Aboukhadijeh

Page 37: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Introduction

This article is a review of the book Dietary Preferences of Penguins, by AliceJones and Bill Smith. Jones and Smith's controversial work makes threehard-to-swallow claims about penguins:

First, that penguins actually prefer tropical foods such as bananas andpineapple to their traditional diet of fish

Second, that tropical foods give penguins an odor that makes them unattractiveto their traditional predators

37 Feross Aboukhadijeh

Page 38: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

<h1>Introduction</h1>

<p> This article is a review of the book Dietary Preferences of Penguins, by Alice Jones and Bill Smith. Jones and Smith's controversial work makes three hard-to-swallow claims about penguins:</p>

<ul> <li> First, that penguins actually prefer tropical foods such as bananas and pineapple to their traditional diet of fish </li>

<li> Second, that tropical foods give penguins an odor that makes them unattractive to their traditional predators </li></ul>

38 Feross Aboukhadijeh

Page 39: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

39 Feross Aboukhadijeh

Page 40: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

<!doctype html><html lang='en'> <head> <meta charset='utf-8' /> <title>Dietary Preferences of Penguins</title> </head> <body> <h1>Introduction</h1>

<p> This article is a review of the book Dietary Preferences... </p> </body></html>

40 Feross Aboukhadijeh

Page 41: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Uniform Resource Locators (URLs)

41 Feross Aboukhadijeh

Page 42: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Ways to specify a URL• Full URL: <a href='http://stanford.edu/news/2019/'>2019 News</a>• Relative URL: <a href='september'>September News</a>

• Same as http://stanford.edu/news/2019/september• Absolute URL: <a href='/events'>Events</a>

• Same as http://stanford.edu/events• Fragment URL: <a href='#section3'>Jump to Section 3</a>

• Scrolls to <a name='section3' /> within page

• Same as http://stanford.edu/events#section3

42 Feross Aboukhadijeh

Page 43: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Lots of HTML tags• <img>• <video>, <audio>• <canvas>• <link>, <style>• <script>

43 Feross Aboukhadijeh

Page 44: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Include CSS in a page<!-- External CSS file --><link rel='stylesheet' href='/path/to/styles.css' />

<!-- Inline CSS --><style> body { color: hot-pink; }</style>

44 Feross Aboukhadijeh

Page 45: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Include JavaScript in a page<!-- External JS file --><script src='/path/to/script.js'></script>

<!-- Inline JS --><script> window.alert('hi there!')</script>

45 Feross Aboukhadijeh

Page 46: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

JavaScript• Fun• Flexible• Immediate feedback• Pre-installed on every device in the world• Dev environment is pre-installed too, so easy to start writing code

46 Feross Aboukhadijeh

Page 47: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Node.js• JavaScript on the command line• Adds built-in functions for filesystem, HTTP, DNS, and sockets

• Stuff that belongs in a scripting language, but not a browser• Also adds module system, binary data support

• Less necessary because JavaScript has improved rapidly

47 Feross Aboukhadijeh

Page 48: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

"JavaScript APIs"• "JavaScript APIs" can come from:

• JavaScript language specification• Document Object Model specification (browser)• Node.js built-ins

• Examples:

• Array• document.createElement• fs.readFile

48 Feross Aboukhadijeh

Page 49: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Crusty browser APIs• window.open()• window.moveTo()• window.resizeTo()

49 Feross Aboukhadijeh

Page 50: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

Demo: Window breakout game

50 Feross Aboukhadijeh

Page 51: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

51 Feross Aboukhadijeh

Page 52: CS 253: Web Security 01.pdfNode.js • JavaScript on the command line • Adds built-in functions for filesystem, HTTP, DNS, and sockets • Stuff that belongs in a scripting language,

END

52 Feross Aboukhadijeh