-
Notifications
You must be signed in to change notification settings - Fork 279
/
search_sighting.py
42 lines (30 loc) · 1.24 KB
/
search_sighting.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pymisp import PyMISP
from keys import misp_url, misp_key, misp_verifycert
import argparse
import os
import json
def init(url, key):
return PyMISP(url, key, misp_verifycert, 'json')
def search_sighting(m, context, out=None, **kwargs):
result = m.search_sightings(context, **kwargs)
if out is None:
print(json.dumps(result['response']))
else:
with open(out, 'w') as f:
f.write(json.dumps(result['response']))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get all the events matching a value.')
parser.add_argument("-c", "--context", default="", help="Context in which to search. Could be empty, attribute or event")
parser.add_argument("-i", "--id", type=int, help="If context is set, the ID in which the search should be done")
parser.add_argument("-o", "--output", help="Output file")
args = parser.parse_args()
if args.output is not None and os.path.exists(args.output):
print('Output file already exists, abord.')
exit(0)
misp = init(misp_url, misp_key)
kwargs = {}
if len(args.context) > 0:
kwargs['id'] = args.id
search_sighting(misp, args.context, args.output, **kwargs)