mirror of https://github.com/MISP/PyMISP
chg: Allow to add multiple attribute of the same type
parent
b1262a0c96
commit
0f21a561b0
|
@ -1,24 +1,35 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from pymisp import PyMISP
|
from pymisp import PyMISP
|
||||||
from pymisp.tools.abstractgenerator import AbstractMISPObjectGenerator
|
from pymisp.tools.abstractgenerator import AbstractMISPObjectGenerator
|
||||||
from keys import misp_url, misp_key, misp_verifycert
|
from keys import misp_url, misp_key, misp_verifycert
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
"""
|
||||||
|
Sample usage:
|
||||||
|
./add_generic_object.py -e 5065 -t email -l '[{"to": "undisclosed@ppp.com"}, {"to": "second.to@mail.com"}]'
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class GenericObject(AbstractMISPObjectGenerator):
|
class GenericObject(AbstractMISPObjectGenerator):
|
||||||
def __init__(self, type, data_dict):
|
def __init__(self, type, attr_list):
|
||||||
super(GenericObject, self).__init__(type)
|
super(GenericObject, self).__init__(type)
|
||||||
self.__data = data_dict
|
self.__data = attr_list
|
||||||
self.generate_attributes()
|
self.generate_attributes()
|
||||||
|
|
||||||
def generate_attributes(self):
|
def generate_attributes(self):
|
||||||
for key, value in self.__data.items():
|
for attribute in self.__data:
|
||||||
|
for key, value in attribute.items():
|
||||||
self.add_attribute(key, value=value)
|
self.add_attribute(key, value=value)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='Create a MISP Object selectable by type starting from a dictionary')
|
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("-e", "--event", required=True, help="Event ID to update")
|
||||||
parser.add_argument("-t", "--type", required=True, help="Type of the generic object")
|
parser.add_argument("-t", "--type", required=True, help="Type of the generic object")
|
||||||
parser.add_argument("-d", "--dict", required=True, help="Dict ")
|
parser.add_argument("-l", "--attr_list", required=True, help="List of attributes")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
|
pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
|
||||||
|
@ -29,5 +40,5 @@ if __name__ == '__main__':
|
||||||
print ("Template for type %s not found! Valid types are: %s" % (args.type, valid_types))
|
print ("Template for type %s not found! Valid types are: %s" % (args.type, valid_types))
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
misp_object = GenericObject(args.type.replace("|", "-"), json.loads(args.dict))
|
misp_object = GenericObject(args.type.replace("|", "-"), json.loads(args.attr_list))
|
||||||
r = pymisp.add_object(args.event, template_id, misp_object)
|
r = pymisp.add_object(args.event, template_id, misp_object)
|
||||||
|
|
Loading…
Reference in New Issue