chg: Use MISPObject instead of GenericObjectGenerator

pull/633/head
Raphaël Vinot 2020-09-16 20:58:57 +02:00
parent b9ee5c69bb
commit 808e8132f2
1 changed files with 14 additions and 18 deletions

View File

@ -1,9 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json from pymisp import PyMISP
from pymisp import ExpandedPyMISP from pymisp import MISPObject
from pymisp.tools import GenericObjectGenerator
from pymisp.tools import update_objects from pymisp.tools import update_objects
from keys import misp_url, misp_key, misp_verifycert from keys import misp_url, misp_key, misp_verifycert
import argparse import argparse
@ -35,24 +34,21 @@ if __name__ == '__main__':
r = requests.get("https://api.github.com/users/{}".format(args.username)) r = requests.get("https://api.github.com/users/{}".format(args.username))
if r.status_code != 200: if r.status_code != 200:
sys.exit("HTTP return is {} and not 200 as expected".format(r.status_code)) sys.exit("HTTP return is {} and not 200 as expected".format(r.status_code))
if args.force_template_update: if args.force_template_update:
print("Updating MISP Object templates...") print("Updating MISP Object templates...")
update_objects() update_objects()
pymisp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert) pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
misp_object = GenericObjectGenerator("github-user") misp_object = MISPObject(name="github-user")
github_user = json.loads(r.text) github_user = r.json()
rfollowers = requests.get(github_user['followers_url']) rfollowers = requests.get(github_user['followers_url'])
followers = json.loads(rfollowers.text) followers = rfollowers.json()
user_followers = [] user_followers = []
for follower in followers: for follower in followers:
user_followers.append({"follower": follower['login']}) misp_object.add_attribute("follower", follower['login'])
print(user_followers) misp_object.add_attribute('bio', github_user['bio'])
github_username = [{"bio": github_user['bio'], misp_object.add_attribute('link', github_user['html_url'])
"link": github_user['html_url'], misp_object.add_attribute('user-fullname', github_user['name'])
"user-fullname": github_user['name'], misp_object.add_attribute('username', github_user['login'])
"username": github_user['login']
}]
misp_object.generate_attributes(github_username)
retcode = pymisp.add_object(args.event, misp_object) retcode = pymisp.add_object(args.event, misp_object)