Skip to content

Instantly share code, notes, and snippets.

@pajswigger
Last active June 14, 2018 10:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pajswigger/c1fff3ce6e5637126ff92bf57fba54e1 to your computer and use it in GitHub Desktop.
Save pajswigger/c1fff3ce6e5637126ff92bf57fba54e1 to your computer and use it in GitHub Desktop.
package burp;
import java.util.Random;
public class BuildUnencodedRequest
{
private Random random = new Random();
private IExtensionHelpers helpers;
BuildUnencodedRequest(IExtensionHelpers helpers)
{
this.helpers = helpers;
}
byte[] buildUnencodedRequest(IScannerInsertionPoint iScannerInsertionPoint, byte[] payload) throws Exception
{
byte[] canary = buildCanary(payload.length);
byte[] request = iScannerInsertionPoint.buildRequest(canary);
int canaryPos = findCanary(canary, request);
System.arraycopy(payload, 0, request, canaryPos, payload.length);
return request;
}
private byte[] buildCanary(int payloadLength)
{
byte[] canary = new byte[payloadLength];
for(int i = 0; i < payloadLength; i++)
{
canary[i] = (byte) '§';
}
return canary;
}
private int findCanary(byte[] canary, byte[] request) throws Exception
{
int canaryPos = helpers.indexOf(request, canary, false, 0, request.length);
if(canaryPos == -1)
{
throw new Exception("Cannot locate canary in request");
}
int canaryPos2 = helpers.indexOf(request, canary, false, canaryPos + 1, request.length);
if(canaryPos2 != -1)
{
throw new Exception("Multiple canary found in request");
}
return canaryPos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment