-
Notifications
You must be signed in to change notification settings - Fork 0
/
umburpo.py
70 lines (50 loc) · 2.04 KB
/
umburpo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Created May 2017 by Rob Brown : https://twitter.com/RB256
from burp import IBurpExtender
from burp import IHttpListener
from burp import IParameter
from java.io import PrintWriter
import base64
import binascii
import re
BASE64_CHARS = re.compile("^([a-z]|[A-Z]|[0-9]|\+|\/|=)*?$")
class BurpExtender(IBurpExtender, IHttpListener, IParameter):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
callbacks.setExtensionName ("Umburpo")
self._stdout = PrintWriter(callbacks.getStdout(), True)
callbacks.registerHttpListener(self)
return
def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo):
self._stdout.println(
("HTTP request to " if messageIsRequest else "HTTP response from ") +
messageInfo.getHttpService().toString() +
" [" + self._callbacks.getToolName(toolFlag) + "]")
if not messageIsRequest:
return
if toolFlag == self._callbacks.TOOL_PROXY:
return
self._stdout.println("Lets do it")
rawRequest = messageInfo.getRequest()
request = self._helpers.analyzeRequest(rawRequest)
params = request.getParameters()
sParam = next((x for x in params if x.getType() == self.PARAM_URL and x.getName() == "s"), None)
if sParam is None:
self._stdout.println("Param not found")
return
self._stdout.println("Param found")
minifyFileParam = sParam.getValue()
needsB64ing = False
self._stdout.println("Lets see if we need to encode it")
try:
base64.decodestring(minifyFileParam)
except binascii.Error:
needsB64ing = True
is_only_b64 = BASE64_CHARS.match(minifyFileParam)
if is_only_b64 is None:
needsB64ing = True
if needsB64ing:
self._stdout.println("Converting from " + minifyFileParam)
messageInfo.setRequest(self._helpers.updateParameter(rawRequest, self._helpers.buildParameter("s", self._helpers.base64Encode(minifyFileParam), self.PARAM_URL)))
else:
self._stdout.println("Already encoded")