Created
December 20, 2017 09:21
-
-
Save pajswigger/2c39132a9f44d0c416d9837c80b7f1cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from burp import IBurpExtender, IScannerInsertionPoint, IScannerInsertionPointProvider | |
import base64, jarray, re | |
class BurpExtender(IBurpExtender): | |
def registerExtenderCallbacks(self, callbacks): | |
callbacks.registerScannerInsertionPointProvider(BasicAuthInsertionPointProvider(callbacks)) | |
class BasicAuthInsertionPointProvider(IScannerInsertionPointProvider): | |
def __init__(self, callbacks): | |
self.callbacks = callbacks | |
def getInsertionPoints(self, baseRequestResponse): | |
request = baseRequestResponse.getRequest() | |
requestInfo = self.callbacks.getHelpers().analyzeRequest(request) | |
for header in requestInfo.getHeaders(): | |
if header.startswith("Authorization: Basic "): | |
return [BasicAuthInsertionPoint(request, 0), BasicAuthInsertionPoint(request, 1)] | |
class BasicAuthInsertionPoint(IScannerInsertionPoint): | |
def __init__(self, baseRequest, position): | |
self.baseRequest = ''.join(map(chr, baseRequest)) | |
self.position = position | |
match = re.search("^Authorization: Basic (.*)$", self.baseRequest, re.MULTILINE) | |
self.baseBlob = match.group(1) | |
self.baseValues = base64.b64decode(self.baseBlob).split(':') | |
self.baseOffset = self.baseRequest.index(self.baseBlob) | |
def getInsertionPointName(self): | |
return "BasicAuth" + ("UserName" if self.position == 0 else "Password") | |
def getBaseValue(self): | |
return self.baseValues[self.position] | |
def makeBlob(self, payload): | |
values = list(self.baseValues) | |
values[self.position] = ''.join(map(chr, payload)) | |
return base64.b64encode(':'.join(values)) | |
def buildRequest(self, payload): | |
return self.baseRequest.replace(self.baseBlob, self.makeBlob(payload)) | |
def getPayloadOffsets(self, payload): | |
return jarray.array([self.baseOffset, self.baseOffset + len(self.makeBlob(payload))], 'i') | |
def getInsertionPointType(self): | |
return IScannerInsertionPoint.INS_EXTENSION_PROVIDED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment