2017-11-15 09:39:59 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-10-20 09:55:46 +02:00
|
|
|
import json
|
|
|
|
from pymisp import PyMISP
|
2017-11-15 17:37:17 +01:00
|
|
|
from pymisp.tools import GenericObjectGenerator
|
2017-10-20 09:55:46 +02:00
|
|
|
from keys import misp_url, misp_key, misp_verifycert
|
|
|
|
import argparse
|
|
|
|
|
2017-11-15 09:39:59 +01:00
|
|
|
"""
|
|
|
|
Sample usage:
|
|
|
|
./add_generic_object.py -e 5065 -t email -l '[{"to": "undisclosed@ppp.com"}, {"to": "second.to@mail.com"}]'
|
|
|
|
"""
|
|
|
|
|
2017-10-20 09:55:46 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description='Create a MISP Object selectable by type starting from a dictionary')
|
|
|
|
parser.add_argument("-e", "--event", required=True, help="Event ID to update")
|
|
|
|
parser.add_argument("-t", "--type", required=True, help="Type of the generic object")
|
2017-11-15 09:39:59 +01:00
|
|
|
parser.add_argument("-l", "--attr_list", required=True, help="List of attributes")
|
2017-10-20 09:55:46 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
|
2018-12-04 17:08:00 +01:00
|
|
|
template = pymisp.get_object_templates_list()
|
|
|
|
if 'response' in template.keys():
|
|
|
|
template = template['response']
|
2017-10-20 09:55:46 +02:00
|
|
|
try:
|
2018-12-04 17:08:00 +01:00
|
|
|
template_ids = [x['ObjectTemplate']['id'] for x in template if x['ObjectTemplate']['name'] == args.type]
|
|
|
|
if len(template_ids) > 0:
|
|
|
|
template_id = template_ids[0]
|
|
|
|
else:
|
|
|
|
raise IndexError
|
2017-10-20 09:55:46 +02:00
|
|
|
except IndexError:
|
2018-12-04 17:08:00 +01:00
|
|
|
valid_types = ", ".join([x['ObjectTemplate']['name'] for x in template])
|
2017-10-20 09:55:46 +02:00
|
|
|
print ("Template for type %s not found! Valid types are: %s" % (args.type, valid_types))
|
|
|
|
exit()
|
|
|
|
|
2017-11-15 17:37:17 +01:00
|
|
|
misp_object = GenericObjectGenerator(args.type.replace("|", "-"))
|
|
|
|
misp_object.generate_attributes(json.loads(args.attr_list))
|
2017-10-20 09:55:46 +02:00
|
|
|
r = pymisp.add_object(args.event, template_id, misp_object)
|