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.

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

placeholders and set <strong>the</strong>ir values in a secure and type-safe way. If used as<br />

intended, this mechanism is not vulnerable to SQL injection. For example:<br />

my $username = “admin’ or 1=1--”;<br />

my $password = “foo”;<br />

my $sql = $db_connection->prepare(“SELECT * FROM users<br />

WHERE username = ? AND password = ?”);<br />

$sql->execute($username, $password);<br />

results in a query that is equivalent to <strong>the</strong> following:<br />

SELECT * FROM users WHERE username = ‘admin’’ or 1=1--’<br />

AND password = ‘foo’<br />

Dynamic Code Execution<br />

eval can be used to dynamically execute a string containing Perl code. The<br />

semicolon delimiter can be used to batch multiple statements. If user-controllable<br />

data is passed into this function, <strong>the</strong> <strong>application</strong> is probably vulnerable to script<br />

injection.<br />

OS Command Execution<br />

The following functions can be used to execute operating system commands:<br />

n system<br />

n exec<br />

n qx<br />

n The backtick operator (`)<br />

In all <strong>the</strong>se cases, commands can be chained toge<strong>the</strong>r using <strong>the</strong> | character.<br />

If user-controllable data is passed unfiltered into any of <strong>the</strong>se functions, <strong>the</strong><br />

<strong>application</strong> is probably vulnerable to arbitrary command execution.<br />

URL Redirection<br />

The redirect function, which is a member of <strong>the</strong> CGI query object, takes a<br />

string containing a relative or absolute URL, to which <strong>the</strong> user is redirected. If<br />

<strong>the</strong> value of this string is user-controllable, <strong>the</strong> <strong>application</strong> is probably vulnerable<br />

to a phishing vector.

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

Saved successfully!

Ooh no, something went wrong!