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.

580 Chapter 14 n Automating Customized Attacks<br />

This configuration includes <strong>the</strong> basic target information, creates a single<br />

request parameter called PageNo, and configures our numeric payload source<br />

to cycle through <strong>the</strong> range 10060 to 10080.<br />

To cycle through a series of requests, potentially targeting multiple parameters,<br />

we need to maintain some state. Let’s use a simple nextRequest method to<br />

advance <strong>the</strong> state of our request engine, returning true until no more requests<br />

remain:<br />

// attack state<br />

int currentParam = 0;<br />

boolean nextRequest()<br />

{<br />

if (currentParam >= params.length)<br />

return false;<br />

if (!params[currentParam].attack)<br />

{<br />

currentParam++;<br />

return nextRequest();<br />

}<br />

if (!payloads.nextPayload())<br />

{<br />

payloads.reset();<br />

currentParam++;<br />

return nextRequest();<br />

}<br />

}<br />

return true;<br />

This stateful request engine keeps track of which parameter we are currently<br />

targeting and which attack payload to place into it. The next step is to actually<br />

build a complete HTTP request using this information. This involves inserting<br />

each type of parameter into <strong>the</strong> correct place in <strong>the</strong> request and adding any<br />

o<strong>the</strong>r required headers:<br />

String buildRequest()<br />

{<br />

// build parameters<br />

StringBuffer urlParams = new StringBuffer();<br />

StringBuffer cookieParams = new StringBuffer();<br />

StringBuffer bodyParams = new StringBuffer();<br />

for (int i = 0; i < params.length; i++)<br />

{<br />

String value = (i == currentParam) ?<br />

payloads.getPayload() :<br />

params[i].value;

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

Saved successfully!

Ooh no, something went wrong!