21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

*ptr++ = *c;<br />

} while (*++c != ’>’);<br />

*ptr++ = ’>’;<br />

break;<br />

}<br />

case ’>’:<br />

*ptr++ = ’&’; *ptr++ = ’g’; *ptr++ = ’t’; *ptr++ = ’;’;<br />

break;<br />

case ’&’:<br />

*ptr++ = ’&’; *ptr++ = ’a’; *ptr++ = ’m’; *ptr++ = ’p’;<br />

*ptr++ = ’;’;<br />

break;<br />

case ’'’:<br />

*ptr++ = ’&’; *ptr++ = ’q’; *ptr++ = ’u’; *ptr++ = ’o’;<br />

*ptr++ = ’t’; *ptr++ = ’t’;<br />

break;<br />

default:<br />

*ptr++ = *c;<br />

break;<br />

}<br />

}<br />

*ptr = 0;<br />

return output;<br />

}<br />

3.11 Preventing SQL Injection Attacks<br />

<strong>Problem</strong><br />

You are developing an application that interacts with a SQLdatabase, and you need<br />

to defend against SQL injection attacks.<br />

Solution<br />

SQLinjection attacks are most common in web applications that use a database to<br />

store data, but they can occur anywhere that a SQLcommand string is constructed<br />

from any type of input from a user. Specifically, a SQLinjection attack is mounted<br />

by inserting characters into the command string that creates a compound command<br />

in a single string. For example, suppose a query string is created with a WHERE clause<br />

that is constructed from user input. A proper command might be:<br />

SELECT * FROM people WHERE first_name="frank";<br />

If the value “frank” comes directly from user input and is not properly validated, an<br />

attacker could include a closing double quote and a semicolon that would complete<br />

the SELECT command and allow the attacker to append additional commands. For<br />

example:<br />

SELECT * FROM people WHERE first_name="frank"; DROP TABLE people;<br />

Preventing SQL Injection Attacks | 107<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!