SQL Injections. SQL Injection is a code injection technique in which malicious SQL statements are...

16
SQL Injections

Transcript of SQL Injections. SQL Injection is a code injection technique in which malicious SQL statements are...

Page 1: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Injections

Page 2: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.
Page 3: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Injections

SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e. to dump the database contents to the attacker)

Page 4: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

History First public discussions of SQL injection appeared around 1998

Specifically in an article in Phrack Magazine (magazine articles posted on line in bulletin board form)

November 2005: A hacker broke into the site of a Taiwanese information security magazine, stealing customer information

May 2008: A server farm inside China used automated queiries to Google to find SQL server websites that are vulnerable to SQL inj.

March 2011: Mysql.com was compromised by a hacker using SQL blind injection

October 2012: a hacker group published personal records of students, faculty, employees, and alumni from 53 universities including, Harvard, Stanford, and the University of Zurich.

Page 5: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Basics: Create

CREATE TABLE `weather` (

`city` VARCHAR(32) NOT NULL,

`state` VARCHAR(16) NOT NULL,

`high` INT(11) NOT NULL,

`low` INT(11) NOT NULL,

);

Weather

city state high low

Page 6: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Basics: Insert

INSERT INTO `weather` (`city`, `state`, `high`, `low`)

VALUES (‘Austin’, ‘Texas’, ‘102’, ’70’);

Weather

city state high low

Austin Texas 102 70

Page 7: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Basics: Select

SELECT * FROM `weather`;

Weather

city state high low

Austin Texas 102 70

Madison Wisconsin 45 0

New York New York 90 25

Las Vegas Nevada 200 100

Page 8: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Basics: Select

SELECT high,low FROM `weather` WHERE state=`Wisconsin`

Weather

city state high low

Austin Texas 102 70

Madison Wisconsin 45 0

New York New York 90 25

Las Vegas Nevada 200 100

Page 9: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Basics: Update

UPDATE `weather` SET high=110 WHERE city=‘Austin’;

Weather

city state high low

Austin Texas 110 70

Madison Wisconsin 45 0

New York New York 90 25

Las Vegas Nevada 200 100

Page 10: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Basics: Delete

DELETE FROM weather WHERE city=‘Las Vegas’ AND state=‘Nevada’;

Weather

city state high low

Austin Texas 102 70

Madison Wisconsin 45 0

New York New York 90 25

Las Vegas Nevada 200 100

Page 11: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Basics: Drop

DROP TABLE weather;

Weather

city state high low

Austin Texas 102 70

Madison Wisconsin 45 0

New York New York 90 25

Page 12: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

Typical Query for an Application

SELECT * FROM users WHERE username=‘$username’

AND password=‘$password’;

Page 13: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Injection

SELECT * FROM users WHERE username=‘jhenn’#

AND password=‘$password’;

$username = jhenn’#

$password = herpderp

Page 14: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Injection

SELECT * FROM users WHERE username= ‘jhenn’; DROP TABLE users;#

AND password=‘$password’;

$username = jhenns’; DROP TABLE users;#

$password = herpderp

Page 15: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

SQL Injection: Prevention

Parametrized Queries

mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");

$query = $db -> prepare(“SELECT * FROM users WHERE username=:username AND

password=:password”);

$db -> bindParam(‘:username’, $username, PDO::PARAM_STR);$db -> bindParam(‘:password’, $password, PDO::PARAM_STR);

Page 16: SQL Injections.  SQL Injection is a code injection technique in which malicious SQL statements are inserted into an entry field for execution (i.e.

Events This Week:

Cryptocurrency Club Meeting on Thursday

EGaDS Game Night this Friday

ANY OTHERS?