Lecture 6: Modules 6.1-6.10 Web Server Security CSE 628/628A
Lecture 6: Modules 6.1-6.10 Web Server Security CSE 628/628A
10
Web Server Security
CSE 628/628A
Sandeep K. Shukla
Indian Institute of Technology
Kanpur
Acknowledgements
Dan Boneh (Stanford University)
John C. Mitchell (Stanford University)
Nicolai Zeldovich (MIT)
Jungmin Park (Virginia Tech)
Patrick Schaumont (Virginia Tech)
C. Edward Chow
Arun Hodigere
Web Resources
Lecture 6: Web Server
Security
Total 6 Modules on Web Client Security
Module 6.1: Major Web server Threats:
Command and SQL Injection Attacks
Module 6.2: CSRF Cross-Site Request
Forgery
Module 6.3: XSS Cross-Site Scripting
Module 6.4: Defenses and Protections
against XSS
Module 6.5: Finding Vulnerabilities
Module 6.6: Secure Development
Module 6.1: Major Web
Server Threats
Command and SQL Injection
OWASP Top Ten (2013)
SQL Injection
Browser sends malicious input to server
Bad input checking leads to malicious SQL query
CSRF Cross-site request forgery
Bad web site sends browser request to good web
site, using credentials of an innocent victim
XSS Cross-site scripting
Bad web site sends innocent victim a script that
steals information from an honest web site
Three vulnerabilities we will discuss
SQL Injection
Uses malicious
Browser sends SQL to change meaning
input of
to server
database command
Bad input checking leads to malicious SQL query
CSRF Cross-site request forgery
Bad web site Leverage users session at
sendsvictim
request to good web site,
server
using credentials of an innocent victim who
visits site
XSS Cross-site scripting
Inject malicious script into
trusted context
Bad web site sends innocent victim a script that
steals information from an honest web site
Command Injection
$in = $_GET[exp'];
eval('$ans = ' . $in . ';');
Attack
http://site.com/calc.php?exp= 10 ; system(rm *.*)
(URL encoded)
Code injection using
system()
Example: PHP server-side code for sending email
$email = $_POST[email]
$subject = $_POST[subject]
system(mail $email s $subject < /tmp/joinmynetwork)
OR
http://yourdomain.com/mail.php?
email=hacker@hackerhome.net&subject=foo;
echo evil::0:0:root:/:/bin/sh">>/etc/passwd; ls
SQL Injection
Database queries with PHP
(the wrong way)
Sample PHP
$recipient = $_POST[recipient];
$sql = "SELECT PersonID FROM Person WHERE
Username='$recipient'";
$rs = $db->executeQuery($sql);
Problem
What if recipient is malicious string that
changes the meaning of the query?
Basic picture: SQL Injection
Victim Server
u s form
i o
malic
1 post
2
unintended
3 receive valuable SQL query
Attacker data
Victim SQL DB
13
CardSystems Attack
CardSystems
credit card payment processing
company
SQL injection attack in June 2005
put out of business
The Attack
263,000 credit cards stolen from
database
credit card #s stored unencrypted
43 million credit card #s exposed
14
http://www.cvedetails.com/vulnerability-list/vendor_id-2337/opsqli-1/Wordpress.html
Example: buggy login page
(ASP)
if not ok.EOF
login success
else fail;
Is this exploitable?
16
Enter
Username SELECT *
& FROM Users
Web Password Web WHERE user='me'
Browser
Server
DB
(Client) AND pwd='1234'
Normal Query
Bad input
Suppose user = ' or 1=1 -- (URL
encoded)
21
Preventing SQL Injection
SQL
Builds SQL queries by properly escaping args: \