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.

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

s.setString(1, genre);<br />

s.setString(2, album);<br />

s.executeQuery();<br />

Which of <strong>the</strong>se methods is more secure, and why?<br />

4. You are reviewing <strong>the</strong> codebase of a Java <strong>application</strong>. During initial reconnaissance,<br />

you search for all uses of <strong>the</strong> HttpServletRequest.getParameter<br />

API. The following code catches your eye:<br />

private void setWelcomeMessage(HttpServletRequest request) throws<br />

ServletException<br />

{<br />

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

if (name == null)<br />

name = “”;<br />

}<br />

m_welcomeMessage = “Welcome “ + name +”!”;<br />

What possible vulnerability might this code indicate? What fur<strong>the</strong>r code<br />

analysis would you need to perform to confirm whe<strong>the</strong>r <strong>the</strong> <strong>application</strong><br />

is indeed vulnerable?<br />

5. You are reviewing <strong>the</strong> mechanism that an <strong>application</strong> uses to generate<br />

session tokens. The relevant code is as follows:<br />

public class TokenGenerator<br />

{<br />

private java.util.Random r = new java.util.Random();<br />

public synchronized long nextToken()<br />

{<br />

long l = r.nextInt();<br />

long m = r.nextInt();<br />

}<br />

}<br />

return l + (m

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

Saved successfully!

Ooh no, something went wrong!