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

In <strong>the</strong> preceding example, <strong>the</strong> attacker can supply <strong>the</strong> following input:<br />

*))%00<br />

The %00 sequence is decoded by <strong>the</strong> <strong>application</strong> server into a literal NULL byte,<br />

so when <strong>the</strong> input is embedded into <strong>the</strong> search filter, it becomes:<br />

(&(givenName=*))[NULL])(department=London*))<br />

Because this filter is truncated at <strong>the</strong> NULL byte, as far as LDAP is concerned it<br />

contains only a single wildcard condition, so <strong>the</strong> details of all employees from<br />

departments outside <strong>the</strong> London area are also returned.<br />

TRY IT!<br />

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

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

Finding LDAP Injection Flaws<br />

Supplying invalid input to an LDAP operation typically does not result in an<br />

informative error message. In general, <strong>the</strong> evidence available to you in diagnosing<br />

vulnerability includes <strong>the</strong> results returned by a search function and <strong>the</strong> occurrence<br />

of an error such as an HTTP 500 status code. Never<strong>the</strong>less, you can use <strong>the</strong><br />

following steps to identify an LDAP injection flaw with a degree of reliability.<br />

HACK STEPS<br />

1. Try entering just <strong>the</strong> * character as a search term. This character functions<br />

as a wildcard in LDAP, but not in SQL. If a large number of results are<br />

returned, this is a good indicator that you are dealing with an LDAP query.<br />

2. Try entering a number of closing brackets:<br />

))))))))))<br />

This input closes any brackets enclosing your input, as well as those<br />

that encapsulate <strong>the</strong> main search filter itself. This results in unmatched<br />

closing brackets, thus invalidating <strong>the</strong> query syntax. If an error results, <strong>the</strong><br />

<strong>application</strong> may be vulnerable to LDAP injection. (Note that this input may<br />

also break many o<strong>the</strong>r kinds of <strong>application</strong> logic, so this provides a strong<br />

indicator only if you are already confident that you are dealing with an<br />

LDAP query.)<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!