19.09.2017 Views

the-web-application-hackers-handbook

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

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

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

checks whe<strong>the</strong>r <strong>the</strong> redirection URL contains a double slash (as in http://). If it<br />

does, <strong>the</strong> script skips past <strong>the</strong> double slash to <strong>the</strong> first single slash, <strong>the</strong>reby converting<br />

it into a relative URL. However, <strong>the</strong> script <strong>the</strong>n makes a final call to <strong>the</strong><br />

unescape() function, which unpacks any URL-encoded characters. Performing<br />

canonicalization after validation often leads to a vulnerability (see Chapter 2).<br />

In this instance an attacker can cause a redirect to an arbitrary absolute URL<br />

with <strong>the</strong> following query string:<br />

?redir=http:%25252f%25252fwahh-attacker.com<br />

OS Command Injection<br />

Code that interfaces with external systems often contains signatures indicating<br />

code injection flaws. In <strong>the</strong> following example, <strong>the</strong> message and address<br />

parameters have been extracted from user-controllable form data and are passed<br />

directly into a call to <strong>the</strong> UNIX system API:<br />

void send_mail(const char *message, const char *addr)<br />

{<br />

char sendMailCmd[4096];<br />

snprintf(sendMailCmd, 4096, “echo ‘%s’ | sendmail %s”, message, addr);<br />

system(sendMailCmd);<br />

return;<br />

}<br />

Backdoor Passwords<br />

Unless <strong>the</strong>y have been deliberately concealed by a malicious programmer,<br />

backdoor passwords that have been used for testing or administrative purposes<br />

usually stand out when you review credential validation logic. For example:<br />

private UserProfile validateUser(String username, String password)<br />

{<br />

UserProfile up = getUserProfile(username);<br />

if (checkCredentials(up, password) ||<br />

“oculiomnium”.equals(password))<br />

return up;<br />

}<br />

return null;<br />

O<strong>the</strong>r items that may be easily identified in this way include unreferenced<br />

functions and hidden debug parameters.

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

Saved successfully!

Ooh no, something went wrong!