CSE 127: Computer Security SQL Injection. Vector Li

Similar documents
Assignment pts. Figure 1: Main page, shown when user requests index.php.

CHAPTER 10. Connecting to Databases within PHP

Chapters 10 & 11 PHP AND MYSQL

Security. CSC309 TA: Sukwon Oh

Application vulnerabilities and defences

Development Technologies. Agenda: phpmyadmin 2/20/2016. phpmyadmin MySQLi. Before you can put your data into a table, that table should exist.

A1 (Part 2): Injection SQL Injection

Web Security: Vulnerabilities & Attacks

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

Advanced Systems Security: Ordinary Operating Systems

CONTENTS IN DETAIL INTRODUCTION 1 THE FAQS OF LIFE THE SCRIPTS EVERY PHP PROGRAMMER WANTS (OR NEEDS) TO KNOW 1 2 CONFIGURING PHP 19

CSE 127 Computer Security

Detecting Insider Attacks on Databases using Blockchains

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

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

ATTACKING SYSTEM & WEB Desmond Alexander CISSP / GIAC/ GPEN CEO FORESEC

Running SQL in Java and PHP

SQL Injection. EECS Introduction to Database Management Systems

CSCE 548 Building Secure Software SQL Injection Attack

Server-side web security (part 2 - attacks and defences)

Options. Real SQL Programming 1. Stored Procedures. Embedded SQL

Running SQL in Java and PHP

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

Locate your Advanced Tools and Applications

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

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

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

Who s Afraid of SQL Injection?! Mike Kölbl Sonja Klausburg Siegfried Goeschl

By the end of this section of the practical, the students should be able to:

CSE 127: Computer Security. Security Concepts. Kirill Levchenko

WEB SECURITY p.1

Homework 7. For your information: Graded out of 100 points; 2 questions total 5-10 hours for phase 1; hours for phase 2.

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

Secure Programming Lecture 8++: SQL Injection

Protecting PostgreSQL Against SQL Injection Attack

PHP and MySQL Programming

pysqlw Documentation Release plausibility

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

Web Application Security. Philippe Bogaerts

Troubleshooting. The NLR Web Interface Does not Appear CHAPTER

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

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 3

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

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

Mysql Workbench Import Sql No Database. Selected >>>CLICK HERE<<<

Systems Programming & Scripting

Configuring an Enhanced Standard Security Policy

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

Web Penetration Testing

NET 311 INFORMATION SECURITY

Vesta Control Panel is a stack of software components which is roughly divided into two main layers as shown below in the architecture diagram.

Hacking Oracle APEX. Welcome. About

Networks and Web for Health Informatics (HINF 6220) Tutorial 13 : PHP 29 Oct 2015

SQL Injection Attack Lab

Barracuda Web Application Firewall Foundation - WAF01. Lab Guide

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

Lecture 13: MySQL and PHP. Monday, March 26, 2018

Injection attacks use specially crafted inputs to subvert the intended operation of applications.

MySQL: Access Via PHP

Injection. CSC 482/582: Computer Security Slide #1

Numara FootPrints Changelog January 26, 2009

Lecture 7: Dates/Times & Sessions. CS 383 Web Development II Wednesday, February 14, 2018

Advanced Web Technology 10) XSS, CSRF and SQL Injection

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Oracle PL/SQL Gateway 0-Day

Oracle Sql Describe Schemas Query To Find Database

Drop Table If Exists Sql Command Not Properly Ended

Basics of SQL Injection

Databases and SQL programming overview

Daniel Pittman October 17, 2011

Handjet EBS-260 Bluetooth Scanner Communication Set-Up

Nemesis: Preventing Authentication & [and] Access Control Vulnerabilities in Web Applications

FUSION REGISTRY COMMUNITY EDITION SETUP GUIDE VERSION 9. Setup Guide. This guide explains how to install and configure the Fusion Registry.

CSCI 420: Mobile Application Security. Lecture 7. Prof. Adwait Nadkarni. Derived from slides by William Enck, Patrick McDaniel and Trent Jaeger

Nemesis: Preventing Web Authentication & Access Control Vulnerabilities. Michael Dalton, Christos Kozyrakis Stanford University

CS4604 Prakash Spring 2016! Project 3, HTML and PHP. By Sorour Amiri and Shamimul Hasan April 20 th, 2016

SmartConnector Configuration Guide for

CSC 3300 Homework 3 Security & Languages

API Gateway Version September Analytics User Guide

Database Security: Transactions, Access Control, and SQL Injection

PostgreSQL Installation Guide

Wentworth Institute of Technology COMP570 Database Applications Fall 2014 Derbinsky. SQL Programming. Lecture 8. SQL Programming

Backend IV: Authentication, Authorization and Sanitization. Tuesday, January 13, 15

Download and Installation Instructions: After WAMP Server download start the installation:

Lab 7 Introduction to MySQL

Lecture 9a: Sessions and Cookies

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

About Securich. Started April Open Sourced June 2009 v0.1.1 Current version v0.2.5 GPLv2 (Sharing is Caring) Supported on MySQL 5.1.

Reflected XSS Cross-Site Request Forgery Other Attacks

SQL Injection Attack: Detection in a Web Application Environment

OCS INSTALLATION GUIDE

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2016

Secure Coding, some simple steps help. OWASP EU Tour 2013

IS 2150 / TEL 2810 Introduction to Security

LXVII. PostgreSQL functions

Configuring Vulnerability Assessment Devices

Web Security: Vulnerabilities & Attacks

C1: Define Security Requirements

PHP: Hypertext Preprocessor. A tutorial Introduction

A Haskell and Information Flow Control Approach to Safe Execution of Untrusted Web Applications

Transcription:

CSE 127: Computer Security SQL Injection Vector Li November 14, 2017

A Magic Trick The functional specification only allowed seeing one user s posts at a time Current user s posts on view.php without URL arguments Any user s posts with view.php?user=username

Wow! very hack

http://127.0.0.1:8080/view.php? user=%27%20or%20%27%27%20=%20%27 encodes http://127.0.0.1:8080/view.php?user=user1' or '' = '

What is going on?

From Someone s view.php: <?php if (isset($_get["user"])) { $user = ($_GET["user"]); } $exists = true; $dbconn = pg_connect("host=localhost dbname=chattr user=student password=hacktheplanet"); $query = "SELECT * FROM messages WHERE name = '$user'"; $result = pg_query($query);?>

From Someone s view.php: <?php if (isset($_get["user"])) { $user = ($_GET["user"]); } $exists = true; $dbconn = pg_connect("host=localhost dbname=chattr user=student password=hacktheplanet"); $query = "SELECT * FROM messages WHERE name = '$user'"; $result = pg_query($query);?>

http://127.0.0.1:8080/view.php? user=%27%20or%20%27%27%20=%20%27 encodes http://127.0.0.1:8080/view.php?user=' or '' = ' results in query select * from posts where name = '' or '' = ''; always true

From Someone s view.php: <?php if (isset($_get["user"])) { $user = ($_GET["user"]); } $exists = true; $dbconn = pg_connect("host=localhost dbname=chattr user=student password=hacktheplanet"); $query = "SELECT * FROM messages WHERE name = '$user'"; $result = pg_query($query);?> untrusted user input inserted directly into query that is sent to the database

