-
Notifications
You must be signed in to change notification settings - Fork 1
/
eiq_to_ids.py
executable file
·757 lines (736 loc) · 35.5 KB
/
eiq_to_ids.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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
#!/usr/bin/env python3
# (c) 2018 Arnim Eijkhoudt <arnime _squigglything_ kpn-cert.nl>
# and Sebastiaan Groot <sebastiaang _monkeytail_ kpn-cert.nl> (for his
# EIQ lib)
# This software is GPLv3 licensed, except where otherwise indicated
import sys
import os
import re
import optparse
import urllib3
import time
import smtplib
import string
import eiqcalls
import pprint
import unicodedata
import pickle
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formatdate, make_msgid
from config import settings
sidfind = re.compile(r'sid:\d+; ?')
gidfind = re.compile(r'gid:\d+; ')
revfind = re.compile(r' rev:\d+')
httpfind = re.compile(r'metadata:service http; ')
stripnl = re.compile(r's/\r\n/ /g')
msgfind = re.compile(r'msg:[:]?\ ?\"[^\"]+\";?; ')
priofind = re.compile(r'priority:\d+; ')
classfind = re.compile(r'classtype:[^\"]+;')
spacefix = re.compile(r' \)')
semicolonfix = re.compile(r's/;;/;/g')
doublespacefix = re.compile(r's/ / /g')
def transform(feedJSON, feedID, options):
'''
Take the EIQ JSON objects, extract all observables into lists,
and transform those into the selected ruletypes.
'''
if options.verbose:
print("U) Converting EIQ JSON objects into a rules group ...")
entities = []
for entity in feedJSON:
if 'extracts' in entity:
if 'description' in entity['data']:
description = entity['data']['description']
else:
description = ''
if 'meta' in entity:
meta = entity['meta']
tlp = 'AMBER'
if 'tlp_color' in meta:
tlp = meta['tlp_color']
if 'title' in meta:
title = meta['title']
if entity['extracts']:
entry = {title: {
'actor-id': [],
'description': [description],
'domain': [],
'email': [],
'email-subject': [],
'file': [],
'ipv4': [],
'ipv6': [],
'hash-md5': [],
'hash-sha1': [],
'hash-sha256': [],
'hash-sha512': [],
'snort': [],
'tlp': [tlp],
'uri': [],
'yara': []
}}
for extract in entity['extracts']:
if 'kind' and 'value' in extract:
kind, value = extract['kind'], extract['value']
if kind == 'actor-id':
entry[title][kind].append(value)
if 'instance_meta' in extract:
instance_meta = extract['instance_meta']
if 'link_types' in instance_meta:
link_types = instance_meta['link_types']
if 'test-mechanism' in link_types:
classification = ''
if 'meta' in extract:
meta = extract['meta']
if 'classification' in meta:
classification = meta[
'classification']
if classification == 'bad' or \
kind == 'snort' or \
kind == 'yara':
if kind in entry[title]:
entry[title][kind].append(value)
entities.append(entry)
return entities
def cleanup(text=None):
if text:
text = text.replace('text: ', ' | ')
text = re.sub(r'<[^>]*?>', '', text)
return text
def rulegen(entities, options):
ruleset = []
if options.type == 's':
if options.verbose:
print("U) Building Snort/SourceFire rules ...")
if not options.rev:
rev = time.strftime('%Y%m%d00')
else:
rev = int(options.rev)
sid = int(options.sid)
gid = int(options.gid)
priority = int(options.priority)
for entity in entities:
for title in entity:
actor = entity[title]['actor-id']
if not actor:
actor = ['unknown']
actor = actor[0]
tlp = entity[title]['tlp']
description = cleanup(title)
Event = "Not in MISP"
EventRE = re.search('Event [0-9]+', description)
if EventRE:
Event = "MISP: " + EventRE.group(0)
else:
Event += ": " + description
message = "TLP:" + ''.join(tlp) + \
" | Actor: " + ''.join(actor) + \
" | " + ''.join(Event)
message = message.replace('"', '')
message = unicodedata.normalize('NFKD', message)
message = ''.join(filter(lambda x: x in string.printable,
message))
for kind in entity[title]:
for value in entity[title][kind]:
if kind == 'ipv4' or kind == 'ipv6':
msg = kind.upper() + " detected: " + value
msg += " | " + message
msg += " | rev:" + str(rev)
ruleset.append('alert ip ' + options.network +
' any <> ' +
value + ' any ' +
'(msg:"' + msg + '"; ' +
'priority:' + str(priority) + '; ' +
'sid:' + str(sid) + '; ' +
'gid:' + str(gid) + '; ' +
'classtype:' + options.classtype +
'; ' + 'rev:' + str(rev) +
')')
sid += 1
# if kind == 'file':
# msg = kind.upper() + " detected | " + message
# msg += " | rev:" + str(rev)
# value = ' '.join("{:02x}".format(ord(c))
# for c in value)
# ruleset.append('alert tcp ' + options.network +
# ' any -> ' +
# options.dest + ' any ' +
# '(msg:"' + msg + '"; ' +
# 'content:"|' + value + '|"; ' +
# 'priority:' + str(priority) + '; ' +
# 'sid:' + str(sid) + '; ' +
# 'gid:' + str(gid) + '; ' +
# 'classtype:' + options.classtype +
# '; ' + 'rev:' + str(rev) +
# ')')
# sid += 1
if kind == 'uri':
msg = kind.upper() + " detected: " + value
msg += " | " + message
msg += " | rev:" + str(rev)
uri = urllib3.util.parse_url(value)
dest = options.dest
host = uri.host
port = uri.port
# Check if we need to write SourceFire/Snort rules
# that need to compensate for proxy traffic
if settings.HTTP_PROXYSERVER:
dest = settings.HTTP_PROXYSERVER
if 'https://' in value:
if uri.port:
value = host + ':' + str(port)
else:
port = 443
value = host + ':443'
http_ports = str(settings.HTTP_PROXYSERVERPORT)
else:
dest = options.dest
if uri.port:
if not settings.HTTP_PROXYSERVER and\
settings.HTTP_PROXYBYPASS:
if str(settings.HTTP_PROXYSERVERPORT) !=\
str(uri.port):
http_ports = '['
http_ports += str(settings.
HTTP_PROXYSERVERPORT)
http_ports += ','
http_ports += str(uri.port)
http_ports += ']'
else:
http_ports =\
str(settings.HTTP_PROXYSERVERPORT)
else:
http_ports = str(port)
else:
http_ports = str(settings.HTTP_PORTS)
# Remove variables in GET request to prevent
# overly long content checks, and strip out the
# http[s] part
# value = re.sub(r'https?:\/\/', '', value)
# if '?' in value:
# value = value.split('?')[0]
# Check if the URI contains UTF/high-ASCII stuff
# that might break SourceFire/Snort parsing
newvalue = unicodedata.normalize('NFKD', value)
newvalue = ''.join(filter(lambda x: x in
string.printable, newvalue))
content = ''
if newvalue != value:
content += 'content:"|'
value = ' '.join("{:02x}".format(ord(c))
for c in value)
content += value + '|"; '
else:
if uri.host and 'https://' not in msg\
and not settings.HTTP_PROXYSERVER:
content += 'content:"'
content += uri.host + '"; '
content += 'http_header; '
content += 'nocase; '
if uri.request_uri and uri.request_uri != '/':
content += 'content:"' + uri.request_uri
content += '"; '
if 'https://' in msg:
content += 'http_header; '
else:
content += 'http_uri; '
content += 'fast_pattern:only; '
content += 'nocase; '
else:
if 'https://' in msg and\
settings.HTTP_PROXYSERVER:
if uri.host:
content += 'content:"CONNECT"; '
content += 'http_method; nocase; '
content += 'content:"' + uri.host
content += '"; '
content += 'http_header; nocase; '
if 'https://' in msg and\
settings.HTTP_PROXYBYPASS:
if uri.host:
content += 'content:"CONNECT"; '
content += 'http_method; nocase; '
content += 'content:"' + uri.host
content += '"; '
content += 'http_header; nocase; '
if 'https://' not in msg:
if uri.host:
content += 'content:"'
content += uri.host + '"; '
content += 'http_header; nocase; '
if uri.request_uri and\
uri.request_uri != '/':
content += 'content:"'
content += uri.request_uri + '"; '
if 'https://' in msg:
content += 'http_header; '
else:
content += 'http_uri; '
content += 'fast_pattern:only; '
content += 'nocase; '
ruleset.append('alert tcp ' + options.network +
' any -> ' +
dest + ' ' +
http_ports + ' ' +
'(msg:"' + msg + '"; ' +
# 'flow:to_server,established; ' +
content +
'priority:' + str(priority) + '; ' +
'sid:' + str(sid) + '; ' +
'gid:' + str(gid) + '; ' +
'metadata:service http; ' +
'classtype:' + options.classtype +
'; rev:' + str(rev) +
')')
sid += 1
if kind == 'domain':
msg = kind.upper() + " detected: " + value
msg += " | " + message
msg += " | rev:" + str(rev)
domainparts = value.split('.')
content = ''
for part in domainparts:
content += '|' + hex(len(part))[2:].zfill(2) + \
'|' + part
content += '|00|'
ruleset.append('alert udp ' + options.network +
' any -> ' +
options.dest + ' 53 ' +
'(msg:"' + msg + '"; ' +
'byte_test:1,!&,0xF8,2; ' +
'content:"' + content + '"; ' +
'fast_pattern:only; ' +
'priority:' + str(priority) + '; ' +
'sid:' + str(sid) + '; ' +
'gid:' + str(gid) + '; ' +
'classtype:' + options.classtype +
'; ' + 'rev:' + str(rev) +
')')
sid += 1
ruleset.append('alert tcp ' + options.network +
' any -> ' +
options.dest + ' 53 ' +
'(msg:"' + msg + '"; ' +
'byte_test:1,!&,0xF8,2; ' +
'content:"' + content + '"; ' +
'fast_pattern:only; ' +
'priority:' + str(priority) + '; ' +
'sid:' + str(sid) + '; ' +
'gid:' + str(gid) + '; ' +
'classtype:' + options.classtype +
'; ' + 'rev:' + str(rev) +
')')
sid += 1
if kind == 'email' or kind == 'email-subject':
msg = kind.upper() + " detected: " + value
msg += " | " + message
msg += " | rev:" + str(rev)
value = ' '.join("{:02x}".format(ord(c))
for c in value)
ruleset.append('alert tcp ' + options.network +
' any <> ' +
options.dest + ' ' +
settings.SMTP_PORTS +
' (msg:"' + msg + '"; ' +
'content:"|' + value + '|"; ' +
'priority:' + str(priority) + '; ' +
'sid:' + str(sid) + '; ' +
'gid:' + str(gid) + '; ' +
'classtype:' + options.classtype +
'; ' + 'rev:' + str(rev) +
')')
sid += 1
ruleset.append('alert tcp ' + options.network +
' any <> ' +
options.dest + ' ' +
settings.POP3_PORTS +
' (msg:"' + msg + '"; ' +
'content:"|' + value + '|"; ' +
'priority:' + str(priority) + '; ' +
'sid:' + str(sid) + '; ' +
'gid:' + str(gid) + '; ' +
'classtype:' + options.classtype +
'; ' + 'rev:' + str(rev) +
')')
sid += 1
ruleset.append('alert tcp ' + options.network +
' any <> ' +
options.dest + ' ' +
settings.IMAP_PORTS + ' ' +
'(msg:"' + msg + '"; ' +
'content:"|' + value + '|"; ' +
'priority:' + str(priority) + '; ' +
'sid:' + str(sid) + '; ' +
'gid:' + str(gid) + '; ' +
'classtype:' + options.classtype +
'; ' + 'rev:' + str(rev) +
')')
sid += 1
if kind == 'snort':
value = re.sub(r'\r\n', ' ', value)
value = re.sub(r';', '; ', value)
value = re.sub(r'; ', '; ', value)
value = re.sub(r'; \)', ';)', value)
value = sidfind.sub('', value)
value = gidfind.sub('', value)
value = revfind.sub('', value)
value = httpfind.sub('', value)
value = priofind.sub('', value)
value = classfind.sub('', value)
value = spacefix.sub(')', value)
value = re.sub(r';;', ';', value)
value = re.sub(r' ', ' ', value)
msg = msgfind.findall(value)[0]
sublist = ['\"', ';', '\'', '(', ')']
for char in sublist:
msg = msg.replace(char, "")
msg += '| rev:' + str(rev)
value = re.sub(r'msg:[:]?\ ?\"[^\"]+\";?; ',
msg + '\"; ', value)
value = value.replace('msg:',
'msg:"3rd-party intel: ', 1)
revstring = ' priority:' + str(priority) + '; '
revstring += 'sid:' + str(sid) + '; '
revstring += 'gid:' + str(gid) + '; '
revstring += 'classtype:'
revstring += options.classtype
revstring += '; ' + 'rev:' + str(rev) + ')'
revstring = revstring[::-1]
value = value[::-1].replace(')',
revstring, 1)[::-1]
sid += 1
ruleset.append(value)
if options.verbose:
print("U) Ruleset is: ")
print(("\n".join(ruleset)))
return ruleset
def striprule(rule):
strippedrule = sidfind.sub('', rule)
strippedrule = gidfind.sub('', strippedrule)
strippedrule = revfind.sub('', strippedrule)
strippedrule = httpfind.sub('', strippedrule)
strippedrule = msgfind.sub('', strippedrule)
strippedrule = priofind.sub('', strippedrule)
strippedrule = classfind.sub('', strippedrule)
strippedrule = spacefix.sub(')', strippedrule)
return strippedrule
def reusesid(ruleset, options):
if ruleset:
newrulemap = {}
oldrulemap = {}
newruleset = []
usedsids = set()
'''
First, create a deduplicated dictionary of the new rules in the format:
strippedrule:(completerule, sid)
'''
for rule in ruleset:
sid = sidfind.findall(rule)
if sid:
newrulemap[striprule(rule)] = (rule, sid[0])
'''
Then, load the old sid map from disk (same format), if it exists...
'''
if os.path.isfile(settings.SIDFILE):
try:
with open(settings.SIDFILE, 'rb') as sidfile:
oldrulemap = pickle.load(sidfile)
if options.verbose:
print("---")
print("Old ruleset and existing sids:")
print("---")
for rule in oldrulemap:
oldrule = oldrulemap[rule][0]
oldsid = oldrulemap[rule][1]
if options.verbose:
print('Key: {} *** Value: {}'.format(rule,
oldrule))
usedsids.add(oldsid)
except (IOError, EOFError):
if options.verbose:
print("An error occurred loading the sidmap from disk!")
raise
'''
For every new rule, check if it already existed in the old set. If so,
reuse the old sid. Then, push the new rule into the final ruleset, the
new sid map, reserve the sid and then delete the rule from the new rule
map.
'''
if options.verbose:
print("---")
print("List of", len(usedsids), "historical sids:",
sorted(usedsids))
print("---")
for rule in list(newrulemap.keys()):
newrule = newrulemap[rule][0]
newsid = newrulemap[rule][1]
if rule in oldrulemap:
oldrule = oldrulemap[rule][0]
oldsid = oldrulemap[rule][1]
newrev = revfind.findall(newrule)[0]
oldrule = revfind.sub(newrev, oldrule)
newruleset.append(oldrule)
del newrulemap[rule]
'''
Check if the remaining rules do not use existing sids and replace them
with a new 'free' sid if so.
'''
for rule in newrulemap:
newrule = newrulemap[rule][0]
newsid = newrulemap[rule][1]
if newsid in usedsids:
counter = options.sid
replacementsid = "sid:" + str(counter) + "; "
'''
Find a new free sid for replacing the old one
'''
while replacementsid in usedsids:
counter += 1
replacementsid = "sid:" + str(counter) + "; "
newrule = sidfind.sub(replacementsid, newrule)
usedsids.add(replacementsid)
newruleset.append(newrule)
oldrulemap[rule] = (newrule, replacementsid)
else:
usedsids.add(newsid)
newruleset.append(newrule)
oldrulemap[rule] = (newrule, newsid)
'''
Finally, build the new sid map by combining the old and the new map,
and store it on disk.
'''
newrulemap.update(oldrulemap)
if options.verbose:
print("---")
print("New map of rules and sids for writing to disk:")
print("---")
for key, value in list(newrulemap.items()):
print('Key: {} *** Value: {}'.format(key, value))
if not options.simulate:
try:
with open(settings.SIDFILE, 'wb') as sidfile:
pickle.dump(newrulemap, sidfile, pickle.HIGHEST_PROTOCOL)
except IOError:
if options.verbose:
print("An error occurred writing the sidmap to disk!")
raise
else:
if options.verbose:
"Not writing sidmap to disk because of the simulate option!"
if options.verbose:
print("---")
print("New ruleset:")
print("---")
for rule in newruleset:
print(rule)
return newruleset
def download(feedID, options):
'''
Download the given feed number from the EclecticIQ JSON instance
'''
if not settings.EIQSSLVERIFY:
if options.verbose:
print("W) You have disabled SSL verification for EIQ, " +
"this is not recommended.")
eiqAPI = eiqcalls.EIQApi(insecure=not(settings.EIQSSLVERIFY))
eiqHost = settings.EIQHOST + settings.EIQVERSION
eiqFeed = settings.EIQFEEDS + '/' + str(feedID) + '/runs/latest'
eiqAPI.set_host(eiqHost)
eiqAPI.set_credentials(settings.EIQUSER, settings.EIQPASS)
eiqToken = eiqAPI.do_auth()
eiqHeaders = {}
eiqHeaders['Authorization'] = 'Bearer %s' % (eiqToken['token'],)
try:
if options.verbose:
print("U) Contacting " + eiqHost + eiqFeed + ' ...')
response = eiqAPI.do_call(endpt=eiqFeed,
headers=eiqHeaders,
method='GET')
except IOError:
print("E) An error occurred contacting the EIQ URL at " +
eiqFeed)
raise
if not response or ('errors' in response):
if response:
for err in response['errors']:
print('[error %d] %s' % (err['status'], err['title']))
print('\t%s' % (err['detail'], ))
else:
print('unable to get a response from host')
sys.exit(1)
if 'content_blocks' not in response['data']:
if options.verbose:
print("E) No content blocks in feed ID!")
else:
if options.verbose:
print("U) Attempting to download latest feed content ...")
content_block = response['data']['content_blocks'][0]
content_block = content_block.replace(settings.EIQVERSION, "")
response = eiqAPI.do_call(endpt=content_block,
headers=eiqHeaders,
method='GET')
if options.verbose:
pprint.pprint(response)
if 'entities' not in response:
print("E) No entities in response!")
else:
return response['entities']
def process(ruleset, options):
ruleset = ('\n'.join(ruleset))+'\n'
if options.action == 'mail' or options.action == 'm':
timestamp = time.strftime('%Y-%m-%d, %H:%M:%S')
filename = time.strftime('%Y%m%d-%H%M%S-') + settings.OUTPUTFILE
if options.verbose:
print("U) Sending ruleset to e-mail ... ")
print("U) From: " + settings.EMAILFROM)
print("U) To: " + settings.EMAILTO)
print("U) Subject: " + settings.EMAILSUBJECT)
if not options.simulate:
msg = MIMEMultipart()
msg['Subject'] = settings.EMAILSUBJECT + " for " + timestamp
msg['From'] = settings.EMAILFROM
msg['To'] = options.email
msg['Date'] = formatdate()
msg['Message-Id'] = make_msgid()
content = "This email contains the output of the eiq_to_ids.py "
content += "run for " + timestamp + ". The generated ruleset "
content += "has been included as a text file attachment.\n"
content += "\n"
content += "Kind regards,\n"
content += "\n"
content += settings.EMAILFROM
content += " - (this was an automatically generated message)"
msg.attach(MIMEText(content))
part = MIMEApplication(ruleset, Name=filename)
content_disposition = 'attachment; filename="%s"' % filename
part['Content-Disposition'] = content_disposition
msg.attach(part)
smtp = smtplib.SMTP(settings.EMAILSERVER)
try:
smtp.send_message(msg)
except IOError:
print("E) An error occurred sending e-mail!")
raise
else:
print("U) Not sending e-mail as simulate option is set!")
if options.action == 'file' or options.action == 'f':
timestamp = time.strftime('%Y%m%d-%H%M%S-')
try:
if not options.simulate:
if options.verbose:
print("U) Writing ruleset to file: " +
timestamp + settings.OUTPUTFILE)
with open(timestamp + settings.OUTPUTFILE, 'w') as file:
file.writelines(ruleset)
else:
print("U) Not writing anything to disk, as " +
"simulation option was set!")
except IOError:
print("E) An error occurred writing to disk!")
raise
if __name__ == "__main__":
cli = optparse.OptionParser(usage="usage: %prog [-v | -t | -s " +
"| -n | -d | -a] <EIQ feed ID>")
cli.add_option('-v', '--verbose',
dest='verbose',
action='store_true',
default=False,
help='[optional] Enable progress/error info (default: ' +
'disabled)')
cli.add_option('-t', '--type',
dest='type',
default='s',
help='[optional] Set the type of IDS / SIEM rule you ' +
'wish to create: [s]ourcefire/Snort (default). ')
cli.add_option('-a', '--action',
dest='action',
default=settings.ACTION,
help='Specify the action to take with the generated ' +
'ruleset: [f]ile, [m]ail (default: write to ' +
'the [f]ilename specified in settings.py)')
cli.add_option('-e', '--email',
dest='email',
default=settings.EMAILTO,
help='Override the default e-mail address from the ' +
'settings.py configuration file (currently set ' +
'to: ' + settings.EMAILTO + ')')
cli.add_option('-d', '--dest',
dest='dest',
default='any',
help='[optional] Set the destination network you ' +
'want to create the ruleset for (default: \'any\')')
cli.add_option('-s', '--simulate',
dest='simulate',
action='store_true',
default=False,
help='[optional] Do not actually generate anything, ' +
'just simulate everything. Mostly useful with ' +
'the -v/--verbose flag for debugging purposes.')
cli.add_option('-i', '--sid',
dest='sid',
default=settings.SID,
help='[optional] Override the sid to start counting ' +
'from (default: ' + str(settings.SID) + ')')
cli.add_option('-g', '--gid',
dest='gid',
default=settings.GID,
help='[optional] Override the gid from the configuration ' +
'file (default: ' + str(settings.GID) + ')')
cli.add_option('-p', '--priority',
dest='priority',
default=settings.PRIORITY,
help='[optional] Override the default priority from the ' +
'configuration file (default: ' +
str(settings.PRIORITY) + ')')
cli.add_option('-c', '--classtype',
dest='classtype',
default=settings.CLASSTYPE,
help='[optional] Override the classtype setting from ' +
'the configuration file (default: ' +
settings.CLASSTYPE + ')')
cli.add_option('-r', '--rev',
dest='rev',
default=None,
help='[optional] Specify the rev id to start counting ' +
'from. Particularly important when creating Snort ' +
'SourceFire rulesets, as not all instances support ' +
'easy deletion/disabling. Using the rev counter ' +
'ensures that the rules can be loaded correctly ' +
'(default: use date/time: YYYYMMDD00)')
cli.add_option('--comment',
dest='name',
default=settings.COMMENT,
help='[optional] Override the default comment from the ' +
'configuration file (default: ' + settings.COMMENT +
'from the settings.py file)')
cli.add_option('-n', '--network',
dest='network',
default=settings.NETVAR,
help='[optional] Override the default source network from '
'the configuration file (default: ' + settings.NETVAR +
'from the settings.py file)')
cli.add_option('-m', '--maliciousness',
dest='maliciousness',
default=1,
help='[optional] Set minimum maliciousness')
(options, args) = cli.parse_args()
if len(args) < 1:
cli.print_help()
sys.exit(1)
if len(args) > 1:
print("E) Please specify exactly one feedID from EclecticIQ.")
sys.exit(1)
else:
try:
feedID = int(args[0])
except ValueError:
print("E) Please specify a numeric feedID only.")
raise
feedDict = download(feedID, options)
entities = transform(feedDict, feedID, options)
ruleset = rulegen(entities, options)
filteredruleset = reusesid(ruleset, options)
if filteredruleset:
process(filteredruleset, options)