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 10 n Attacking Back-End Components 367<br />

HACK STEPS<br />

1. Any item of user-supplied data may be passed to a dynamic execution<br />

function. Some of <strong>the</strong> items most commonly used in this way are <strong>the</strong><br />

names and values of cookie parameters and persistent data stored in user<br />

profiles as <strong>the</strong> result of previous actions.<br />

2. Try submitting <strong>the</strong> following values in turn as each targeted parameter:<br />

;echo%20111111<br />

echo%20111111<br />

response.write%20111111<br />

:response.write%20111111<br />

3. Review <strong>the</strong> <strong>application</strong>’s responses. If <strong>the</strong> string 111111 is returned on its<br />

own (is not preceded by <strong>the</strong> rest of <strong>the</strong> command string), <strong>the</strong> <strong>application</strong><br />

is likely to be vulnerable to <strong>the</strong> injection of scripting commands.<br />

4. If <strong>the</strong> string 111111 is not returned, look for any error messages that indicate<br />

that your input is being dynamically executed and that you may need<br />

to fine-tune your syntax to achieve injection of arbitrary commands.<br />

5. If <strong>the</strong> <strong>application</strong> you are attacking uses PHP, you can use <strong>the</strong> test string<br />

phpinfo(), which, if successful, returns <strong>the</strong> configuration details of <strong>the</strong><br />

PHP environment.<br />

6. If <strong>the</strong> <strong>application</strong> appears to be vulnerable, verify this by injecting some<br />

commands that result in time delays, as described previously for OS command<br />

injection. For example:<br />

system(‘ping%20127.0.0.1’)<br />

Preventing OS Command Injection<br />

In general, <strong>the</strong> best way to prevent OS command injection flaws from arising<br />

is to avoid calling out directly to operating system commands. Virtually any<br />

conceivable task that a <strong>web</strong> <strong>application</strong> may need to carry out can be achieved<br />

using built-in APIs that cannot be manipulated to perform commands o<strong>the</strong>r<br />

than <strong>the</strong> one intended.<br />

If it is considered unavoidable to embed user-supplied data into command<br />

strings that are passed to an operating system command interpreter, <strong>the</strong> <strong>application</strong><br />

should enforce rigorous defenses to prevent a vulnerability from arising.<br />

If possible, a whitelist should be used to restrict user input to a specific set of<br />

expected values. Alternatively, <strong>the</strong> input should be restricted to a very narrow<br />

character set, such as alphanumeric characters only. Input containing any o<strong>the</strong>r<br />

data, including any conceivable metacharacter or whitespace, should be rejected.

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

Saved successfully!

Ooh no, something went wrong!