Web Programming Step by Step

Lecture 21
Web Security

Except where otherwise noted, the contents of this presentation are Copyright 2010 Marty Stepp, Jessica Miller, and Kevin Wallace.

Valid XHTML 1.1 Valid CSS!

1. The "security mindset"

CSE <= 190M

group hug

The real world

orcs (dorks?)

2. Some basic web attacks

HTML injection

a flaw where a user is able to inject arbitrary HTML content into your page

8-ball

Injecting HTML content

8ball.php?question=<blink>lololol</blink>

Cross-site scripting

a flaw where a user is able to inject and execute arbitrary JavaScript code in your page

8ball.php?question=<script type='text/javascript>alert('pwned');</script>
Buy-a-Grade

Securing against HTML injection

htmlspecialchars returns an HTML-escaped version of a string
$text = "<p>hi 2 u & me</p>";
$text = htmlspecialchars($text);   # "&lt;p&gt;hi 2 u &amp; me&lt;/p&gt;"

SQL injection

a flaw where the user is able to inject arbitrary SQL commands into your query

8-ball

A SQL injection attack

Too true...

bobby tables xkcd comic

Securing against SQL injection

  • similar to securing against HTML injection, escape the string before you include it in your query
mysql_real_escape_string returns a SQL-escaped version of a string
$username = mysql_real_escape_string($_REQUEST["username"]);
$password = mysql_real_escape_string($_REQUEST["password"]);
$query = "SELECT name, ssn, dob FROM users
WHERE username = '$username' AND password = '$password'";

  • replaces ' with \', etc.

3. Breaking and securing an example page

  • PHP/SQL review
  • some basic web attacks
  • breaking and securing an example page

Practice problem: Hack Marty's turnin

  • How can we break this page?
    https://webster.cs.washington.edu/stepp/security/turnin/
  • We want to cheat on Homework Assignment 7, Song.java. We want to find a way to submit a perfect working solution without doing any real work.
  • We got a low grade on a past assignment, so if possible, we want to set our past grades to be higher than they are now.
  • Our enemy is fellow classmate Felix Chu. We want to find out his personal information (password, email, student ID, grade, etc.).
  • We don't like the course instructor, Marty Stepp. We want to make the turnin page print an embarrassing message about him.