A simple BurpSuite Jython extension to capture https traffic, which is used in the passive scanning.
BurpSuite Jython Extension
In order to glean the vulnerability detection information and avoid scanning the massive useless URLs of the websites, I prefer using passive scanner during my daily work.
I’d like to use BurpSuite to analyze URLs and store them in the database for the next passive scanning process via socket tunnel. But here comes the problem, BurpSuite cannot transfer https flow to another place, so I wrote a simple Jython script as the disposal.
Tutorial about writing a Jython extension can be found everywhere. Here I put the main code
defprocessHttpMessage(self, toolFlag, messageIsRequest, messageInfo): # only process requests ifnot messageIsRequest: # create a new log entry with the message details self._lock.acquire() row = self._log.size() req = self._helpers.analyzeRequest(messageInfo) LE = LogEntry(toolFlag, self._callbacks.saveBuffersToTempFiles(messageInfo), req.getUrl()) self._log.add(LE) try: params = req.getParameters() pas = [] pnames = [] for pa in params: pnames.append(pa.getName()) pas.append(pa.getName()+"="+pa.getValue()) #pas = pas.join('&') values = {"docs":[{"TIME":time.time(),"URL":LE._url.toString(),"PNames":'&'.join(pnames),"Method":req.getMethod(),"HOST":LE._url.getHost(),"PATH":LE._url.getPath(),"PARAM":'&'.join(pas),"REQ":LE._requestResponse.getRequest().tostring(),"RESP":LE._requestResponse.getResponse().tostring(),"USER":"test"}]} #data = 'docs=[{"URL":"'+LE._url.toString()+'","REQ":"'+urllib.quote(LE._requestResponse.getRequest().tostring())+'","RESP":"'+urllib.quote(LE._requestResponse.getResponse().tostring())+'"}]' # data = "docs="+urllib.quote(json.dumps(values['docs'], sort_keys=True)) send_data = {} req_url = LE._url.toString() req_headers, req_body = split_req(LE._requestResponse.getRequest().tostring()) o = urlparse(req_url) req_host = o.netloc req_headers['Host'] = req_host req_method = req.getMethod() data = extract_request(req_url, req_headers, req_method, req_body) send_data['req_url'] = req_url send_data['req_headers'], send_data['req_body'] = req_headers, req_body send_data['req_host'] = req_host send_data['req_method'] = req_method send_data['data'] = data print(send_data)
target_url = "http://192.168.10.57:8888" res = urllib2.Request(target_url, str(send_data)) threading.Thread(target=urllib2.urlopen, args=(res,)).start()
except: pass self.fireTableRowsInserted(row, row) self._lock.release() return defextract_request(url, headers, method, body): try: a = re.search('://.*?/(.*)', url) except: pass url = ('/' + a.group(1)) if a isnotNoneelse'/' requests = "%s %s\r\n" % (method, url) for key, value in headers.items(): requests += "%s: %s\r\n" % (key, value) requests += "\r\n%s" % body return requests
the function extract_request(url, headers, method, body) is used to transform requests and the processHttpMessage(self, toolFlag, messageIsRequest, messageInfo) function is used to send the BurpSuite URLs to another server which is started locally. Sure, there’s no need to do such complicated work, but I can’t find some modules(redis) I need in Jython, maybe you have better ideas I don’t know…Start a server
The function content_deal() is declared in the passive scanner system which written in python.
one last thing we should pay attention to is that if we decide to use BurpSuite to transfer the https data, we must import the BurpSuite certificate. Of course, in addition to using BurpSuite, we also have many other choices, such as sslsplit, mitmproxy…and we need to import the right certificates by the same.