130 likes | 255 Views
Announcements. Extended office hours from now until the midterm Thursday 10-11:30am Tao, 8pm-9pm Jaebum Friday 10-11:30am Tao Saturday 7-8pm Tao Sunday 8-9pm Jaebum Monday 12:55-1:55pm Arash , 5-6pm Arash Tuesday 10-11am Jaebum , 12:55-1:55pm Arash Questions on the midterm?
E N D
Announcements Extended office hours from now until the midtermThursday 10-11:30am Tao, 8pm-9pm Jaebum Friday 10-11:30am Tao Saturday 7-8pm Tao Sunday 8-9pm Jaebum Monday12:55-1:55pm Arash, 5-6pm Arash Tuesday 10-11am Jaebum, 12:55-1:55pm Arash Questions on the midterm? SQL injection attack slides Other attacks
Database Vulnerabilities on the Web SQL injection Cross-site scripting (XSS) Cross-site request forgeries (CSRF) Not just a DB vulnerability
Is this funny yet? From xkcd.com
How can you prevent SQL injection attacks? • Use “parameterized statements”, if your DBMS/host language supports them (shown in Sruthi’s slides) • Else validate data prior to using it within dynamic SQL queries, e.g., with PHP filtering functions, and remove all suspect characters • Use a testing tool that tries injection attacks before you release your code But these rules are intended for developers. How can you fix legacy code? [Bandhakavi et al., CCS07]
Cross-site scripting (XSS): don’t trust any kind of input From http://shiflett.org/articles/foiling-cross-site-attacks <form action="/register.php" method="POST"> <p>Username: <input type="text" name="username" /> <p>Email: <input type="text" name="email" /> <p><input type="submit" value="Register" /></p> </form>
Cross-site scripting (XSS): don’t trust any kind of input From http://shiflett.org/articles/foiling-cross-site-attacks <form action="/register.php" method="POST"> <p>Username: <input type="text" name="username" /> <p>Email: <input type="text" name="email" /> <p><input type="submit" value="Register" /></p> </form> … <?php $mysql = array(); $mysql['username'] =mysql_real_escape_string($_POST['username']); $mysql['email'] = mysql_real_escape_string($_POST['email']); $sql = "INSERT INTO users (username, email) ” . “VALUES ('{$mysql['username']}', '{$mysql['email']}')"; > … Finds the special characters and puts \ in front of them
Cross-site scripting (XSS): don’t trust any kind of input From http://shiflett.org/articles/foiling-cross-site-attacks <form action="/register.php" method="POST"> <p>Username: <input type="text" name="username" /> <p>Email: <input type="text" name="email" /> <p><input type="submit" value="Register" /></p> </form> <script>alert('XSS');</script> whatever@wherever.edu … <?php $mysql = array(); $mysql['username'] =mysql_real_escape_string($_POST['username']); $mysql['email'] = mysql_real_escape_string($_POST['email']); $sql = "INSERT INTO users (username, email) ” . “VALUES ('{$mysql['username']}', '{$mysql['email']}')"; > …
Now the DB contains malicious garbage <table> <tr> <th>Username</th> <th>Email</th> </tr> <?php if ($_SESSION['admin']) { $sql = 'SELECT username, email FROM users'; $result = mysql_query($sql); while ($record = mysql_fetch_assoc($result)) { echo " <tr>\n"; echo " <td>{$record['username']}</td>\n"; echo " <td>{$record['email']}</td>\n"; echo " </tr>\n"; } } ?> </table> XSS ADMIN
We can steal the admin’s cookies, hijack her session, impersonate her <table> <tr> <th>Username</th> <th>Email</th> </tr> <?php if ($_SESSION['admin']) { $sql = 'SELECT username, email FROM users'; $result = mysql_query($sql); while ($record = mysql_fetch_assoc($result)) { echo " <tr>\n"; echo " <td>{$record['username']}</td>\n"; echo " <td>{$record['email']}</td>\n"; echo " </tr>\n"; } } ?> </table> ADMIN
How to prevent XSS attacks • Carefully filter all input • Carefully escape all output (so that it cannot be interpreted as HTML commands)
Cross-site request forgery (CSRF): user = unwitting accomplice http://shiflett.org/articles/foiling-cross-site-attacks An administrator requests http://attacksite.org/cuteKittens.html and receives: HTTP/1.1 200 OK Content-Length: 121 <html> <imgsrc=“http://cutecats.com/cat_of_the_week.gif”> <imgsrc="http://mycompany.org/admin/terminate_employee.php?employee_id=123" > </html> When the browser requests the second image: GET /admin/terminate_employee.php?employee_id=123 HTTP/1.1 Host: mycompany.org Cookie: PHPSESSID=123456789
This works even if the target is only available on an intranet http://shiflett.org/articles/ foiling-cross-site-attacks
Preventing CSRF • Use POST, not GET, for actions; and use $_POST, not $_REQUEST • Ask the user to confirm: “Do you really want to fire these people?” • Embed a fresh token in the legitimate form used to fire people, and require that this token be submitted with the form’s request, within a timeout interval What about legacy forms?