Last active
June 14, 2018 10:12
-
-
Save pajswigger/c1fff3ce6e5637126ff92bf57fba54e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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