This time
Getting insane with Continuing with
Software
Security
- New attacks and countermeasures:
- SQL injection
- Background on web architectures
I n p u t
sanitization’);
drop table slides
I n p u t sanitization); drop table slides New attacks and - - PowerPoint PPT Presentation
This time Continuing with Software Getting insane with Security I n p u t sanitization); drop table slides New attacks and countermeasures: SQL injection Background on web architectures A very basic web architecture Client
Getting insane with Continuing with
drop table slides
Client Server
Client Server
Client Server
Browser Web server
Client Server
Browser Web server Database
Client Server
Browser Web server Database
Client Server
(Private) Data
Browser Web server Database
Client Server
(Private) Data
DB is a separate entity, logically (and often physically)
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Table
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Table name
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Column
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Row (Record)
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Transactions are the unit of work on a database
Transactions are the unit of work on a database
“Deduct $100 from Alice; Add $100 to Bob” “Give me everyone in the User table who is listed as taking CMSC414 in the Classes table”
Transactions are the unit of work on a database
“Deduct $100 from Alice; Add $100 to Bob” “Give me everyone in the User table who is listed as taking CMSC414 in the Classes table” 2 reads
2 writes
Transactions are the unit of work on a database
“Deduct $100 from Alice; Add $100 to Bob” “Give me everyone in the User table who is listed as taking CMSC414 in the Classes table”
1 transaction
2 reads 2 writes
(but not necessarily correct)
until it is complete
remains, despite, e.g., power failures
Transactions are the unit of work on a database
“Deduct $100 from Alice; Add $100 to Bob” “Give me everyone in the User table who is listed as taking CMSC414 in the Classes table”
1 transaction
2 reads 2 writes
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
28
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
28
UPDATE Users SET email=‘readgood@pp.com’ WHERE Age=32; -- this is a comment
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
28
UPDATE Users SET email=‘readgood@pp.com’ WHERE Age=32; -- this is a comment
readgood@pp.com
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
28
UPDATE Users SET email=‘readgood@pp.com’ WHERE Age=32; -- this is a comment
readgood@pp.com
INSERT INTO Users Values(‘Frank’, ‘M’, 57, ...);
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
28
UPDATE Users SET email=‘readgood@pp.com’ WHERE Age=32; -- this is a comment
readgood@pp.com
INSERT INTO Users Values(‘Frank’, ‘M’, 57, ...);
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
28
UPDATE Users SET email=‘readgood@pp.com’ WHERE Age=32; -- this is a comment
readgood@pp.com
INSERT INTO Users Values(‘Frank’, ‘M’, 57, ...); DROP TABLE Users;
Users
Name Gender Age Email Password Dee F 28 dee@pp.com j3i8g8ha Mac M 7 bouncer@pp.com a0u23bt Charlie M 32 aneifjask@pp.com 0aergja Dennis M 28 imagod@pp.com 1bjb9a93 Frank M 57 armed@pp.com ziog9gga
SELECT Age FROM Users WHERE Name=‘Dee’;
28
UPDATE Users SET email=‘readgood@pp.com’ WHERE Age=32; -- this is a comment
readgood@pp.com
INSERT INTO Users Values(‘Frank’, ‘M’, 57, ...); DROP TABLE Users;
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Website “Login code” (php) Suppose you successfully log in as $user if this query returns any rows whatsoever
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Website “Login code” (php) Suppose you successfully log in as $user if this query returns any rows whatsoever How could you exploit this?
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
frank’ OR 1=1); --
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
frank’ OR 1=1); --
$result = mysql_query(“select * from Users where(name=‘frank’ OR 1=1); -- and password=‘whocares’);”);
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
frank’ OR 1=1); DROP TABLE Users; -- Can chain together statements with semicolon: STATEMENT 1 ; STATEMENT 2
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
frank’ OR 1=1); DROP TABLE Users; --
$result = mysql_query(“select * from Users where(name=‘frank’ OR 1=1); DROP TABLE Users; -- ‘ and password=‘whocares’);”);
Can chain together statements with semicolon: STATEMENT 1 ; STATEMENT 2
5 10 15 20 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 1 2 1 1 2 1 2 2 1 3 2 1 4 2 1 5
% of vulnerabilities that are SQL injection
http://web.nvd.nist.gov/view/vuln/statistics
5 10 15 20 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 1 2 1 1 2 1 2 2 1 3 2 1 4 2 1 5
% of vulnerabilities that are buffer overflows
http://web.nvd.nist.gov/view/vuln/statistics
values known to be safe
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
When the boundary between code and data blurs, we open ourselves up to vulnerabilities
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
select / from / where * Users and = name $user = password $pass
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
select / from / where * Users and = name $user = password $pass
$user
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Key idea: Decouple the code and the data
$db = new mysql(“localhost”, “user”, “pass”, “DB”); $statement = $db->prepare(“select * from Users where(name=? and password=?);”); $statement->bind_param(“ss”, $user, $pass); $statement->execute(); $result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Key idea: Decouple the code and the data
$db = new mysql(“localhost”, “user”, “pass”, “DB”); $statement = $db->prepare(“select * from Users where(name=? and password=?);”); $statement->bind_param(“ss”, $user, $pass); $statement->execute(); $result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Bind variables
Key idea: Decouple the code and the data
$db = new mysql(“localhost”, “user”, “pass”, “DB”); $statement = $db->prepare(“select * from Users where(name=? and password=?);”); $statement->bind_param(“ss”, $user, $pass); $statement->execute(); $result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Bind variables Bind variables are typed
Key idea: Decouple the code and the data
$db = new mysql(“localhost”, “user”, “pass”, “DB”); $statement = $db->prepare(“select * from Users where(name=? and password=?);”); $statement->bind_param(“ss”, $user, $pass); $statement->execute(); $result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Bind variables Bind variables are typed Decoupling lets us compile now, before binding the data
Key idea: Decouple the code and the data
$statement = $db->prepare(“select * from Users where(name=? and password=?);”);
select / from / where * Users and = name
?
= password
?
$user $pass
$statement = $db->prepare(“select * from Users where(name=? and password=?);”);
select / from / where * Users and = name
?
= password
?
$statement = $db->prepare(“select * from Users where(name=? and password=?);”);
select / from / where * Users and = name
?
= password
?
Prepare is only applied to the leaves, so the structure of the tree is fixed
Creditcards_Table
Browser Web server Database
Client Server
(Private) Data
DB is a separate entity, logically (and often physically)
Browser Web server Database
Client Server
(Private) Data
DB is a separate entity, logically (and often physically) (Much) user data is part of the browser
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Protocol ftp https tor
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Hostname/server Translated to an IP address by DNS (more on this later)
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Path to a resource Here, the file home.html is static content i.e., a fixed file returned by the server
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Path to a resource Here, the file home.html is static content i.e., a fixed file returned by the server http://facebook.com/delete.php
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Path to a resource Here, the file home.html is static content i.e., a fixed file returned by the server http://facebook.com/delete.php Path to a resource Here, the file home.html is dynamic content i.e., the server generates the content on the fly
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Path to a resource Here, the file home.html is static content i.e., a fixed file returned by the server http://facebook.com/delete.php Here, the file home.html is dynamic content i.e., the server generates the content on the fly
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Path to a resource Here, the file home.html is static content i.e., a fixed file returned by the server http://facebook.com/delete.php Here, the file home.html is dynamic content i.e., the server generates the content on the fly ?f=joe123&w=16
http://www.cs.umd.edu/~dml/home.html Get and put resources which are identified by a URL Path to a resource Here, the file home.html is static content i.e., a fixed file returned by the server http://facebook.com/delete.php Here, the file home.html is dynamic content i.e., the server generates the content on the fly ?f=joe123&w=16 Arguments
Browser Web server
Client Server
Database (Private) Data
Browser Web server
Client Server
Browser Web server
Client Server HTTP
Browser Web server
Client Server
collections of data
HTTP
Browser Web server
Client Server
Browser Web server
Client Server User clicks
Browser Web server
Client Server HTTP Request User clicks
Browser Web server
Client Server HTTP Request User clicks
http://www.reddit.com/r/security
http://www.reddit.com/r/security
http://www.reddit.com/r/security User-Agent is typically a browser but it can be wget, JDK, etc.
Referrer URL: the site from which this request was issued.
Posting on Piazza
Posting on Piazza
Posting on Piazza Implicitly includes data as a part of the URL
Posting on Piazza Explicitly includes data as a part of the request’s content Implicitly includes data as a part of the URL
Browser Web server
Client Server HTTP Request User clicks
Browser Web server
Client Server User clicks
Browser Web server
Client Server User clicks HTTP Response
Browser Web server
Client Server User clicks
HTTP Response
<html> …… </html>
<html> …… </html> Headers Data HTTP version Status code Reason phrase HTTP responses
client from that previous session”
Continuing with
XSS & CSRF
Required reading for next lecture: “Web Security: Are You Part Of The Problem?” “Cross Site Request Forgery: An Introduction…”
Optional reading for this lecture:
“SQL Injection Attacks by Example”