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.

352 Chapter 9 n Attacking Data Stores<br />

Conjunctive Queries<br />

Consider a similar <strong>application</strong> function that allows users to search for employees<br />

by name, again within <strong>the</strong> geographic region <strong>the</strong>y are authorized to view.<br />

If a user is authorized to search within <strong>the</strong> London location, and he searches<br />

for <strong>the</strong> name daf, <strong>the</strong> following query is performed:<br />

(&(givenName=daf)(department=London*))<br />

Here, <strong>the</strong> user’s input is inserted into a conjunctive query, <strong>the</strong> second part of<br />

which enforces <strong>the</strong> required access control by matching items in only one of<br />

<strong>the</strong> London departments.<br />

In this situation, two different attacks might succeed, depending on <strong>the</strong><br />

details of <strong>the</strong> back-end LDAP service. Some LDAP implementations, including<br />

OpenLDAP, allow multiple search filters to be batched, and <strong>the</strong>se are applied<br />

disjunctively. (In o<strong>the</strong>r words, directory entries are returned that match any of<br />

<strong>the</strong> batched filters.) For example, an attacker could supply <strong>the</strong> following input:<br />

*))(&(givenName=daf<br />

When this input is embedded into <strong>the</strong> original search filter, it becomes:<br />

(&(givenName=*))(&(givenName=daf)(department=London*))<br />

This now contains two search filters, <strong>the</strong> first of which contains a single<br />

wildcard match condition. The details of all employees are returned from all<br />

locations, <strong>the</strong>reby subverting <strong>the</strong> <strong>application</strong>’s access control.<br />

TRY IT!<br />

http://mdsec.net/employees/42/<br />

NOTE This technique of injecting a second search filter is also effective<br />

against simple match conditions that do not employ any logical operator, provided<br />

that <strong>the</strong> back-end implementation accepts multiple search filters.<br />

The second type of attack against conjunctive queries exploits how many LDAP<br />

implementations handle NULL bytes. Because <strong>the</strong>se implementations typically are<br />

written in native code, a NULL byte within a search filter effectively terminates <strong>the</strong><br />

string, and any characters coming after <strong>the</strong> NULL are ignored. Although LDAP<br />

does not itself support comments (in <strong>the</strong> way that <strong>the</strong> -- sequence can be used<br />

in SQL), this handling of NULL bytes can effectively be exploited to “comment<br />

out” <strong>the</strong> remainder of <strong>the</strong> query.

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

Saved successfully!

Ooh no, something went wrong!