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.

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

Detecting Path Traversal Vulnerabilities<br />

Having identified <strong>the</strong> various potential targets for path traversal testing, you<br />

need to test every instance individually to determine whe<strong>the</strong>r user-controllable<br />

data is being passed to relevant filesystem operations in an unsafe manner.<br />

For each user-supplied parameter being tested, determine whe<strong>the</strong>r traversal<br />

sequences are being blocked by <strong>the</strong> <strong>application</strong> or whe<strong>the</strong>r <strong>the</strong>y work as expected.<br />

An initial test that is usually reliable is to submit traversal sequences in a way<br />

that does not involve stepping back above <strong>the</strong> starting directory.<br />

HACK STEPS<br />

1. Working on <strong>the</strong> assumption that <strong>the</strong> parameter you are targeting is being<br />

appended to a preset directory specified by <strong>the</strong> <strong>application</strong>, modify <strong>the</strong><br />

parameter’s value to insert an arbitrary subdirectory and a single traversal<br />

sequence. For example, if <strong>the</strong> <strong>application</strong> submits this parameter:<br />

file=foo/file1.txt<br />

try submitting this value:<br />

file=foo/bar/../file1.txt<br />

If <strong>the</strong> <strong>application</strong>’s behavior is identical in <strong>the</strong> two cases, it may be vulnerable.<br />

You should proceed directly to attempting to access a different<br />

file by traversing above <strong>the</strong> start directory.<br />

2. If <strong>the</strong> <strong>application</strong>’s behavior is different in <strong>the</strong> two cases, it may be blocking,<br />

stripping, or sanitizing traversal sequences, resulting in an invalid file<br />

path. You should examine whe<strong>the</strong>r <strong>the</strong>re are any ways to circumvent <strong>the</strong><br />

<strong>application</strong>’s validation filters (described in <strong>the</strong> next section).<br />

The reason why this test is effective, even if <strong>the</strong> subdirectory “bar” does<br />

not exist, is that most common filesystems perform canonicalization of<br />

<strong>the</strong> file path before attempting to retrieve it. The traversal sequence cancels<br />

out <strong>the</strong> invented directory, so <strong>the</strong> server does not check whe<strong>the</strong>r it is<br />

present.<br />

If you find any instances where submitting traversal sequences without stepping<br />

above <strong>the</strong> starting directory does not affect <strong>the</strong> <strong>application</strong>’s behavior, <strong>the</strong><br />

next test is to attempt to traverse out of <strong>the</strong> starting directory and access files<br />

from elsewhere on <strong>the</strong> server filesystem.

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

Saved successfully!

Ooh no, something went wrong!