SQL Injection
Slides thanks to Prof. Shmatikov at UT Austin
SQL Injection Slides thanks to Prof. Shmatikov at UT Austin Dynamic - - PowerPoint PPT Presentation
SQL Injection Slides thanks to Prof. Shmatikov at UT Austin Dynamic Web Application GET / HTTP/1.0 Browser Web server HTTP/1.1 200 OK index.php Database server slide 2 PHP: Hypertext Preprocessor Server scripting language with C-like
Slides thanks to Prof. Shmatikov at UT Austin
Browser Web server GET / HTTP/1.0 HTTP/1.1 200 OK index.php Database server
slide 2
slide 3
INSERT INTO Key (Username, Key) VALUES (‘Vitaly’, 3611BBFF)
UPDATE Keys SET Key=FA33452D WHERE PersonID=5
slide 4
slide 5
Victim server Victim SQL DB Attacker post malicious form unintended query receive valuable data 1 2 3
slide 6
This is an input validation vulnerability
Unsanitized user input in SQL query to back- end database changes the meaning of query
Specific case of more general command injection
slide 7
Enter Username & Password
slide 8
Web server Web browser (Client) DB SELECT passwd FROM USERS WHERE uname IS ‘$user’
Enter Username & Password
slide 9
Web server Web browser (Client) DB SELECT passwd FROM USERS WHERE uname IS ‘smith’
slide 10
Enter Username & Password
slide 11
Web server Web browser (Client) DB SELECT passwd FROM USERS WHERE uname IS ‘’; DROP TABLE USERS; -- ’
Eliminates all user accounts
slide 12
http://xkcd.com/327/
slide 13
Only true if the result of SQL query is not empty, i.e., user/ pwd is in the database
slide 14
Always true! Everything after -- is ignored!
slide 15
[From Kevin Mitnick’s “The Art of Intrusion”]
Wildcard matches any password
slide 16
slide 17
slide 18
– Apostrophes, semicolons, percent symbols, hyphens, underscores, … – Any character that has special meanings
– Forget to filter out some characters – Could prevent valid input (e.g., last name O’Brien)
– Set implicitly defined through regular expressions
slide 28
slide 29
slide 30
PreparedStatement ps = db.prepareStatement("SELECT pizza, toppings, quantity, order_day " + "FROM orders WHERE userid=? AND order_month=?"); ps.setInt(1, session.getCurrentUserId()); ps.setInt(2, Integer.parseInt(request.getParamenter("month"))); ResultSet res = ps.executeQuery(); Bind variable: data placeholder
slide 31
http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
slide 32