Skip to content

Commit

Permalink
new: Add bindings to PyMISPWarninglists
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Jan 25, 2018
1 parent 837372c commit 250190e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/warninglists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pymisp import PyMISP
from pymisp.tools import load_warninglists
import argparse
from keys import misp_url, misp_key


if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Load the warninglists.')
parser.add_argument("-p", "--package", action='store_true', help="from the PyMISPWarninglists package.")
parser.add_argument("-r", "--remote", action='store_true', help="from the MISP instance.")

args = parser.parse_args()

if args.package:
print(load_warninglists.from_package())
elif args.remote:
pm = PyMISP(misp_url, misp_key)
print(load_warninglists.from_instance(pm))
1 change: 1 addition & 0 deletions pymisp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def new_func(*args, **kwargs):
from .tools import Neo4j # noqa
from .tools import stix # noqa
from .tools import openioc # noqa
from .tools import load_warninglists # noqa
logger.debug('pymisp loaded properly')
except ImportError as e:
logger.warning('Unable to load pymisp properly: {}'.format(e))
26 changes: 26 additions & 0 deletions pymisp/tools/load_warninglists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

try:
from pymispwarninglists import WarningLists
has_pymispwarninglists = True
except ImportError:
has_pymispwarninglists = False


def from_instance(pymisp_instance, slow_search=False):
"""Load the warnindlist from an existing MISP instance
:pymisp_instance: Already instantialized PyMISP instance."""

warninglists_index = pymisp_instance.get_warninglists()['Warninglists']
all_warningslists = []
for warninglist in warninglists_index:
wl = pymisp_instance.get_warninglist(warninglist['Warninglist']['id'])['Warninglist']
wl['list'] = wl.pop('WarninglistEntry')
all_warningslists.append(wl)

return WarningLists(slow_search, all_warningslists)


def from_package(slow_search=False):
return WarningLists(slow_search)

0 comments on commit 250190e

Please sign in to comment.