mirror of https://github.com/MISP/PyMISP
Merge branch 'master' of github.com:MISP/PyMISP
commit
fc80e711a9
|
@ -0,0 +1,52 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
result = m.get_event(event)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='Tag something.')
|
||||||
|
parser.add_argument("-u", "--uuid", help="UUID to tag.")
|
||||||
|
parser.add_argument("-e", "--event", help="Event ID to tag.")
|
||||||
|
parser.add_argument("-a", "--attribute", help="Attribute ID to tag")
|
||||||
|
parser.add_argument("-t", "--tag", required=True, help="Attribute ID to modify.")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if not args.event and not args.uuid and not args.attribute:
|
||||||
|
print("Please provide at least one of the following : uuid, eventID or attribute ID, see --help")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
misp = init(misp_url, misp_key)
|
||||||
|
|
||||||
|
event = misp.get_event(args.event)
|
||||||
|
|
||||||
|
if args.event and not args.attribute:
|
||||||
|
result = misp.search(eventid=args.event)
|
||||||
|
data = result['response']
|
||||||
|
for event in data:
|
||||||
|
uuid = event['Event']['uuid']
|
||||||
|
|
||||||
|
if args.attribute:
|
||||||
|
if not args.event:
|
||||||
|
print("Please provide event ID also")
|
||||||
|
exit()
|
||||||
|
result = misp.search(eventid=args.event)
|
||||||
|
data = result['response']
|
||||||
|
for event in data:
|
||||||
|
for attribute in event['Event']['Attribute']:
|
||||||
|
if attribute["id"] == args.attribute:
|
||||||
|
uuid = attribute["uuid"]
|
||||||
|
|
||||||
|
if args.uuid:
|
||||||
|
uuid = args.uuid
|
||||||
|
|
||||||
|
print("UUID tagged: %s"%uuid)
|
||||||
|
misp.tag(uuid, args.tag)
|
|
@ -362,15 +362,21 @@ class PyMISP(object):
|
||||||
return self.add_event(json.dumps(misp_event, cls=EncodeUpdate))
|
return self.add_event(json.dumps(misp_event, cls=EncodeUpdate))
|
||||||
|
|
||||||
def tag(self, uuid, tag):
|
def tag(self, uuid, tag):
|
||||||
|
if not self._valid_uuid(uuid):
|
||||||
|
raise PyMISPError('Invalid UUID')
|
||||||
session = self.__prepare_session()
|
session = self.__prepare_session()
|
||||||
path = '/tags/attachTagToObject/{}/{}/'.format(uuid, tag)
|
to_post = {'uuid':uuid, 'tag':tag}
|
||||||
response = session.post(urljoin(self.root_url, path))
|
path = 'tags/attachTagToObject'
|
||||||
|
response = session.post(urljoin(self.root_url, path), data=json.dumps(to_post))
|
||||||
return self._check_response(response)
|
return self._check_response(response)
|
||||||
|
|
||||||
def untag(self, uuid, tag):
|
def untag(self, uuid, tag):
|
||||||
|
if not self._valid_uuid(uuid):
|
||||||
|
raise PyMISPError('Invalid UUID')
|
||||||
session = self.__prepare_session()
|
session = self.__prepare_session()
|
||||||
path = '/tags/removeTagFromObject/{}/{}/'.format(uuid, tag)
|
to_post = {'uuid':uuid, 'tag':tag}
|
||||||
response = session.post(urljoin(self.root_url, path))
|
path = 'tags/removeTagFromObject'
|
||||||
|
response = session.post(urljoin(self.root_url, path), data=json.dumps(to_post))
|
||||||
return self._check_response(response)
|
return self._check_response(response)
|
||||||
|
|
||||||
# ##### File attributes #####
|
# ##### File attributes #####
|
||||||
|
|
Loading…
Reference in New Issue