From Someone s login.php: <?php else { $query = "SELECT username FROM chattrdb.users WHERE username='$username' AND password='$password'"; $result = pg_query($conn, $query); if (!$row = pg_fetch_row($result)) { session_unset();?> <?php } else { $_SESSION[ username ] = $username; header( Location: view.php?user=$username ); }?> What can we do?

SQL Injection SQL Injection: Inserting SQL fragment into query sent by an application to an SQL database Application assumes user input is data Databases parses user input as code

Is it a Real Problem?

SQL Injection Possibilities Dump the entire database (violate secrecy) Drop the entire database (deny availability) Modify database data (violate integrity)

From Someone s post.php: <?PHP $username = $_SESSION['username']; $timestamp = date("y-m-d H:i:s"); $usermessage = $_POST['TEXT']; //Insert into database $insertquery = "INSERT INTO messages (username, time, message) VALUES ('$username', $timestamp', '$usermessage')"; $result = pg_query($insertquery); //Navigate to view the posts header('location: view.php?user='. $username)?> Delete user s posts through SQL injection

Constraints Easiest case (for attacker): known application code and database schema, direct access to query results HW2: view.php?user= Hardest case (for attacker): unknown code and schema, one bit of output per query 1 bit output: success or failure HW2: login.php

From Someone s view.php: <?php if (isset($_get["user"])) { $user = ($_GET["user"]); } $exists = true; $dbconn = pg_connect("host=localhost dbname=chattr user=student password=hacktheplanet"); $query = "SELECT * FROM messages WHERE name = '$user'"; $result = pg_query($query);?> View users passwords through SQL injection

SQL Injection SQL Injection: Inserting SQL fragment into query sent by an application to an SQL database Application assumes user input is data Databases parses user input as code Attacker gains ability to submit SQL directly to backend database on behalf of application database user

Web Application Architecture

User Domains Operating system HW2: root and student Database HW2: postgres, student, chattr Application HW2: idfoster, jmaskiew (in examples)

SQL Injection Privileges Server-side application process connects to database as a particular database user (application database user) <?php $db_host = 'localhost'; $db_user = 'student'; $db_pass = 'hacktheplanet'; $db_name = 'chattr'; $conn = pg_connect ( "host=$db_host dbname=$db_name user=$db_user password=$db_pass") Attacker gains direct access to database with application database user privilege

Mitigation Sanitize user input Escape SQL delimiters to input treated as quote Use prepared statements Complete separation of control and data Preferred way

Sanitizing User Input Escape special characters E.g. change ' to '' ('' treated as single ' inside quote) Easy to get wrong With above rule \' in input becomes \''which closes quote Each database has its own special quoting rules Use DB-specific string escape function instead PHP & PostgreSQL: pg_escape_literal PHP & MySQL: mysqli_real_escape_string

Prepared Statements Separate control and data Prepare: define statement with parameters pg_prepare($conn, "get_posts", 'select * from posts where name = $1'); Execute: execute query with given parameters $rows = pg_execute($conn, "get_posts", array($user));

Prepared Statements vs Sanitizing Input Economy of Mechanism argues against sanitizing String parsing implemented in database code Tempting to add additional escape mechanisms as a feature String escaping implemented in database connector Database connector usually maintained by third party (not database vendor) Two mechanisms must be exactly in sync Prepared statement escaping (if any) is at lower level Handled by common library maintained by DB vendor Invisible to user

Escaping Problems Robustness principle (Postel s law): Be conservative in what you do, be liberal in what you accept from others. (RFC 793) Historically considered good protocol design philosophy Security problems can occur when assumptions at interfaces of two systems differ

The Bigger Problem

The Bigger Problem Application server accesses with database on behalf of application user In most cases application users have distinct privileges Application uses database as single database user This application database user must have union of all user s privileges in order to implement functionality

<?php $db_host = 'localhost'; $db_user = 'student'; $db_pass = 'hacktheplanet'; $db_name = 'chattr'; $conn = pg_connect ( "host=$db_host dbname=$db_name user=$db_user password=$db_pass")

The Bigger Problem Compromising application gives attacker access to database as application database user Best case: attacker gains union of all application user s access privileges to data Worst case: application database user is DB superuser

DB User = App User? Database user domain managed by database admin Application user domain managed by application code No easy way to map application user to database user

The Bigger Problem

The Bigger Problem Application similar to setuid executable in Unix Application code must ensure all interaction consistent with security policy Application code part of TCB Is there a better way?