CSE 127 Computer Security

Similar documents
SQL Injection. EECS Introduction to Database Management Systems

NET 311 INFORMATION SECURITY

This slide shows the OWASP Top 10 Web Application Security Risks of 2017, which is a list of the currently most dangerous web vulnerabilities in

Web Application Security. Philippe Bogaerts

Excerpts of Web Application Security focusing on Data Validation. adapted for F.I.S.T. 2004, Frankfurt


Application vulnerabilities and defences

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

C1: Define Security Requirements

Web Application & Web Server Vulnerabilities Assessment Pankaj Sharma

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

CSCE 813 Internet Security Case Study II: XSS

Ruby on Rails Secure Coding Recommendations

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

Copyright

CS 161 Computer Security

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

Advanced Web Technology 10) XSS, CSRF and SQL Injection

1 About Web Security. What is application security? So what can happen? see [?]

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

Provide you with a quick introduction to web application security Increase you awareness and knowledge of security in general Show you that any

Configuring User Defined Patterns

Exploiting and Defending: Common Web Application Vulnerabilities

Perslink Security. Perslink Security. Eleonora Petridou Pascal Cuylaerts. System And Network Engineering University of Amsterdam.

HP 2012 Cyber Security Risk Report Overview

Aguascalientes Local Chapter. Kickoff

OWASP TOP 10. By: Ilia

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

Andrew Muller, Canberra Managing Director, Ionize, Canberra The challenges of Security Testing. Security Testing. Taming the Wild West

OWASP TOP Release. Andy Willingham June 12, 2018 OWASP Cincinnati

Security. CSC309 TA: Sukwon Oh

A D V I S O R Y S E R V I C E S. Web Application Assessment

John Coggeshall Copyright 2006, Zend Technologies Inc.

Web Security: Web Application Security [continued]

CSCE 548 Building Secure Software SQL Injection Attack

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

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

A1 (Part 2): Injection SQL Injection

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

CS 161 Computer Security

COMP9321 Web Application Engineering

Finding Vulnerabilities in Web Applications

Integrity attacks (from data to code): Malicious File upload, code execution, SQL Injection

COMP9321 Web Application Engineering

Web Application Vulnerabilities: OWASP Top 10 Revisited

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

SQL Injection Attack Lab

Security issues. Unit 27 Web Server Scripting Extended Diploma in ICT 2016 Lecture: Phil Smith

Slides adopted from Laurie Williams. OWASP Top Ten. John Slankas

Web Penetration Testing

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

WELCOME. APEX Security Primer. About Enkitec. About the Presenter. ! Oracle Platinum Partner! Established in 2004

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

Security. 1 Introduction. Alex S. 1.1 Authentication

Solution of Exercise Sheet 5

epldt Web Builder Security March 2017

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

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

Application Layer Security

Web Security: Vulnerabilities & Attacks

3. WWW and HTTP. Fig.3.1 Architecture of WWW

Web Security Computer Security Peter Reiher December 9, 2014

CIS 4360 Secure Computer Systems XSS

W e b A p p l i c a t i o n S e c u r i t y : T h e D e v i l i s i n t h e D e t a i l s

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

OWASP Top 10 The Ten Most Critical Web Application Security Risks

CS 155 Project 2. Overview & Part A

MWR InfoSecurity Security Advisory. Oracle Enterprise Manager SQL Injection Advisory. 1 st February 2010

Application Security Introduction. Tara Gu IBM Product Security Incident Response Team

Jacksonville Linux User Group Presenter: Travis Phillips Date: 02/20/2013

Security Course. WebGoat Lab sessions

GUI based and very easy to use, no security expertise required. Reporting in both HTML and RTF formats - Click here to view the sample report.

DreamFactory Security Guide

(System) Integrity attacks System Abuse, Malicious File upload, SQL Injection

Maximizing the speed of time based SQL injection data retrieval

A1 (Part 1): Injection Command and Code injection

Webapps Vulnerability Report

P2_L12 Web Security Page 1

CNIT 129S: Securing Web Applications. Ch 12: Attacking Users: Cross-Site Scripting (XSS) Part 2

