forked from stephenbrannon/IOCextractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIOCextractor.py
executable file
·427 lines (366 loc) · 22 KB
/
IOCextractor.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#This script helps extract indicators of compromise (IOCs) from a text file.
#A user can add or remove tagged indicators then export the remaining tags.
#Usage: "python IOCextractor.py" or "python IOCextractor.py document.txt"
#2012 Stephen Brannon, Verizon RISK Team
import re
import sys
from Tkinter import *
from tkFileDialog import askopenfilename, asksaveasfilename, askdirectory
import cybox.api as cybox_api
try:
from ioc_writer import ioc_api, ioc_common
ioc_writer_available = True
except ImportError, e:
print 'ERROR: Could not load ioc_writer. Will not be able to export IOCs in OpenIOC 1.1 format.'
ioc_writer_available = False
tags = ['md5', 'ipv4', 'url', 'domain', 'email']
reMD5 = r"([A-F]|[0-9]){32}"
reIPv4 = r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|\[\.\])){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
reURL = r"[A-Z0-9\-\.\[\]]+(\.|\[\.\])(XN--CLCHC0EA0B2G2A9GCD|XN--HGBK6AJ7F53BBA|XN--HLCJ6AYA9ESC7A|XN--11B5BS3A9AJ6G|XN--MGBERP4A5D4AR|XN--XKC2DL3A5EE0H|XN--80AKHBYKNJ4F|XN--XKC2AL3HYE2A|XN--LGBBAT1AD8J|XN--MGBC0A9AZCG|XN--9T4B11YI5A|XN--MGBAAM7A8H|XN--MGBAYH7GPA|XN--MGBBH1A71E|XN--FPCRJ9C3D|XN--FZC2C9E2C|XN--YFRO4I67O|XN--YGBI2AMMX|XN--3E0B707E|XN--JXALPDLP|XN--KGBECHTV|XN--OGBPF8FL|XN--0ZWM56D|XN--45BRJ9C|XN--80AO21A|XN--DEBA0AD|XN--G6W251D|XN--GECRJ9C|XN--H2BRJ9C|XN--J6W193G|XN--KPRW13D|XN--KPRY57D|XN--PGBS0DH|XN--S9BRJ9C|XN--90A3AC|XN--FIQS8S|XN--FIQZ9S|XN--O3CW4H|XN--WGBH1C|XN--WGBL6A|XN--ZCKZAH|XN--P1AI|MUSEUM|TRAVEL|AERO|ARPA|ASIA|COOP|INFO|JOBS|MOBI|NAME|BIZ|CAT|COM|EDU|GOV|INT|MIL|NET|ORG|PRO|TEL|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|DM|DO|DZ|EC|EE|EG|ER|ES|ET|EU|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|IO|IQ|IR|IS|IT|JE|JM|JO|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|ME|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|ST|SU|SV|SX|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TP|TR|TT|TV|TW|TZ|UA|UG|UK|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|ZA|ZM|ZW)\b"
def dotToNum(ip): return int(''.join(["%02x"%int(i) for i in ip.split('.')]),16)
def tag_initial():
lines = text.get(1.0, 'end').split('\n')
#md5
text.tag_configure('md5', background='#FE6AA8')
linenumber = 1
for line in lines:
for m in re.finditer(reMD5, line, re.IGNORECASE):
text.tag_add('md5',str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
linenumber += 1
#ipv4
text.tag_configure('ipv4', background='#6CB23E')
linenumber = 1
for line in lines:
for m in re.finditer(reIPv4, line, re.IGNORECASE):
result = text.get(str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
result = result.replace('[','').replace(']','') #remove brackets
#reject private, link-local, and loopback IPs
if result.find('10.') != 0 and \
result.find('192.168') != 0 and \
result.find('127') != 0:
if (dotToNum(result) < dotToNum('172.16.0.0') or \
dotToNum(result) > dotToNum('172.31.255.255')) and \
(dotToNum(result) < dotToNum('169.254.1.0') or \
dotToNum(result) > dotToNum('169.254.254.255')):
text.tag_add('ipv4',str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
linenumber += 1
#url
text.tag_configure('url', background='#378A20')
linenumber = 1
for line in lines:
for m in re.finditer(reURL, line, re.IGNORECASE):
result = text.get(str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
end = m.end()
#drop trailing punctuation
while (u'.,\u201d"\'\u2019').find(result[len(result)-1:len(result)]) != -1:
result = result[:len(result)-1]
end -= 1
text.tag_add('url',str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(end))
linenumber += 1
#domain
text.tag_configure('domain', background='#5DC5D1')
linenumber = 1
for line in lines:
for m in re.finditer(reDomain, line, re.IGNORECASE):
#reject if preceding character is @ or following character is /
if not text.get(str(linenumber) + '.' + str(m.start()-1), str(linenumber) + '.' + str(m.start())) == '@':
if not text.get(str(linenumber) + '.' + str(m.end()), str(linenumber) + '.' + str(m.end()+1)) == '/':
text.tag_add('domain',str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
linenumber += 1
#email
text.tag_configure('email', background='#0224F2')
linenumber = 1
for line in lines:
for m in re.finditer(reEmail, line, re.IGNORECASE):
#reject verizon emails
result = text.get(str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
if result.find('@verizon.com') == -1 and \
result.find('@verizonbusiness.com') == -1 and \
result.find('@one.verizon.com') == -1 and \
result.find('@jp.verizonbusiness.com') == -1:
text.tag_add('email',str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
linenumber += 1
def askopen(filename = ''):
if filename == '':
filename = askopenfilename(title="Select plain-text file", filetypes=[("txt file",".txt"),("All files",".*")])
if filename != '':
with open(filename, 'rb') as f: #read as binary
doc = f.read()
doc = doc.decode('utf_8', 'ignore') #drop any non-ascii bytes
#if a carriage return is orphaned, replace it with a new line
doc = list(doc)
i = 0
while (i < len(doc) - 1):
if ord(doc[i]) == 13: #it's a carriage return
if ord(doc[i + 1]) != 10: #it's not followed by a new line
doc[i] = chr(10) #replace it with a new line
i += 1
if ord(doc[len(doc)-1]) == 13: #end
doc[len(doc)-1] = chr(10)
#drop carriage returns
i = 0
while (i < len(doc) - 1):
if ord(doc[i]) == 13: #it's a carriage return
doc.pop(i)
else:
i += 1
doc = ''.join(doc)
text.delete('1.0',END)
text.insert('1.0', doc)
tag_initial()
root.title(filename + ' - IOCextractor')
def clear_tag(holder = 0):
if len(text.tag_ranges("sel")) != 0: #selection is not empty
#untag all occurrences of selected string
key = text.get(text.tag_ranges("sel")[0], text.tag_ranges("sel")[1])
lines = text.get(1.0, 'end').split('\n')
linenumber = 1
for line in lines:
for m in re.finditer(re.escape(key), line, re.IGNORECASE):
for t in tags:
text.tag_remove(t, str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
linenumber += 1
for t in tags: #necessary backup in case the regex fails to match
text.tag_remove(t, text.tag_ranges("sel")[0], text.tag_ranges("sel")[1])
def tag_new(tag):
if len(text.tag_ranges("sel")) != 0: #selection is not empty
#remove any newline characters from the selection
if '\n' in text.get(text.tag_ranges("sel")[0], text.tag_ranges("sel")[1]):
line_start = (str(text.tag_ranges("sel")[0]).split('.'))[1]
newline_index = text.get(text.tag_ranges("sel")[0], text.tag_ranges("sel")[1]).index('\n')
del_line = str(text.tag_ranges("sel")[0]).split('.')[0]
del_position = str(int(line_start) + int(newline_index))
text.delete(del_line + '.' + del_position)
#tag all occurences of selected string
key = text.get(text.tag_ranges("sel")[0], text.tag_ranges("sel")[1])
lines = text.get(1.0, 'end').split('\n')
linenumber = 1
for line in lines:
for m in re.finditer(re.escape(key), line, re.IGNORECASE):
for t in tags:
text.tag_add(tag, str(linenumber) + '.' + str(m.start()), str(linenumber) + '.' + str(m.end()))
linenumber += 1
def export_console():
#need better way to iterate through highlights and remove brackets
for t in tags:
indicators = []
print(t + ':')
myhighlights = text.tag_ranges(t)
mystart = 0
for h in myhighlights:
if mystart == 0:
mystart = h
else:
mystop = h
if t == 'md5': #make all hashes uppercase
if not text.get(mystart,mystop).upper() in indicators:
indicators.append(text.get(mystart,mystop).upper())
else:
if not text.get(mystart,mystop).replace('[.]','.').replace('[@]','@') in indicators:
indicators.append(text.get(mystart,mystop).replace('[.]','.').replace('[@]','@'))
mystart = 0
for i in indicators:
print(i)
print()
def export_csv():
filename = asksaveasfilename(title="Save As", filetypes=[("csv file",".csv"),("All files",".*")])
if filename != '':
output = 'IOC,Type\n'
#need better way to iterate through highlights and remove brackets
for t in tags:
indicators = []
myhighlights = text.tag_ranges(t)
mystart = 0
for h in myhighlights:
if mystart == 0:
mystart = h
else:
mystop = h
if t == 'md5': #make all hashes uppercase
if not text.get(mystart,mystop).upper() in indicators:
indicators.append(text.get(mystart,mystop).upper())
else:
if not text.get(mystart,mystop).replace('[.]','.').replace('[@]','@') in indicators:
indicators.append(text.get(mystart,mystop).replace('[.]','.').replace('[@]','@'))
mystart = 0
for i in indicators:
if i.find(',') == -1: #no commas, print normally
output += str(i) + ',' + t + '\n'
else: #internal comma, surround in double quotes
output += '"' + str(i) + '",' + t + '\n'
if len(filename) - filename.find('.csv') != 4:
filename += '.csv' #add .csv extension if missing
with open(filename, 'w') as f:
f.write(output)
def export_cybox():
filename = asksaveasfilename(title="Save As", filetypes=[("xml file",".xml"),("All files",".*")])
observables_doc = None
if filename:
observables = []
for t in tags:
indicators = []
myhighlights = text.tag_ranges(t)
mystart = 0
for h in myhighlights:
if mystart == 0:
mystart = h
else:
mystop = h
value = text.get(mystart,mystop).replace('[.]','.').replace('[@]','@')
if t == 'md5':
value = value.upper()
if value not in indicators:
observable = cybox_api.create_file_hash_observable('', value, 'MD5')
observables.append(observable)
indicators.append(value)
elif t == 'ipv4':
if not value in indicators:
observable = cybox_api.create_ipv4_observable(value)
observables.append(observable)
indicators.append(value)
elif t == 'domain':
if not value in indicators:
observable = cybox_api.create_domain_name_observable(value)
observables.append(observable)
indicators.append(value)
elif t == 'url':
if not value in indicators:
observable = cybox_api.create_url_observable(value)
observables.append(observable)
indicators.append(value)
elif t == 'email':
if not value in indicators:
observable = cybox_api.create_email_address_observable(value)
observables.append(observable)
indicators.append(value)
mystart = 0
# end if
# end for
# end for
if len(observables) > 0:
observables_doc = cybox_api.create_observables_document(observables)
if len(filename) - filename.find('.xml') != 4:
filename = "%s.xml" % filename #add .xml extension if missing
# end if
f = open(filename, "wb")
observables_doc.export(f, 0)
f.close()
# end if
def export_openioc():
'''
Export the tagged items in OpenIOC 1.1 format.
This prompts the user to determine which directory they want the IOC saved
out too.
Email tags default to 'Email/From' address, implying that the email address
found is the source address of an email. This may not be accurate in all
cases.
'''
def make_network_uri(uri, condition='contains', negate=False, preserve_case = False):
document = 'Network'
search = 'Network/URI'
content_type = 'string'
content = uri
IndicatorItem_node = ioc_api.make_IndicatorItem_node(condition, document, search, content_type, content, negate=negate, preserve_case=preserve_case, context_type = None)
return IndicatorItem_node
def make_email_from(from_address, condition='contains', negate=False, preserve_case = False):
document = 'Email'
search = 'Email/From'
content_type = 'string'
content = from_address
IndicatorItem_node = ioc_api.make_IndicatorItem_node(condition, document, search, content_type, content, negate=negate, preserve_case=preserve_case, context_type = None)
return IndicatorItem_node
output_directory = askdirectory(title = "Save IOC To")
if output_directory:
indicator_nodes = []
for tag in tags:
temp_indicators = []
myhighlights = text.tag_ranges(tag)
mystart = 0
for h in myhighlights:
if mystart == 0:
mystart = h
else:
mystop = h
# Deobfuscate ip addresses, domain names and email addresses
value = text.get(mystart,mystop).replace('[.]','.').replace('[@]','@')
if tag == 'md5':
value = value.upper()
if value not in temp_indicators:
indicator_node = ioc_common.make_fileitem_md5sum(value)
indicator_nodes.append(indicator_node)
temp_indicators.append(value)
elif tag == 'ipv4':
if value not in temp_indicators:
indicator_node = ioc_common.make_portitem_remoteip(value)
indicator_nodes.append(indicator_node)
temp_indicators.append(value)
elif tag == 'domain':
if value not in temp_indicators:
indicator_node = ioc_common.make_dnsentryitem_recordname(value)
indicator_nodes.append(indicator_node)
temp_indicators.append(value)
elif tag == 'url':
if value not in temp_indicators:
indicator_node = make_network_uri(value)
indicator_nodes.append(indicator_node)
temp_indicators.append(value)
elif tag == 'email':
if value not in temp_indicators:
indicator_node = make_email_from(value)
indicator_nodes.append(indicator_node)
temp_indicators.append(value)
else:
print 'Unknown tag encountered [%s]' % str(tag)
mystart = 0
if len(indicator_nodes) > 0:
ioc_obj = ioc_api.IOC(name = "IOC Extractor", description = "IOC generated with IOCExtractor")
for indicator in indicator_nodes:
ioc_obj.top_level_indicator.append(indicator)
ioc_obj.write_ioc_to_file(output_directory)
return True
root = Tk()
root.title('IOCextractor')
topframe = Frame(root)
topframe.pack()
bottomframe = Frame(root)
bottomframe.pack(side=BOTTOM)
openb = Button(topframe, text = "Open File", command = askopen)
openb.pack(side=LEFT)
clear = Button(topframe, text = "Clear", command = clear_tag)
clear.pack({"side": "left"})
md5 = Button(topframe, text = "MD5", command = lambda: tag_new('md5'), bg = "#FE6AA8")
md5.pack({"side": "left"})
ipv4 = Button(topframe, text = "IPV4", command = lambda: tag_new('ipv4'), bg = "#6CB23E")
ipv4.pack({"side": "left"})
url = Button(topframe, text = "URL", command = lambda: tag_new('url'), bg = "#378A20")
url.pack({"side": "left"})
domain = Button(topframe, text = "Domain", command = lambda: tag_new('domain'), bg = "#5DC5D1")
domain.pack({"side": "left"})
email = Button(topframe, text = "Email", command = lambda: tag_new('email'), bg = "#0224F2")
email.pack({"side": "left"})
export_console = Button(topframe, text = "Export Console", command = export_console)
export_console.pack({"side": "left"})
export_csv = Button(topframe, text = "Export CSV", command = export_csv)
export_csv.pack({"side": "left"})
export_cybox = Button(topframe, text = "Export CybOX", command = export_cybox)
export_cybox.pack({"side": "left"})
if ioc_writer_available:
export_openioc = Button(topframe, text = "Export OpenIOC 1.1", command = export_openioc)
export_openioc.pack({"side" : "left"})
#build main text area
text = Text(bottomframe, width=120, height=50)
text.pack({"side": "left"})
scrollbar = Scrollbar(bottomframe)
scrollbar.pack({"side": "left", "fill" : "y"})
scrollbar.config(command = text.yview)
text.config(yscrollcommand = scrollbar.set)
text.bind('<Button-3>', clear_tag) #right-click selection to untag (Windows, Linux)
text.bind('<Command-Button-1>', clear_tag) #command-click selection to untag (Mac)
#insert doc if received as commandline argument
if len(sys.argv) == 2:
askopen(sys.argv[1])
root.mainloop()