If you have a MISP instance to test against, you can also run the live ones:
Note: You need to update the key in tests/testlive_comprehensive.py to the automation key of your admin account.
poetry run pytest --cov=pymisp tests/testlive_comprehensive.py
Samples and how to use PyMISP
Various examples and samples scripts are in the examples/ directory.
In the examples directory, you will need to change the keys.py.sample to enter your MISP url and API key.
cd examples
cp keys.py.sample keys.py
vim keys.py
The API key of MISP is available in the Automation section of the MISP web interface.
To test if your URL and API keys are correct, you can test with examples/last.py to
fetch the events published in the last x amount of time (supported time indicators: days (d), hours (h) and minutes (m)).
last.py
... or at least everything that can be imported/exported from/to a json blob
AbstractMISP is the master class, and inherits from collections.MutableMapping which means
the class can be represented as a python dictionary.
The abstraction assumes every property that should not be seen in the dictionary is prepended with a _,
or its name is added to the private list __not_jsonable (accessible through update_not_jsonable and set_not_jsonable.
This master class has helpers that make it easy to load, and export to, and from, a json string.
MISPEvent, MISPAttribute, MISPObjectReference, MISPObjectAttribute, and MISPObject
are subclasses of AbstractMISP, which mean that they can be handled as python dictionaries.
MISP Objects
Creating a new MISP object generator should be done using a pre-defined template and inherit AbstractMISPObjectGenerator.
Your new MISPObject generator must generate attributes and add them as class properties using add_attribute.
When the object is sent to MISP, all the class properties will be exported to the JSON export.
Installing PyMISP on a machine with no internet access
This is done using poetry and you need to have this repository cloned on your machine.
The commands below have to be run from inside the cloned directory.
From a machine with access to the internet, get the dependencies: