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

In some cases, it may not be possible to inject an entirely separate command<br />

due to filtering of required characters or <strong>the</strong> behavior of <strong>the</strong> command<br />

API being used by <strong>the</strong> <strong>application</strong>. Never<strong>the</strong>less, it may still be possible to<br />

interfere with <strong>the</strong> behavior of <strong>the</strong> command being performed to achieve<br />

some desired result.<br />

In one instance seen by <strong>the</strong> authors, <strong>the</strong> <strong>application</strong> passed user input<br />

to <strong>the</strong> operating system command nslookup to find <strong>the</strong> IP address of a<br />

domain name supplied by <strong>the</strong> user. The metacharacters needed to inject new<br />

commands were being blocked, but <strong>the</strong> < and > characters used to redirect<br />

<strong>the</strong> command’s input and output were allowed. The nslookup command<br />

usually outputs <strong>the</strong> IP address for a domain name, which did not seem to<br />

provide an effective attack vector. However, if an invalid domain name is<br />

supplied, <strong>the</strong> command outputs an error message that includes <strong>the</strong> domain<br />

name that was looked up. This behavior proved sufficient to deliver a<br />

serious attack:<br />

n Submit a fragment of server-executable script code as <strong>the</strong> domain name<br />

to be resolved. The script can be encapsulated in quotes to ensure that<br />

<strong>the</strong> command interpreter treats it as a single token.<br />

n Use <strong>the</strong> > character to redirect <strong>the</strong> command’s output to a file in an executable<br />

folder within <strong>the</strong> <strong>web</strong> root. The command executed by <strong>the</strong> operating<br />

system is as follows:<br />

nslookup “[script code]” > [/path/to/executable_file]<br />

n When <strong>the</strong> command is run, <strong>the</strong> following output is redirected to <strong>the</strong> executable<br />

file:<br />

** server can’t find [script code]: NXDOMAIN<br />

n This file can <strong>the</strong>n be invoked using a browser, and <strong>the</strong> injected script<br />

code is executed on <strong>the</strong> server. Because most scripting languages allow<br />

pages to contain a mix of client-side content and server-side markup,<br />

<strong>the</strong> parts of <strong>the</strong> error message that <strong>the</strong> attacker does not control are<br />

just treated as plain text, and <strong>the</strong> markup within <strong>the</strong> injected script is<br />

executed. The attack <strong>the</strong>refore succeeds in leveraging a restricted command<br />

injection condition to introduce an unrestricted backdoor into <strong>the</strong><br />

<strong>application</strong> server.<br />

TRY IT!<br />

http://mdsec.net/admin/18/

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

Saved successfully!

Ooh no, something went wrong!