forked from nian-hua/BurpExtender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntelligentAnalysis.py
279 lines (156 loc) · 6.7 KB
/
IntelligentAnalysis.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# -*- coding: utf-8 -*-
# Thursday, 4 April 2019
# Author:nianhua
# Blog:http://nianhua.in
# Python Import
import time
import json
import re
# Burp Import
from burp import IBurpExtender
from burp import IHttpListener
from burp import IMessageEditorTab
from burp import IMessageEditorTabFactory
# Java Import
from java.io import PrintWriter
class BurpExtender(IBurpExtender, IHttpListener, IMessageEditorTabFactory):
#
# implement IBurpExtender
#
def registerExtenderCallbacks(self, callbacks):
# keep a reference to our callbacks object
self._callbacks = callbacks
# obtain an extension helpers object
self._helpers = callbacks.getHelpers()
# set our extension name
callbacks.setExtensionName("Intelligent analysis")
# obtain our output streams
self._stdout = PrintWriter(callbacks.getStdout(), True)
# register ourselves as an HTTP listener
callbacks.registerHttpListener(self)
# register ourselves as an Tab factory
callbacks.registerMessageEditorTabFactory(self)
return
def createNewInstance(self, controller, editable):
# implement createNewInstance
return JSONDecoderTab(self, controller, editable)
def stringIsGps(self, Xhacker, string):
if Xhacker:
return False
if ("\"longitude\"" in string and "\"latitude\"" in string) or ("\"lat\"" in string and "\"lon\"" in string):
locations = re.findall(r'\d{2,3}\.\d{3,6}', string)
for location in locations:
if 3 < float(location) < 135:
print time.strftime("%Y-%m-%d %H:%M:%S Find:", time.localtime())
print location
return True
return False
def stringIsPhone(self, string):
iphones = re.findall(
r'[%"\'< ](?:13[012]\d{8}[%"\'< ]|15[56]\d{8}[%"\'< ]|18[56]\d{8}[%"\'< ]|176\d{8}[%"\'< ]|145\d{8}[%"\'< ]|13[456789]\d{8}[%"\'< ]|147\d{8}[%"\'< ]|178\d{8}[%"\'< ]|15[012789]\d{8}[%"\'< ]|18[23478]\d{8}[%"\'< ]|133\d{8}[%"\'< ]|153\d{8}[%"\'< ]|189\d{8}[%"\'< ])', string)
if iphones != []:
iphones = set(iphones)
print time.strftime("%Y-%m-%d %H:%M:%S Find:", time.localtime())
for iphone in iphones:
print str(iphone[:-1]),
print ""
return True
return False
def stringIsIdCard(self, string):
coefficient = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
parityBit = '10X98765432'
idcards = re.findall(
r'([1-8][1-7]\d{4}[1|2]\d{3}[0|1]\d{1}[1-3]\d{4}[0-9|X|x])', string)
if idcards != []:
for idcard in idcards:
sumnumber = 0
for i in range(17):
sumnumber += int(idcard[i]) * coefficient[i]
if parityBit[sumnumber % 11] == idcard[-1]:
print time.strftime("%Y-%m-%d %H:%M:%S Find:", time.localtime())
print idcard
return True
return False
#
# implement IHttpListener
#
def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo):
# only process response
if messageIsRequest:
return
content = messageInfo.getResponse()
r = self._helpers.analyzeResponse(content)
headers = content[:r.getBodyOffset()].tostring()
msg = content[r.getBodyOffset():].tostring()
Xhacker = True if "X-Hacker" in headers else False
if self.stringIsGps(Xhacker, msg):
messageInfo.setHighlight('green')
if self.stringIsPhone(msg):
messageInfo.setHighlight('blue')
if self.stringIsIdCard(msg):
messageInfo.setHighlight('red')
class JSONDecoderTab(IMessageEditorTab):
def __init__(self, extender, controller, editable):
self._extender = extender
self._helpers = extender._helpers
self._editable = editable
self._txtInput = extender._callbacks.createTextEditor()
self._txtInput.setEditable(editable)
self._jsonMark = ['{"', '["', '[{']
return
def getTabCaption(self):
return "JSON Decoder"
def getUiComponent(self):
return self._txtInput.getComponent()
def isEnabled(self, content, isRequest): # 始终显示该窗体
return True
def setMessage(self, content, isRequest):
if content is None:
self._txtInput.setText(None)
self._txtInput.setEditable(False)
else:
if isRequest:
r = self._helpers.analyzeRequest(content)
else:
r = self._helpers.analyzeResponse(content)
msg = content[r.getBodyOffset():].tostring()
try:
boundary = min(
msg.index('{') if '{' in msg else len(msg),
msg.index('[') if '[' in msg else len(msg)
)
except ValueError:
return
garbage = msg[:boundary]
clean = msg[boundary:]
try:
pretty_msg = garbage.strip() + '\n' + json.dumps(json.loads(clean), indent=4)
except:
pretty_msg = garbage + clean
self._txtInput.setText(pretty_msg)
self._txtInput.setEditable(self._editable)
self._currentMessage = content
return
def getMessage(self):
if self._txtInput.isTextModified(): # 判断用户是否修改了数据
try:
pre_data = self._txtInput.getText().tostring() # 检索当前正在显示的文本
boundary = min(pre_data.index('{') if '{' in pre_data else len(pre_data),
pre_data.index(
'[') if '[' in pre_data else len(pre_data)
)
garbage = pre_data[:boundary] # 分开乱七八糟
clean = pre_data[boundary:] # 分开clean数据
data = garbage + json.dumps(json.loads(clean)) # 获取数据
except:
data = self._helpers.bytesToString(
self._txtInput.getText()) # 原样的数据
# Reconstruct request/response #重构数据
r = self._helpers.analyzeRequest(self._currentMessage) # 再次获取
return self._helpers.buildHttpMessage(r.getHeaders(), self._helpers.stringToBytes(data))
else:
return self._currentMessage # 显示当前数据
def isModified(self):
return self._txtInput.isTextModified()
def getSelectedData(self):
return self._txtInput.getSelectedText()