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 9 n Attacking Data Stores 349<br />

Hence, in any situation where your tests for SQL injection provide tentative<br />

evidence for a vulnerability, but you are unable to conclusively exploit <strong>the</strong> flaw,<br />

you should investigate <strong>the</strong> possibility that you are dealing with an XPath injection<br />

flaw.<br />

HACK STEPS<br />

1. Try submitting <strong>the</strong> following values, and determine whe<strong>the</strong>r <strong>the</strong>se result<br />

in different <strong>application</strong> behavior, without causing an error:<br />

‘ or count(parent::*[position()=1])=0 or ‘a’=’b<br />

‘ or count(parent::*[position()=1])>0 or ‘a’=’b<br />

If <strong>the</strong> parameter is numeric, also try <strong>the</strong> following test strings:<br />

1 or count(parent::*[position()=1])=0<br />

1 or count(parent::*[position()=1])>0<br />

2. If any of <strong>the</strong> preceding strings causes differential behavior within <strong>the</strong><br />

<strong>application</strong> without causing an error, it is likely that you can extract arbitrary<br />

data by crafting test conditions to extract one byte of information at<br />

a time. Use a series of conditions with <strong>the</strong> following form to determine<br />

<strong>the</strong> name of <strong>the</strong> current node’s parent:<br />

substring(name(parent::*[position()=1]),1,1)=’a’<br />

3. Having extracted <strong>the</strong> name of <strong>the</strong> parent node, use a series of conditions<br />

with <strong>the</strong> following form to extract all <strong>the</strong> data within <strong>the</strong> XML tree:<br />

substring(//parentnodename[position()=1]/child::node()<br />

[position()=1]/text(),1,1)=’a’<br />

Preventing XPath Injection<br />

If you think it is necessary to insert user-supplied input into an XPath query,<br />

this operation should only be performed on simple items of data that can be<br />

subjected to strict input validation. The user input should be checked against<br />

a white list of acceptable characters, which should ideally include only alphanumeric<br />

characters. Characters that may be used to interfere with <strong>the</strong> XPath<br />

query should be blocked, including ( ) = ‘ [ ] : , * / and all whitespace.<br />

Any input that does not match <strong>the</strong> white list should be rejected, not sanitized.<br />

Injecting into LDAP<br />

The Lightweight Directory Access Protocol (LDAP) is used to access directory<br />

services over a network. A directory is a hierarchically organized data store that<br />

may contain any kind of information but is commonly used to store personal<br />

data such as names, telephone numbers, e-mail addresses, and job functions.

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

Saved successfully!

Ooh no, something went wrong!