19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

744 Chapter 19 n Finding Vulnerabilities in Source Code<br />

Summary<br />

Many people who have substantial experience with testing <strong>web</strong> <strong>application</strong>s<br />

interactively, exhibit an irrational fear of looking inside an <strong>application</strong>’s codebase<br />

to discover vulnerabilities directly. This fear is understandable for people who<br />

are not programmers, but it is rarely justified. Anyone who is familiar with<br />

dealing with computers can, with a little investment, gain sufficient knowledge<br />

and confidence to perform an effective code audit. Your objective in reviewing<br />

an <strong>application</strong>’s codebase need not be to discover “all” <strong>the</strong> vulnerabilities<br />

it contains, any more than you would set yourself this unrealistic goal when<br />

performing hands-on testing. More reasonably, you can aspire to understand<br />

some of <strong>the</strong> key processing that <strong>the</strong> <strong>application</strong> performs on user-supplied input<br />

and recognize some of <strong>the</strong> signatures that point toward potential problems.<br />

Approached in this way, code review can be an extremely useful complement<br />

to <strong>the</strong> more familiar black-box testing. It can improve <strong>the</strong> effectiveness of that<br />

testing and reveal defects that may be extremely difficult to discover when you<br />

are dealing with an <strong>application</strong> entirely from <strong>the</strong> outside.<br />

Questions<br />

Answers can be found at http://mdsec.net/wahh.<br />

1. List three categories of common vulnerabilities that often have easily<br />

recognizable signatures within source code.<br />

2. Why can identifying all sources of user input sometimes be challenging<br />

when reviewing a PHP <strong>application</strong>?<br />

3. Consider <strong>the</strong> following two methods of performing a SQL query that<br />

incorporates user-supplied input:<br />

// method 1<br />

String artist = request.getParameter(“artist”).replaceAll(“’”, “’’”);<br />

String genre = request.getParameter(“genre”).replaceAll(“’”, “’’”);<br />

String album = request.getParameter(“album”).replaceAll(“’”, “’’”);<br />

Statement s = connection.createStatement();<br />

s.executeQuery(“SELECT * FROM music WHERE artist = ‘” + artist +<br />

‘” AND genre = ‘” + genre + ‘” AND album = ‘” + album + “’”);<br />

// method 2<br />

String artist = request.getParameter(“artist”);<br />

String genre = request.getParameter(“genre”);<br />

String album = request.getParameter(“album”);<br />

Statement s = connection.prepareStatement(<br />

“SELECT * FROM music WHERE artist = ‘” + artist +<br />

“’ AND genre = ? AND album = ?”);

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

Saved successfully!

Ooh no, something went wrong!