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.

Chapter 10 n Attacking Back-End Components 381<br />

if it is <strong>the</strong> filesystem root, and any redundant traversal sequences that attempt<br />

to step up above it are ignored. Chrooted filesystems are supported natively<br />

on most UNIX-based platforms. A similar effect can be achieved on Windows<br />

platforms (in relation to traversal vulnerabilities, at least) by mounting <strong>the</strong><br />

relevant start directory as a new logical drive and using <strong>the</strong> associated drive<br />

letter to access its contents.<br />

The <strong>application</strong> should integrate its defenses against path traversal attacks<br />

with its logging and alerting mechanisms. Whenever a request is received that<br />

contains path traversal sequences, this indicates likely malicious intent on <strong>the</strong><br />

user’s part. The <strong>application</strong> should log <strong>the</strong> request as an attempted security<br />

breach, terminate <strong>the</strong> user’s session, and, if applicable, suspend <strong>the</strong> user’s account<br />

and generate an alert to an administrator.<br />

File Inclusion Vulnerabilities<br />

Many scripting languages support <strong>the</strong> use of include files. This facility enables<br />

developers to place reusable code components into separate files and to include<br />

<strong>the</strong>se within function-specific code files as and when <strong>the</strong>y are needed. The code<br />

within <strong>the</strong> included file is interpreted just as if it had been inserted at <strong>the</strong> location<br />

of <strong>the</strong> include directive.<br />

Remote File Inclusion<br />

The PHP language is particularly susceptible to file inclusion vulnerabilities<br />

because its include functions can accept a remote file path. This has been <strong>the</strong><br />

basis of numerous vulnerabilities in PHP <strong>application</strong>s.<br />

Consider an <strong>application</strong> that delivers different content to people in different<br />

locations. When users choose <strong>the</strong>ir location, this is communicated to <strong>the</strong> server<br />

via a request parameter, as follows:<br />

https://wahh-app.com/main.php?Country=US<br />

The <strong>application</strong> processes <strong>the</strong> Country parameter as follows:<br />

$country = $_GET[‘Country’];<br />

include( $country . ‘.php’ );<br />

This causes <strong>the</strong> execution environment to load <strong>the</strong> file US.php that is located<br />

on <strong>the</strong> <strong>web</strong> server filesystem. The contents of this file are effectively copied into<br />

<strong>the</strong> main.php file and executed.

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

Saved successfully!

Ooh no, something went wrong!