Created
September 14, 2013 05:47
-
-
Save coffeetocode/6559127 to your computer and use it in GitHub Desktop.
Code sample included with "Burp Extensions in Python & Pentesting Custom Web Services" at http://labs.neohapsis.com/
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
# These are java classes, being imported using python syntax (Jython magic) | |
from burp import IBurpExtender | |
from burp import IHttpListener | |
# These are plain old python modules, from the standard library | |
# (or from the "Folder for loading modules" in Burp>Extender>Options) | |
from datetime import datetime | |
class BurpExtender(IBurpExtender, IHttpListener): | |
def registerExtenderCallbacks(self, callbacks): | |
self._callbacks = callbacks | |
self._helpers = callbacks.getHelpers() | |
callbacks.setExtensionName("Burp Plugin Python Demo") | |
callbacks.registerHttpListener(self) | |
return | |
def processHttpMessage(self, toolFlag, messageIsRequest, currentRequest): | |
# only process requests | |
if not messageIsRequest: | |
return | |
requestInfo = self._helpers.analyzeRequest(currentRequest) | |
timestamp = datetime.now() | |
print "Intercepting message at:", timestamp.isoformat() | |
headers = requestInfo.getHeaders() | |
newHeaders = list(headers) #it's a Java arraylist; get a python list | |
newHeaders.append("Timestamp: " + timestamp.isoformat()) | |
bodyBytes = currentRequest.getRequest()[requestInfo.getBodyOffset():] | |
bodyStr = self._helpers.bytesToString(bodyBytes) | |
newMsgBody = bodyStr + timestamp.isoformat() | |
newMessage = self._helpers.buildHttpMessage(newHeaders, newMsgBody) | |
print "Sending modified message:" | |
print "----------------------------------------------" | |
print self._helpers.bytesToString(newMessage) | |
print "----------------------------------------------\n\n" | |
currentRequest.setRequest(newMessage) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment