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

print “$command\n”;<br />

print end_html;<br />

When used as intended, this script simply appends <strong>the</strong> value of <strong>the</strong> usersupplied<br />

dir parameter to <strong>the</strong> end of a preset command, executes <strong>the</strong> command,<br />

and displays <strong>the</strong> results, as shown in Figure 10-1.<br />

Figure 10-1: A simple <strong>application</strong> function for listing a directory’s contents<br />

This functionality can be exploited in various ways by supplying crafted input<br />

containing shell metacharacters. These characters have a special meaning to<br />

<strong>the</strong> interpreter that processes <strong>the</strong> command and can be used to interfere with<br />

<strong>the</strong> command that <strong>the</strong> developer intended to execute. For example, <strong>the</strong> pipe<br />

character (|) is used to redirect <strong>the</strong> output from one process into <strong>the</strong> input of<br />

ano<strong>the</strong>r, enabling multiple commands to be chained toge<strong>the</strong>r. An attacker can<br />

leverage this behavior to inject a second command and retrieve its output, as<br />

shown in Figure 10-2.<br />

Here, <strong>the</strong> output from <strong>the</strong> original du command has been redirected as <strong>the</strong><br />

input to <strong>the</strong> command cat/etc/passwd. This command simply ignores <strong>the</strong><br />

input and performs its sole task of outputting <strong>the</strong> contents of <strong>the</strong> passwd file.<br />

An attack as simple as this may appear improbable; however, exactly this type<br />

of command injection has been found in numerous commercial products. For<br />

example, HP OpenView was found to be vulnerable to a command injection<br />

flaw within <strong>the</strong> following URL:<br />

https://target:3443/OvCgi/connectedNodes.ovpl?node=a| [your command] |

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

Saved successfully!

Ooh no, something went wrong!