Modules for expansion services, import and export in MISP http://misp.github.io/misp-modules
 
 
 
 
Go to file
Christophe Vandeplas 1bdb24c9bc
fix: fixes issues added in latest commit
2024-08-12 11:34:13 +02:00
.github/workflows fix: [tests] fix yara issue in unit tests 2024-08-10 07:12:20 +02:00
docker Disable not required package virtualenv for final stage 2019-09-02 12:20:18 +02:00
docs chg: [doc] Big doc revamp #680 2024-08-12 11:23:10 +02:00
documentation fix: fixes issues added in latest commit 2024-08-12 11:34:13 +02:00
etc/systemd/system Update misp-modules.service 2022-08-07 18:27:38 +02:00
misp_modules fix: fixes issues added in latest commit 2024-08-12 11:34:13 +02:00
tests fix: fixes issues added in latest commit 2024-08-12 11:34:13 +02:00
tools chr: Restart the modules after update 2019-02-26 16:48:15 -08:00
var default var directory added 2016-02-18 09:25:51 +01:00
website chg: [query] query as same 2024-07-08 16:06:29 +02:00
.gitchangelog.rc chg: [gitchangelogrc] added 2021-12-22 11:37:33 +01:00
.gitignore chg: [doc] Big doc revamp #680 2024-08-12 11:23:10 +02:00
.gitmodules Contribute a TAXII 2.1 import style misp-module. 2022-01-11 21:54:09 -05:00
.travis.yml chg: [travis] flake8 updated 2021-06-11 14:52:28 +02:00
ChangeLog.md new: [ChangeLog] added 2021-04-19 09:47:52 +02:00
DOC-REQUIREMENTS new: [REQUIREMENTS] for the documentation generation 2022-01-07 12:10:21 +01:00
LICENSE Create LICENSE 2016-09-05 07:26:29 +02:00
Makefile chg: [doc] Makefile fixed 2021-04-19 11:05:22 +02:00
Pipfile fix: [tests] fix yara issue in unit tests 2024-08-10 07:12:20 +02:00
Pipfile.lock fix: [tests] fix yara issue in unit tests 2024-08-10 07:12:20 +02:00
README.md chg: [doc] Big doc revamp #680 2024-08-12 11:23:10 +02:00
README.rst Make it a package 2016-06-18 11:04:41 +09:00
REQUIREMENTS fix: [tests] fix yara issue in unit tests 2024-08-10 07:12:20 +02:00
mkdocs.yml chg: [doc] Big doc revamp #680 2024-08-12 11:23:10 +02:00
pyproject.toml Update dependency files 2021-08-24 12:31:23 +01:00
setup.py fix: [setup] Fixed potential conflicts with libraries in python 3.10 install 2022-05-24 17:05:21 +02:00

README.md

MISP modules

Build statusCoverage Status codecov

MISP modules are autonomous modules that can be used to extend MISP for new services such as expansion, import, export and workflow action.

MISP modules can be also installed and used without MISP as a standalone tool accessible via a convenient web interface.

The modules are written in Python 3 following a simple API interface. The objective is to ease the extensions of MISP functionalities without modifying core components. The API is available via a simple REST API which is independent from MISP installation or configuration and can be used with other tools.

For more information: Extending MISP with Python modules slides from MISP training.

Existing MISP modules

