• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

pymisp/H07-May-2022-42,97140,860

LICENSEH A D19-Dec-20191.6 KiB2924

PKG-INFOH A D22-Jun-20207.4 KiB208148

README.mdH A D16-Jun-20205.4 KiB160102

pyproject.tomlH A D22-Jun-20202.3 KiB8070

setup.pyH A D22-Jun-202020.7 KiB297288

README.md

1**IMPORTANT NOTE**: This library will require **at least** python 3.6 starting the 1st of January 2020. If you have to legacy versions of python, please use PyMISP v2.4.119.1, and consider updating your system(s). Anything released within the last 2 years will do, starting with Ubuntu 18.04.
2
3README
4======
5
6[![Documentation Status](https://readthedocs.org/projects/pymisp/badge/?version=latest)](http://pymisp.readthedocs.io/?badge=latest)
7[![Build Status](https://travis-ci.org/MISP/PyMISP.svg?branch=main)](https://travis-ci.org/MISP/PyMISP)
8[![Coverage Status](https://coveralls.io/repos/github/MISP/PyMISP/badge.svg?branch=main)](https://coveralls.io/github/MISP/PyMISP?branch=main)
9[![Python 3.6](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/downloads/release/python-360/)
10[![PyPi version](https://img.shields.io/pypi/v/pymisp.svg)](https://pypi.python.org/pypi/pymisp/)
11[![Number of PyPI downloads](https://img.shields.io/pypi/dm/pymisp.svg)](https://pypi.python.org/pypi/pymisp/)
12
13# PyMISP - Python Library to access MISP
14
15PyMISP is a Python library to access [MISP](https://github.com/MISP/MISP) platforms via their REST API.
16
17PyMISP allows you to fetch events, add or update events/attributes, add or update samples or search for attributes.
18
19## Install from pip
20
21**It is strongly recommended to use a virtual environment**
22
23If you want to know more about virtual environments, [python has you covered](https://docs.python.org/3/tutorial/venv.html)
24
25Only basic dependencies:
26```
27pip3 install pymisp
28```
29
30With optional dependencies:
31```
32pip3 install pymisp[fileobjects,openioc,virustotal]
33```
34
35## Install the latest version from repo from development purposes
36
37**Note**: poetry is required
38
39```
40git clone https://github.com/MISP/PyMISP.git && cd PyMISP
41git submodule update --init
42poetry install -E fileobjects -E openioc -E virustotal -E docs -E pdfexport
43```
44
45### Running the tests
46
47```bash
48poetry run nosetests-3.4 --with-coverage --cover-package=pymisp,tests --cover-tests tests/test_*.py
49```
50
51If you have a MISP instance to test against, you can also run the live ones:
52
53**Note**: You need to update the key in `tests/testlive_comprehensive.py` to the automation key of your admin account.
54
55```bash
56poetry run nosetests-3.4 --with-coverage --cover-package=pymisp,tests --cover-tests tests/testlive_comprehensive.py
57```
58
59## Samples and how to use PyMISP
60
61Various examples and samples scripts are in the [examples/](examples/) directory.
62
63In the examples directory, you will need to change the keys.py.sample to enter your MISP url and API key.
64
65```
66cd examples
67cp keys.py.sample keys.py
68vim keys.py
69```
70
71The API key of MISP is available in the Automation section of the MISP web interface.
72
73To test if your URL and API keys are correct, you can test with examples/last.py to
74fetch the events published in the last x amount of time (supported time indicators: days (d), hours (h) and minutes (m)).
75last.py
76```
77cd examples
78python3 last.py -l 10h # 10 hours
79python3 last.py -l 5d  #  5 days
80python3 last.py -l 45m # 45 minutes
81```
82
83
84## Debugging
85
86You have two options there:
87
881. Pass `debug=True` to `PyMISP` and it will enable logging.DEBUG to stderr on the whole module
89
902. Use the python logging module directly:
91
92```python
93
94import logging
95logger = logging.getLogger('pymisp')
96
97# Configure it as you whish, for example, enable DEBUG mode:
98logger.setLevel(logging.DEBUG)
99```
100
101Or if you want to write the debug output to a file instead of stderr:
102
103```python
104import pymisp
105import logging
106
107logger = logging.getLogger('pymisp')
108logging.basicConfig(level=logging.DEBUG, filename="debug.log", filemode='w', format=pymisp.FORMAT)
109```
110
111## Test cases
112
1131. The content of `mispevent.py` is tested on every commit
1142. The tests cases that require a running MISP instance can be run the following way:
115
116
117```bash
118# From poetry
119
120nosetests-3.4 -s --with-coverage --cover-package=pymisp,tests --cover-tests tests/testlive_comprehensive.py:TestComprehensive.[test_name]
121
122```
123
124## Documentation
125
126[PyMISP API documentation is available](https://media.readthedocs.org/pdf/pymisp/latest/pymisp.pdf).
127
128Documentation can be generated with epydoc:
129
130```
131epydoc --url https://github.com/MISP/PyMISP --graph all --name PyMISP --pdf pymisp -o doc
132```
133
134### Jupyter notebook
135
136A series of [Jupyter notebooks for PyMISP tutorial](https://github.com/MISP/PyMISP/tree/master/docs/tutorial) are available in the repository.
137
138## Everything is a Mutable Mapping
139
140... or at least everything that can be imported/exported from/to a json blob
141
142`AbstractMISP` is the master class, and inherit `collections.MutableMapping` which means
143the class can be represented as a python dictionary.
144
145The abstraction assumes every property that should not be seen in the dictionary is prepended with a `_`,
146or its name is added to the private list `__not_jsonable` (accessible through `update_not_jsonable` and `set_not_jsonable`.
147
148This master class has helpers that will make it easy to load, and export, to, and from, a json string.
149
150`MISPEvent`, `MISPAttribute`, `MISPObjectReference`, `MISPObjectAttribute`, and `MISPObject`
151are subclasses of AbstractMISP, which mean that they can be handled as python dictionaries.
152
153## MISP Objects
154
155Creating a new MISP object generator should be done using a pre-defined template and inherit `AbstractMISPObjectGenerator`.
156
157Your new MISPObject generator need to generate attributes, and add them as class properties using `add_attribute`.
158
159When the object is sent to MISP, all the class properties will be exported to the JSON export.
160