Your Turn to Hack the OWASP Top 10!

WEB SECURITY: XSS & CSRF

WebGoat Lab session overview

Web Applica+on Security

SECURE CODING ESSENTIALS

The security of Mozilla Firefox s Extensions. Kristjan Krips

Penetration Testing following OWASP. Boyan Yanchev Chief Technology Ofcer Peter Dimkov IS Consultant

WEB SECURITY p.1

6.170 Tutorial 7 - Rails Security. Prerequisites. Goals of this tutorial. Resources

CSCD 303 Essential Computer Security Fall 2017

Application Design and Development: October 30

Why bother? Causes of data breaches OWASP. Top ten attacks. Now what? Do it yourself Questions?

IronWASP (Iron Web application Advanced Security testing Platform)

SAP Security. BIZEC APP/11 Version 2.0 BIZEC TEC/11 Version 2.0

5/10/2009. Introduction. The light-saber is a Jedi s weapon not as clumsy or random as a blaster.

Web Attacks CMSC 414. September 25 & 27, 2017

COMP9321 Web Application Engineering

Web Security. Thierry Sans

MWR InfoSecurity Advisory. 26 th April Elastic Path Administrative. Quit. Session Hijacking through Embedded XSS

Web Application Security GVSAGE Theater

Lecture Overview. IN5290 Ethical Hacking. Lecture 4: Web hacking 1, Client side bypass, Tampering data, Brute-forcing

Transcription:

CSE 127 Computer Security Fall 2015 Web Security I: SQL injection Stefan Savage

The Web creates new problems Web sites are programs Partially implemented in browser» Javascript, Java, Flash Partially implemented in server» PHP, SQL, Ruby, ASP*, etc Browser OS Hardware request reply website Network

Web languages Most database and web scripting languages are also untyped Unforeseen user input allows attacker to side-step programmer intent Server attacks: SQL injection Browser attacks: Cross-site scripting (XSS) [should be called Web page injection]

SQL recap Structured Query Language mostly std syntax for sending queries to databases Examples SELECT * FROM books WHERE price > 100.00 ORDER BY title INSERT INTO books (title, price) VALUES ( War and Peace, 15.25) Data types are generally either numbers, strings, or field names

How SQL gets used on the Web Server-side Web application processes user input (e.g. via PHP) Formats it into SQL query Sends query to DB Formats DB response for Web page This is how every e-commerce site you ve ever used likely works

Simple example Query= select count(*) from users where username= &username & and userpass= & password & Courtesy Pankaj Sharma

Aside: syntax Queries get expressed slightly differently in different languages: Query= select count(*) from users where username= &username & and userpass= & password & sql_query = "SELECT count(*) " + "FROM users " + "WHERE username= "+request.getparameter("user") + "AND userpass= +regquest.getparameter("pass"); $username = $_GET[ user ]; $password = $_GET[ pass ]; $sql = SELECT count(*). FROM users. WHERE username= $username. AND userpass = $password ;

Key problem What if user provides malicious input that is passed to the database?

SQL Injection: Basic Idea Victim server Attacker 1 3 receive valuable data 2 unintended query This is an input validation vulnerability Unsanitized user input in SQL query to backend database changes the meaning of query Specific case of more general command injection Victim SQL DB

Uh-oh user provides input user: savage ;-- password: anything What happens? (-- is a comment) Query= select count(*) from users where username= &username & and userpass= & password & Query= select count(*) from users where username= savage ;-- and userpass= anything

Uh-oh user provides input user: savage password: - What happens? Query= select count(*) from users where username= &username & and userpass= & password & Query= select count(*) from users where username= savage and userpass= -

Uh-oh user provides input user: anyone password: crud or 1=1 - What happens? Query= select count(*) from users where username= &username & and userpass= & password & Query= select count(*) from users where username= anyone and userpass= crud or 1=1 -

Some basics of HTTP http://www.tom.com:80/calendar/render.php?gsession id=ok protocol port path query hostname RL s only allow ASCII-US characters. Encode other characters: %0A = newline %20 = space Special characters: + = space? = separates URL from parameters % = special characters / = divides directories, subdirectories # = bookmark & = separator between parameters

Aside: URL encoding Frequently input is encoded into url: http://website.com/products.asp?user=savage Can still encode spaces, escapes, etc E.g., -> %27, space -> %20, = -> %3D http://website.com/products.asp?user=crud%27%20or%201 %3D1%20-

This isn t only a problem for authentication query= select prodinfo from prodtable where prodname = &productreq & any OR x = x Entire database is returned any ;; DROP TABLE prodinfo;; -- Entire database is deleted any ;; exec cmdshell( foo.exe') -- Run foo.exe (or any application on system with any arguments) This only scratches the surface UNION lets you append a second query, INSERT INTO lets you add records, etc Whenever you see a string in your browser like: http://website.com/products.asp?p_id=7 it is ripe for injection

This isn t only a problem for authentication

What s the problem here? Unvalidated input make difficult by Untyped variables Multiple levels of interpretation What to do: Input validation Static queries Proxying

Input Validation Strip out comments and (if possible) SQL keywords from input Can we just strip out quotes? Probably not in general What about names like O'Brien?

Input Validation(2) Better escaping Remove ambiguity about whether the quote is a string literal or syntactic sugar Replace in user input with token that indicates it should be treated as a string literal» E.g. Convert into \ Need to cover all cases (e.g. \ )» mysql_real_escape_string();; php provides mode to deal with this: magic_quotes sanitizes input automatically» However, still allows quoting problems: cannonicalization

Input Validation(3) Integer field validation Quoting doesn t solve problem» SELECT fields from TABLE where id= 52 OR 1=1 Need to validate that integers are integers Validate that integers are in expected range

Integer field validation issues Many languages, such as Perl and PHP, will convert a string into to a number as long as the string begins with digits Each language and database has different quoting rules Return true even if $category = 2 union if ($category > 0) { $categ = "AND AND catid=$category catid=2 union ; "; } elseif ($category == 0) {... }

Second-Order SQL Injection Input parameters not the only risk Second-order SQL injection: data stored in database is later used to conduct SQL injection For example, user manages to set username to admin -- This vulnerability could exist if string escaping is applied inconsistently (e.g., strings not escaped) UPDATE USERS SET passwd= cracked WHERE username= admin -- Solution: treat all parameters as dangerous

Another solution: prepared statements Create query as a parameterized statement q = SELECT * FROM scenarios WHERE username=? AND password=? ; PreparedStatement ps = conn.preparestatement(q); ps.setobject(1,user); Create static parameterized query and explicitly fill in parameters rather than creating a dynamic query Bind variables (indicated by?) can also be explicitly typed (e.g., ps.setint());; Somewhat awkward syntax and can t be used in some cases

Mitigation strategies Be careful not to leak database schema Make attacker guess about field names Some databases allow certain commands to be executed to privilege of requestor (typically using user login as key to privs) E.g. database can only be read not written E.g. external programs cannot be invoked by Weboriginated request Encrypt sensitive data in DB (e.g. credit cards) Even if data stolen, data has little value Tricky issue: key management (key can t be in DB)

Web Application Gateway (WAG) WAG works like a reverse web proxy It can interpret more information in the HTTP protocol and HTML content, it checks Form inputs are within our expectation Hidden fields and cookies are unmodified Multiple choice (select/radio) input is one of the allowed option etc. Potentially protects more than just SQL injection

The downside of WAG Can be challenging to configure it precisely, especially for protecting SQL injection attacks on free-format text input Use heuristics to resolve in practice (does this look like an injection attack or not?) A new user register to a web portal application Noted the apostrophe But should we block this?

CardSystems Attack (June 2005) CardSystems was a major credit card processing company Put out of business by a SQL injection attack Credit card numbers stored unencrypted Data on 263,000 accounts stolen 43 million identities exposed

Hold Security (2014) Uncovered widespread sql injection attacks from Russia against online websites with user registrations Identified theft of username and password hashes from 420,000 websites And this is why you shouldn t use the same password everywhere SQLI remains the most common form of sucessful online attack against Web servers

Next time Problems on the browser Cross site scripting Cross site request forwarding Click jacking, etc