Expansion Modules

  • Abuse IPDB - AbuseIPDB MISP expansion module
  • OSINT DigitalSide - On demand query API for OSINT.digitalside.it project.
  • APIVoid - Module to query APIVoid with some domain attributes.
  • AssemblyLine Query - A module tu query the AssemblyLine API with a submission ID to get the submission report and parse it.
  • AssemblyLine Submit - A module to submit samples and URLs to AssemblyLine for advanced analysis, and return the link of the submission.
  • Backscatter.io - Backscatter.io module to bring mass-scanning observations into MISP.
  • BGP Ranking - Query BGP Ranking to get the ranking of an Autonomous System number.
  • BTC Scam Check - An expansion hover module to query a special dns blacklist to check if a bitcoin address has been abused.
  • BTC Steroids - An expansion hover module to get a blockchain balance from a BTC address in MISP.
  • Censys Enrich - An expansion module to enrich attributes in MISP by quering the censys.io API
  • CIRCL Passive DNS - Module to access CIRCL Passive DNS.
  • CIRCL Passive SSL - Modules to access CIRCL Passive SSL.
  • ClaamAV - Submit file to ClamAV
  • Cluster25 Expand - Module to query Cluster25 CTI.
  • Country Code - Module to expand country codes.
  • CPE Lookup - An expansion module to query the CVE search API with a cpe code to get its related vulnerabilities.
  • CrowdSec CTI - Hover module to lookup an IP in CrowdSec's CTI
  • CrowdStrike Falcon - Module to query CrowdStrike Falcon.
  • Cuckoo Submit - Submit files and URLs to Cuckoo Sandbox
  • CVE Lookup - An expansion hover module to expand information about CVE id.
  • CVE Advanced Lookup - An expansion module to query the CIRCL CVE search API for more information about a vulnerability (CVE).
  • Cytomic Orion Lookup - An expansion module to enrich attributes in MISP by quering the Cytomic Orion API
  • DBL Spamhaus Lookup - Checks Spamhaus DBL for a domain name.
  • DNS Resolver - jj
  • DOCX Enrich - Module to extract freetext from a .docx document.
  • DomainTools Lookup - DomainTools MISP expansion module.
  • EQL Query Generator - EQL query generation for a MISP attribute.
  • EUPI Lookup - A module to query the Phishing Initiative service (https://phishing-initiative.lu).
  • URL Components Extractor - Extract URL components
  • Farsight DNSDB Lookup - Module to access Farsight DNSDB Passive DNS.
  • GeoIP ASN Lookup - Query a local copy of the Maxmind Geolite ASN database (MMDB format)
  • GeoIP City Lookup - An expansion module to query a local copy of Maxmind's Geolite database with an IP address, in order to get information about the city where it is located.
  • GeoIP Country Lookup - Query a local copy of Maxminds Geolite database, updated for MMDB format
  • Google Safe Browsing Lookup - Google safe browsing expansion module
  • Google Search - An expansion hover module to expand google search information about an URL
  • Google Threat Intelligence Lookup - An expansion module to have the observable's threat score assessed by Google Threat Intelligence.
  • GreyNoise Lookup - Module to query IP and CVE information from GreyNoise
  • Hashdd Lookup - A hover module to check hashes against hashdd.com including NSLR dataset.
  • CIRCL Hashlookup Lookup - An expansion module to query the CIRCL hashlookup services to find it if a hash is part of a known set such as NSRL.
  • Have I Been Pwned Lookup - Module to access haveibeenpwned.com API.
  • HTML to Markdown - Expansion module to fetch the html content from an url and convert it into markdown.
  • HYAS Insight Lookup - HYAS Insight integration to MISP provides direct, high volume access to HYAS Insight data. It enables investigators and analysts to understand and defend against cyber adversaries and their infrastructure.
  • Intel471 Lookup - Module to access Intel 471
  • IP2Location.io Lookup - An expansion module to query IP2Location.io to gather more information on a given IP address.
  • IPASN-History Lookup - Module to query an IP ASN history service (https://github.com/D4-project/IPASN-History).
  • IPInfo.io Lookup - An expansion module to query ipinfo.io to gather more information on a given IP address.
  • IPQualityScore Lookup - IPQualityScore MISP Expansion Module for IP reputation, Email Validation, Phone Number Validation, Malicious Domain and Malicious URL Scanner.
  • IPRep Lookup - Module to query IPRep data for IP addresses.
  • Ninja Template Rendering - Render the template with the data passed
  • Joe Sandbox Import - Query Joe Sandbox API with a submission url to get the json report and extract its data that is parsed and converted into MISP attributes and objects.
  • Joe Sandbox Submit - A module to submit files or URLs to Joe Sandbox for an advanced analysis, and return the link of the submission.
  • Lastline Lookup - Deprecation notice: this module will be deprecated by December 2021, please use vmware_nsx module.

Query Lastline with an analysis link and parse the report into MISP attributes and objects.

  • Lastline Submit - Deprecation notice: this module will be deprecated by December 2021, please use vmware_nsx module.

Module to submit a file or URL to Lastline.

Export Modules

Import Modules

  • PDNS COF Importer - Passive DNS Common Output Format (COF) MISP importer
  • CSV Import - Module to import MISP attributes from a csv file.
  • Cuckoo Sandbox Import - Module to import Cuckoo JSON.
  • Email Import - Email import module for MISP
  • GoAML Import - Module to import MISP objects about financial transactions from GoAML files.
  • Import Blueprint - Generic blueprint to be copy-pasted to quickly boostrap creation of import module.
  • Joe Sandbox Import - A module to import data from a Joe Sandbox analysis json report.
  • Lastline Import - Deprecation notice: this module will be deprecated by December 2021, please use vmware_nsx module.

Module to import and parse reports from Lastline analysis links.

Action Modules

  • Mattermost - Simplistic module to send message to a Mattermost channel.
  • Slack - Simplistic module to send messages to a Slack channel.
  • Test action - This module is merely a test, always returning true. Triggers on event publishing.

Installation

Be sure to run the latest version of pip. To install the latest version of pip, pip install --upgrade pip will do the job.

SUDO_WWW="sudo -u www-data"

sudo apt-get install -y \
  python3-dev \
  python3-pip \
  git \
  libpq5 \
  libjpeg-dev \
  tesseract-ocr \
  libpoppler-cpp-dev \
  imagemagick virtualenv \
  libopencv-dev \
  zbar-tools \
  libzbar0 \
  libzbar-dev \
  libfuzzy-dev \
  libcaca-dev \
  build-essential

# BEGIN with virtualenv:
$SUDO_WWW virtualenv -p python3 /var/www/MISP/venv
# END with virtualenv

cd /usr/local/src/
# Ideally you add your user to the staff group and make /usr/local/src group writeable, below follows an example with user misp
sudo adduser misp staff
sudo chmod 2775 /usr/local/src
sudo chown root:staff /usr/local/src
git clone https://github.com/MISP/misp-modules.git
git clone git://github.com/stricaud/faup.git faup
git clone git://github.com/stricaud/gtcaca.git gtcaca

# Install gtcaca/faup
cd gtcaca
mkdir -p build
cd build
cmake .. && make
sudo make install
cd ../../faup
mkdir -p build
cd build
cmake .. && make
sudo make install
sudo ldconfig

cd ../../misp-modules

# BEGIN with virtualenv:
$SUDO_WWW  /var/www/MISP/venv/bin/pip install -I -r REQUIREMENTS
$SUDO_WWW  /var/www/MISP/venv/bin/pip install .
# END with virtualenv

# BEGIN without virtualenv:
sudo pip install -I -r REQUIREMENTS
sudo pip install .
# END without virtualenv

# Start misp-modules as a service
sudo cp etc/systemd/system/misp-modules.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now misp-modules
sudo service misp-modules start  # or
/var/www/MISP/venv/bin/misp-modules -l 127.0.0.1 -s & # to start the modules manually

How to install and start MISP modules on RHEL-based distributions ?

As of this writing, the official RHEL repositories only contain Ruby 2.0.0 and Ruby 2.1 or higher is required. As such, this guide installs Ruby 2.2 from the SCL repository.

SUDO_WWW="sudo -u apache"
sudo yum install \
  rh-python36 \
  rh-ruby22 \
  openjpeg-devel \
  rubygem-rouge \
  rubygem-asciidoctor \
  zbar-devel \
  opencv-devel \
  gcc-c++ \
  pkgconfig \
  poppler-cpp-devel \
  python-devel \
  redhat-rpm-config
cd /var/www/MISP
$SUDO_WWW git clone https://github.com/MISP/misp-modules.git
cd misp-modules
$SUDO_WWW /usr/bin/scl enable rh-python36 "virtualenv -p python3 /var/www/MISP/venv"
$SUDO_WWW /var/www/MISP/venv/bin/pip install -U -I -r REQUIREMENTS
$SUDO_WWW /var/www/MISP/venv/bin/pip install -U .

Create the service file /etc/systemd/system/misp-modules.service :

echo "[Unit]
Description=MISP's modules
After=misp-workers.service

[Service]
Type=simple
User=apache
Group=apache
ExecStart=/usr/bin/scl enable rh-python36 rh-ruby22  '/var/www/MISP/venv/bin/misp-modules -l 127.0.0.1 -s'
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/misp-modules.service

The After=misp-workers.service must be changed or removed if you have not created a misp-workers service. Then, enable the misp-modules service and start it:

systemctl daemon-reload
systemctl enable --now misp-modules

How to use an MISP modules Docker container

Docker build

docker build -t misp-modules \
    --build-arg BUILD_DATE=$(date -u +"%Y-%m-%d") \
  docker/

Docker run

# Start Redis
docker run --rm -d --name=misp-redis redis:alpine
# Start MISP-modules
docker run \
    --rm -d --name=misp-modules \
    -e REDIS_BACKEND=misp-redis \
    -e REDIS_PORT="6379" \
    -e REDIS_PW="" \
    -e REDIS_DATABASE="245" \
    -e MISP_MODULES_DEBUG="false" \
    dcso/misp-dockerized-misp-modules

Docker-compose

services:
  misp-modules:
    # https://hub.docker.com/r/dcso/misp-dockerized-misp-modules
    image: dcso/misp-dockerized-misp-modules:3

    # Local image:
    #image: misp-modules
    #build:
    #  context: docker/

    environment:
      # Redis
      REDIS_BACKEND: misp-redis
      REDIS_PORT: "6379"
      REDIS_DATABASE: "245"
      # System PROXY (OPTIONAL)
      http_proxy:
      https_proxy:
      no_proxy: 0.0.0.0
      # Timezone (OPTIONAL)
      TZ: Europe/Berlin
      # MISP-Modules (OPTIONAL)
      MISP_MODULES_DEBUG: "false"
      # Logging options (OPTIONAL)
      LOG_SYSLOG_ENABLED: "no"
  misp-redis:
    # https://hub.docker.com/_/redis or alternative https://hub.docker.com/r/dcso/misp-dockerized-redis/
    image: redis:alpine

Install misp-module on an offline instance.

First, you need to grab all necessary packages for example like this :

Use pip wheel to create an archive

mkdir misp-modules-offline
pip3 wheel -r REQUIREMENTS shodan --wheel-dir=./misp-modules-offline
tar -cjvf misp-module-bundeled.tar.bz2 ./misp-modules-offline/*

On offline machine :

mkdir misp-modules-bundle
tar xvf misp-module-bundeled.tar.bz2 -C misp-modules-bundle
cd misp-modules-bundle
ls -1|while read line; do sudo pip3 install --force-reinstall --ignore-installed --upgrade --no-index --no-deps ${line};done

Next you can follow standard install procedure.

How to add your own MISP modules?

Create your module in misp_modules/modules/expansion/, misp_modules/modules/export_mod/, or misp_modules/modules/import_mod/. The module should have at minimum three functions:

  • introspection function that returns a dict of the supported attributes (input and output) by your expansion module.
  • handler function which accepts a JSON document to expand the values and return a dictionary of the expanded values.
  • version function that returns a dict with the version and the associated meta-data including potential configurations required of the module.

Don't forget to return an error key and value if an error is raised to propagate it to the MISP user-interface.

Your module's script name should also be added in the __all__ list of <module type folder>/__init__.py in order for it to be loaded.

...
    # Checking for required value
    if not request.get('ip-src'):
        # Return an error message
        return {'error': "A source IP is required"}
...

introspection

The function that returns a dict of the supported attributes (input and output) by your expansion module.

mispattributes = {'input': ['link', 'url'],
                  'output': ['attachment', 'malware-sample']}

def introspection():
    return mispattributes

version

The function that returns a dict with the version and the associated meta-data including potential configurations required of the module.

Additional Configuration Values

If your module requires additional configuration (to be exposed via the MISP user-interface), you can define those in the moduleconfig value returned by the version function.

# config fields that your code expects from the site admin
moduleconfig = ["apikey", "event_limit"]

def version():
    moduleinfo['config'] = moduleconfig
    return moduleinfo

When you do this a config array is added to the meta-data output containing all the potential configuration values:

"meta": {
      "description": "PassiveTotal expansion service to expand values with multiple Passive DNS sources",
      "config": [
        "username",
        "password"
      ],
      "module-type": [
        "expansion",
        "hover"
      ],

...

If you want to use the configuration values set in the web interface they are stored in the key config in the JSON object passed to the handler.

def handler(q=False):

    # Check if we were given a configuration
    config = q.get("config", {})

    # Find out if there is a username field
    username = config.get("username", None)

handler

The function which accepts a JSON document to expand the values and return a dictionary of the expanded values.

def handler(q=False):
    "Fully functional rot-13 encoder"
    if q is False:
        return False
    request = json.loads(q)
    src = request.get('ip-src')
    if src is None:
        # Return an error message
        return {'error': "A source IP is required"}
    else:
        return {'results':
                codecs.encode(src, "rot-13")}

export module

For an export module, the request["data"] object corresponds to a list of events (dictionaries) to handle.

Iterating over events attributes is performed using their Attribute key.

...
for event in request["data"]:
        for attribute in event["Attribute"]:
          # do stuff w/ attribute['type'], attribute['value'], ...
...

### Returning Binary Data

If you want to return a file or other data you need to add a data attribute.

~~~python
{"results": {"values": "filename.txt",
             "types": "attachment",
             "data"  : base64.b64encode(<ByteIO>)  # base64 encode your data first
             "comment": "This is an attachment"}}

If the binary file is malware you can use 'malware-sample' as the type. If you do this the malware sample will be automatically zipped and password protected ('infected') after being uploaded.

{"results": {"values": "filename.txt",
             "types": "malware-sample",
             "data"  : base64.b64encode(<ByteIO>)  # base64 encode your data first
             "comment": "This is an attachment"}}

To learn more about how data attributes are processed you can read the processing code here.

Module type

A MISP module can be of four types:

  • expansion - service related to an attribute that can be used to extend and update an existing event.
  • hover - service related to an attribute to provide additional information to the users without updating the event.
  • import - service related to importing and parsing an external object that can be used to extend an existing event.
  • export - service related to exporting an object, event, or data.

module-type is an array where the list of supported types can be added.

Testing your modules?

MISP uses the modules function to discover the available MISP modules and their supported MISP attributes:

% curl -s http://127.0.0.1:6666/modules | jq .
[
  {
    "name": "passivetotal",
    "type": "expansion",
    "mispattributes": {
      "input": [
        "hostname",
        "domain",
        "ip-src",
        "ip-dst"
      ],
      "output": [
        "ip-src",
        "ip-dst",
        "hostname",
        "domain"
      ]
    },
    "meta": {
      "description": "PassiveTotal expansion service to expand values with multiple Passive DNS sources",
      "config": [
        "username",
        "password"
      ],
      "author": "Alexandre Dulaunoy",
      "version": "0.1"
    }
  },
  {
    "name": "sourcecache",
    "type": "expansion",
    "mispattributes": {
      "input": [
        "link"
      ],
      "output": [
        "link"
      ]
    },
    "meta": {
      "description": "Module to cache web pages of analysis reports, OSINT sources. The module returns a link of the cached page.",
      "author": "Alexandre Dulaunoy",
      "version": "0.1"
    }
  },
  {
    "name": "dns",
    "type": "expansion",
    "mispattributes": {
      "input": [
        "hostname",
        "domain"
      ],
      "output": [
        "ip-src",
        "ip-dst"
      ]
    },
    "meta": {
      "description": "Simple DNS expansion service to resolve IP address from MISP attributes",
      "author": "Alexandre Dulaunoy",
      "version": "0.1"
    }
  }
]

The MISP module service returns the available modules in a JSON array containing each module name along with their supported input attributes.

Based on this information, a query can be built in a JSON format and saved as body.json:

{
  "hostname": "www.foo.be",
  "module": "dns"
}

Then you can POST this JSON format query towards the MISP object server:

curl -s http://127.0.0.1:6666/query -H "Content-Type: application/json" --data @body.json -X POST

The module should output the following JSON:

{
  "results": [
    {
      "types": [
        "ip-src",
        "ip-dst"
      ],
      "values": [
        "188.65.217.78"
      ]
    }
  ]
}

It is also possible to restrict the category options of the resolved attributes by passing a list of categories along (optional):

{
  "results": [
    {
      "types": [
        "ip-src",
        "ip-dst"
      ],
      "values": [
        "188.65.217.78"
      ],
      "categories": [
        "Network activity",
        "Payload delivery"
      ]
    }
  ]
}

For both the type and the category lists, the first item in the list will be the default setting on the interface.

Enable your module in the web interface

For a module to be activated in the MISP web interface it must be enabled in the "Plugin Settings.

Go to "Administration > Server Settings" in the top menu

  • Go to "Plugin Settings" in the top "tab menu bar"
  • Click on the name of the type of module you have created to expand the list of plugins to show your module.
  • Find the name of your plugin's "enabled" value in the Setting Column. "Plugin.[MODULE NAME]_enabled"
  • Double click on its "Value" column
Priority        Setting                         Value   Description                             Error Message
Recommended     Plugin.Import_ocr_enabled       false   Enable or disable the ocr module.       Value not set.
  • Use the drop-down to set the enabled value to 'true'
Priority        Setting                         Value   Description                             Error Message
Recommended     Plugin.Import_ocr_enabled       true   Enable or disable the ocr module.       Value not set.

Set any other required settings for your module

In this same menu set any other plugin settings that are required for testing.

Install misp-module on an offline instance.

First, you need to grab all necessary packages for example like this :

Use pip wheel to create an archive

mkdir misp-modules-offline
pip3 wheel -r REQUIREMENTS shodan --wheel-dir=./misp-modules-offline
tar -cjvf misp-module-bundeled.tar.bz2 ./misp-modules-offline/*

On offline machine :

mkdir misp-modules-bundle
tar xvf misp-module-bundeled.tar.bz2 -C misp-modules-bundle
cd misp-modules-bundle
ls -1|while read line; do sudo pip3 install --force-reinstall --ignore-installed --upgrade --no-index --no-deps ${line};done

Next you can follow standard install procedure.

How to contribute your own module?

Fork the project, add your module, test it and make a pull-request. Modules can be also private as you can add a module in your own MISP installation.

Tips for developers creating modules

Download a pre-built virtual image from the MISP training materials.

  • Create a Host-Only adapter in VirtualBox
  • Set your Misp OVA to that Host-Only adapter
  • Start the virtual machine
  • Get the IP address of the virtual machine
  • SSH into the machine (Login info on training page)
  • Go into the misp-modules directory
cd /usr/local/src/misp-modules

Set the git repo to your fork and checkout your development branch. If you SSH'ed in as the misp user you will have to use sudo.

sudo git remote set-url origin https://github.com/YourRepo/misp-modules.git
sudo git pull
sudo git checkout MyModBranch

Remove the contents of the build directory and re-install misp-modules.

sudo rm -fr build/*
sudo -u www-data /var/www/MISP/venv/bin/pip install --upgrade .

SSH in with a different terminal and run misp-modules with debugging enabled.

# In case misp-modules is not a service do:
# sudo killall misp-modules
sudo systemctl disable --now misp-modules
sudo -u www-data /var/www/MISP/venv/bin/misp-modules -d

In your original terminal you can now run your tests manually and see any errors that arrive

cd tests/
curl -s http://127.0.0.1:6666/query -H "Content-Type: application/json" --data @MY_TEST_FILE.json -X POST
cd ../

Documentation

In order to provide documentation about some modules that require specific input / output / configuration, the index.md file within the docs directory contains detailed information about the general purpose, requirements, features, input and ouput of each of these modules:

  • *description - quick description of the general purpose of the module, as the one given by the moduleinfo
  • requirements - special libraries needed to make the module work
  • features - description of the way to use the module, with the required MISP features to make the module give the intended result
  • references - link(s) giving additional information about the format concerned in the module
  • input - description of the format of data used in input
  • output - description of the format given as the result of the module execution

Licenses

For further Information see also the license file.