-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathc1_session_action.py
81 lines (59 loc) · 2.69 KB
/
c1_session_action.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
71
72
73
74
75
76
77
78
79
80
81
# References
# https://github.com/PortSwigger/example-custom-session-tokens/
# https://github.com/PortSwigger/example-custom-session-tokens/blob/master/python/SessionTokens.py
# https://www.twelvesec.com/2017/05/05/authorization-token-manipulation/
# https://github.com/securityMB/burp-exceptions
from exceptions_fix import FixBurpExceptions
import json
import datetime
from burp import IBurpExtender
from burp import IBurpExtenderCallbacks
from burp import ISessionHandlingAction
class BurpExtender(IBurpExtender, ISessionHandlingAction):
#
# Define Extension Name
#
NAME = "Custom Authorization Header Handler"
#
# Implement IBurpExtender Methods
#
def registerExtenderCallbacks(self, callbacks):
# save helper functions to use in other methods in class
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
# set Extension name
callbacks.setExtensionName(self.NAME)
# tell Burp this extension uses Session Handling Action
self._callbacks.registerSessionHandlingAction(self)
# print out for extension loaded
print("Custom Authorization Header Handler Loaded")
return
# set action name in session handling
def getActionName(self):
return self.NAME
# main function to operate on the request
def performAction(self, currentRequest, macroItems):
# extract current request values
request_info = self._helpers.analyzeRequest(currentRequest)
# get response body for the macro issued request
macro_response_info = self._helpers.analyzeResponse(macroItems[0].getResponse())
macro_msg = macroItems[0].getResponse()
resp_body = macro_msg[macro_response_info.getBodyOffset():]
macro_body_string = self._helpers.bytesToString(resp_body)
# parse JSON and retrieve token in response body
login_resp = json.loads(macro_body_string)
print('Macro Response Body: %s',login_resp)
# todo: get token
# retrieve headers in current request and
# reconstruct it with token value
req_headers = request_info.getHeaders()
req_body = currentRequest.getRequest()[request_info.getBodyOffset():]
# todo - remove existing header/value in request
# add header and value to request
req_headers.add(TODO)
# build request with bypass headers
message = self._helpers.buildHttpMessage(req_headers, req_body)
# update Request with New Header
currentRequest.setRequest(message)
return
FixBurpExceptions()