Code Monkey home page Code Monkey logo

tenzir / threatbus Goto Github PK

View Code? Open in Web Editor NEW
256.0 26.0 16.0 910 KB

๐ŸšŒ Threat Bus โ€“ A threat intelligence dissemination layer for open-source security tools.

Home Page: https://docs.tenzir.com/threatbus

License: BSD 3-Clause "New" or "Revised" License

Python 92.82% Zeek 2.86% Makefile 2.55% Dockerfile 0.95% Shell 0.83%
threat-intelligence threatintel threat-hunting ids zeek misp opencti opencti-connector sightings threat-bus

threatbus's Introduction

Threat Bus

A threat intelligence dissemination layer for open-source security tools.

PyPI Status Build Status Total alerts Language grade: Python Development Status Latest Release License

Getting Started โ€” Contributing Guidelines โ€” Writing Plugins โ€” License โ€” Documentation

Chat

Key Features

  • Connect Open-Source Security Tools: Threat Bus is a pub-sub broker for threat intelligence data. With Threat Bus you can seamlessly integrate threat intel platforms like OpenCTI or MISP with detection tools and databases like Zeek or VAST.

  • Native STIX-2: Threat Bus transports indicators and sightings encoded as per the STIX-2 open format specification.

  • Plugin-based Architecture: The project is plugin-based and can be extended easily. Read about the different plugin types and how to write your own. We welcome contributions to adopt new open source tools!

  • Official Plugins: We maintain many plugins right in the official Threat Bus repository. Check out our integrations for MISP, Zeek, CIFv3, and generally apps that connect via ZeroMQ, like vast-threatbus and our OpenCTI connector.

  • Snapshotting: The snapshot feature allows subscribers to directly request threat intelligence data for a certain time range from other applications. Threat Bus handles the point-to-point communication of all involved apps.

Getting Started

The config.yaml.example file provides a working configuration for Threat Bus with all existing application plugins enabled together with the RabbitMQ backbone.

The following example shows how to connect Zeek via Threat Bus. There are more integrations available, so make sure to check out all Threat Bus projects on PyPI.

The example assumes that threatbus is available in your PATH. See the section on Installation below for more information on how to get there.

Start Threat Bus

threatbus

Start with a specially named config file

The config.yaml.example file in this directory gives an overview of the available config keys and their default values.

threatbus -c /path/to/your/special-config.yaml

Environment variables take precedence over config file values. Prefix everything with THREATBUS_

export THREATBUS_LOGGING__CONSOLE=true
threatbus -c /path/to/your/special-config.yaml

Note that you must use a double underscores __ in your env to refer to nested config variables.

Start Zeek as Threat Bus app

zeek -i <INTERFACE> -C ./apps/zeek/threatbus.zeek

Start Zeek and request a snapshot

zeek -i <INTERFACE> -C ./apps/zeek/threatbus.zeek "Tenzir::snapshot_intel=30 days"

Threat Bus also ships as pre-built Docker image and is available on Docker Hub.

Use the Threat Bus Docker container

docker run tenzir/threatbus:latest --help

Start Threat Bus container with a custom config file

docker run -p 47661:47661 -v $PWD/my-custom-config.yaml:/opt/tenzir/threatbus/my-custom-config.yaml tenzir/threatbus:latest -c my-custom-config.yaml

Tip: Threat Bus checks for config files with default names. If you mount your config file to /opt/tenzir/threatbus/config.yaml, you can start the application without specifying the config file location with the -c parameter.

Installation

Install threatbus and all plugins that you require. Optionally, use a virtual environment.

Note that Threat Bus requires at least Python 3.7+, earlier versions are not supported.

virtualenv venv                       # optional
source venv/bin/activate              # optional
pip install threatbus
pip install threatbus-inmem           # inmemory backbone plugin
pip install threatbus-rabbitmq        # RabbitMQ backbone plugin
pip install threatbus-misp[zmq]       # MISP application plugin
pip install threatbus-zeek            # Zeek application plugin
pip install threatbus-zmq             # ZeroMQ application plugin
pip install threatbus-<plugin_name>

Testing

Use the Makefile to run unit and integration tests.

make unit-tests
make integration-tests

The integration tests require a local Zeek and Docker installation.

Development

Setup a virtual environment and install threatbus and some plugins with the in development mode:

virtualenv venv
source venv/bin/activate
make dev-mode

Configuration & Extension

A plugin must define a setup.py. Whenever a plugin is installed, you have to add a corresponding configuration section to threatbus' config.yaml. That section has to be named after the name in the entrypoint declaration of the plugin's setup.py file.

Please adhere to the plugin naming conventions and always prefix your plugin name with threatbus-.

Plugins can either be apps or backbones. Application plugins (apps) add new functionality to Threat Bus and allow communication to a specific app and/or via a specific protocol (e.g., ZeroMQ or Zeek/broker). Backbone plugins add a new storage and distribution backend to Threat Bus (e.g., in-memory or RabbitMQ).

Example:

  • plugin folder structure:
    plugins
    โ”œโ”€โ”€ apps
    |   โ””โ”€โ”€ threatbus-myapp
    โ”‚       โ”œโ”€โ”€ setup.py
    |       โ””โ”€โ”€ threatbus_myapp.py
    โ””โ”€โ”€ backbones
        โ””โ”€โ”€ threatbus-inmem
            โ”œโ”€โ”€ setup.py
            โ””โ”€โ”€ threatbus_inmem.py
  • setup.py
    from setuptools import setup
    setup(
      name="threatbus-myapp",
      install_requires="threatbus",
      entry_points={"threatbus.app": ["myapp = threatbus_myapp"]},
      py_modules=["threatbus_myapp"],
    )
  • config.yaml entry for threatbus
    ...
    plugins:
      apps:
        myapp:
        ...

Threat Bus API

Plugins specifications are available in threatbus/appspecs.py and threatbus/backbonespecs.py, respectively. For any plugin, you should at least implement the run function.

App plugins are provided two callback functions to use for subscription management. Internally, Threat Bus will propagate subscription requests to all installed backbone plugins.

The subscription callback allows applications to request an optional snapshot time delta. Threat Bus will forward snapshot requests to all those apps that have implemented the snapshot feature (see threatbus/appspecs.py).

Implementation

Please use the StoppableWorker base class to model your plugin's busy work. Plugins should never block the main thread of the application. Implementing that class also facilitates a graceful shutdown.

All officially maintained Threat Bus plugins implement StoppableWorker. Refer to any of the existing plugins for an example.

License

Threat Bus comes with a 3-clause BSD license.

threatbus's People

Contributors

0snap avatar dispanser avatar dominiklohmann avatar lava avatar mattreduce avatar mavam avatar mdavis332 avatar satta avatar tobim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

threatbus's Issues

cif3 plugin -- output queue.Queue() hanging on get()

Hi @0ortmann and team,

ich bin zurueck =/

Trying to finish up an app plugin for threatbus to send out to another threat intel system (CIFv3). Setup is working fine and I can get threatbus started up with the cif3 plugin. The primary objective is to take submissions from MISP and eventually send them on to CIF.

However, the issue I've run into is that while the zmq sub to MISP seems to be picking up new attributes and sending them out to threatbus/intel topic, the call to queue.Queue().get() at https://github.com/mdavis332/threatbus/blob/master/plugins/apps/threatbus_cif3/plugin.py#L42 is hanging. If I take the if watched_queue.empty() bit out and just let it rely on the get() timeout, it cycles back around fine every 15 seconds. However, the second an Intel item is picked up by the queue, the loop never cycles again and never moves forward.

Any thoughts? Thanks again for your help.

See nothing in kafka topic

Hi!
First of all thank you for your great job!

I have some troubles with Threatbus using with Kafka. I want to ship IOCs from MISP to kafka via ThreatBus
That am i dooing wrong?

I have installed misp and dockerized kafka, manually created topic with name indicator, and run threatbus with my config-file.

ThreatBus messages:

image

ThreatBus host tcpdump:
image
Kafka host tcpdump:
image

I saw nothing in my indicator topic, only this in __consumer_offsets topic:
image

My ThreatBus config:

logging:
  console: true
  console_verbosity: INFO        # One of "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL".
  file: false

plugins:
  backbones:
    inmem: {}
  apps:
    misp:
      api:
        host: https://localhost
        ssl: false
        key: zBkLoUb7Q*******************Vqz
      filter:
        - orgs: 
            - "2"
      kafka:
        topics:
        - indicator
        poll_interval: 1.0
      #  # All config entries are passed as-is to librdkafka
      #  # https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
        config:
          bootstrap.servers: "kafka:9092"
          group.id: "threatbus"
          auto.offset.reset: "earliest"

My dockerized kafka:

version: '3.5'

networks:
  default:
    name: threatbus
    external: false
volumes:
  kafka_data:
  zookeeper_data:
services:
  zookeeper:
    image: docker.io/bitnami/zookeeper:3.7
    restart: unless-stopped
    ports:
      - "2181:2181"
    volumes:
      - "zookeeper_data:/bitnami"
      - "./zookeeper_data/:/bitnami/zookeeper/"
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
      - ZOO_SERVER_ID=1 
  kafka:
    image: docker.io/bitnami/kafka:2
    restart: unless-stopped
    ports:
      - "9092:9092"
    volumes:
      - "kafka_data:/bitnami"
      - "./kafka_data/:/bitnami/kafka/data"
    environment:
      - KAFKA_BROKER_ID=1 
      - KAFKA_ADVERTISED_PORT=9092
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
#      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
      - KAFKA_CFG_PLAINTEXT_HOST://localhost:9092
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
      - KAFKA_CFG_LOG_RETENTION_BYTES=21474836480
      - KAFKA_CFG_LOG_RETENTION_HOURS=24
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_DELETE_TOPIC_ENABLE=true
    depends_on:
      - zookeeper

Thank you!

Cannot subscribe to MISP and Failed to start MISP plugin

Hello sir,
I am very new to the threatbus and misp. So sincere apology for asking the naive question here.
I am trying to figure out how threatbus works with zeek and misp. Also I referred the youtube video put my tenzir team regarding that. I am using misp and zeek all on same host inside a ubuntu 20.04 vm. I am able to access the misp through https://localhost from inside And using https://localhost:8443 from outside vm. I am struggling through the following problem, I will be very grateful if someone can take a look about why I am getting this error:
threatbus

Observed Behavior

(venv) root@ubuntu-pc:/home/ubuntu# threatbus -c config-new.yaml
2020-12-09 20:52:48 INFO [threatbus] Starting plugins...
2020-12-09 20:52:48 INFO [threatbus_inmem.plugin] In-memory backbone started.
2020-12-09 20:52:48 INFO [threatbus_inmem.plugin] Adding subscription to: threatbus/snapshotrequest
2020-12-09 20:52:48 INFO [threatbus_inmem.plugin] Adding subscription to: threatbus/snapshotenvelope
2020-12-09 20:52:48 INFO [threatbus_zeek.plugin] Zeek plugin started
2020-12-09 20:52:48 ERROR [threatbus_misp.plugin] Cannot subscribe to MISP at https://localhost, using SSL: True
2020-12-09 20:52:48 ERROR [threatbus_misp.plugin] Failed to start MISP plugin

  • Version:
  • Compiler:
  • Operating System: Ubuntu 20.04
  • ..

Can't tell that MISP messages are making it to backbone

Observed Behavior

Guten Tag!
Running tenzir/threatbus:latest docker container and mounting config.yaml as volume. I believe it's successfully talking to my MISP instance, but there's no indication the backbone is getting traffic (debug for console turned on but nothing showing up in STDOUT on docker-compose logs -f). As an aside, I'm not using the zeek portion of the config at all (no Zeek instance).

Ultimately, I'm looking at writing a threatbus plugin to take the MISP messages that are published to in_mem and submit those as indicators to another threat intel platform (CIF) using that python client.

Expected Behavior

I've got an alpha CIF plugin for threatbus written, but it doesn't appear to be getting any data, which makes me think the publisher for MISP perhaps isn't publishing like I would expect? I've been adding logger.debug statements everywhere to hopefully find where something isn't going right, but so far no luck.

Steps to reproduce

  1. docker-compose up -d
  2. docker-compose logs -f
  3. See just startup info
Attaching to threatbus
threatbus    | 2020-05-22 20:23:04 INFO     [threatbus] Starting plugins...
threatbus    | 2020-05-22 20:23:04 INFO     [threatbus_zeek.plugin] Broker: endpoint listening - localhost:47761
threatbus    | 2020-05-22 20:23:04 INFO     [threatbus_zeek.plugin] Zeek plugin started
threatbus    | WARNING [api.py:82 - __init__() ] The version of PyMISP recommended by the MISP instance (2.4.126) is newer than the one you're using now (2.4.125). Please upgrade PyMISP.
threatbus    | 2020-05-22 20:23:04 INFO     [threatbus_misp.plugin] MISP plugin started
threatbus    | 2020-05-22 20:23:04 INFO     [threatbus_inmem.plugin] In-memory backbone started.

Environment Context

  • Version: latest docker image
  • Compiler:
  • Operating System: host is Ubuntu 1804

Config.yaml

logging:
  console: true
  console_verbosity: DEBUG
  file: false
  file_verbosity: DEBUG
  filename: threatbus.log

plugins:
  apps:
    zeek:
      host: localhost
      port: 47761
      module_namespace: Tenzir
    misp:
      api:
        host: https://192.168.0.2:8006
        ssl: false
        key: <MISP_API_KEY>
      zmq:
        host: 192.168.0.2
        port: 50000

docker-compose.yml

version: '3.0'
services:
  threatbus:
    image: tenzir/threatbus:latest
    container_name: threatbus
    hostname: threatbus
    volumes:
      - ./config.yaml:/opt/tenzir/threatbus/config.yaml
    command: -c config.yaml

vielen Dank!

vast-threatbus: check for error code instead of checking stderr

When using an external command to transform a sighting context, the stderr output from the proc.communicate() call is checked and an error message is logged if that output is non-empty (https://github.com/tenzir/threatbus/blob/master/apps/vast/vast_threatbus/vast_threatbus.py#L579). However, this triggers an error message in vast-threatbus each time the external command outputs any log information on stderr. This is not uncommon and is not always a clear indication of an actual error. For example, I am calling a command that simply prints the location of its configuration file to stderr on startup.

I propose to use the returncode attribute that the communicate() call sets implicitly to check the returned error code of the external process and to use that information to trigger the error detection. This avoids spamming vast-threatbus's log with non-error messages.

Zeek Broker error (Broker::PEER_UNAVAILABLE): (invalid-node, *localhost:47760, "unable to connect to remote peer

Hello sir,
While solving the issue #82 I have encountered new issue. I have tried installing into fresh system. And reinstalled all the components again freshly. So here are the following conclusion I have reached till this point:
1- when I am compiling the threat bus and other tools like inmem, misp, zeek from the cloning the github, its not installing properly for some reasons. threatbus was stucking at :
2020-12-16 17:57:31 INFO [threatbus] Starting plugins...

2- What is working for me in that in "venv" envoirnment running the following command for installing threatbus and related utilities using:

pip install threatbus
pip install threatbus-inmem
pip install threatbus-misp
pip install threatbus-zeek

3- Seems like since the day zeek has been updated there is some issue started occurring between zeek and threatbus communication, because zeek version i am running is: 3.2.3

4- Threatbus misp communication is working fine for me.
So now the persistent issue is as shown in screenshot: (I will replace the API key later so didnt hide it here, once all fixed, atleast I hope so)
//Also tried with http://localhost
error in /opt/zeek/share/zeek/base/frameworks/broker/./log.zeek, line 80: Broker error (Broker::PEER_UNAVAILABLE): (invalid-node, *localhost:47760, "unable to connect to remote peer")

Screenshot from 2020-12-16 17-58-01

Sir, if my issue can be resolved, I will be very grateful to you.Thank you very much.

Kind Regards
Nillay

Plugin development

Hello,

i would like to develop an own Plugin for threatbus. In the description are links to a guide on how to write a plugin (https://docs.tenzir.com/threatbus/plugins/plugin-development) and different plugin types (https://docs.tenzir.com/threatbus/plugins/overview). Unfortunately both links are redirected to the main page of vast.io, where i am not able to find the guides. Are the guides now located anywhere else and I am unable to find them? If not would it be possible to still get access to the guides?

Thanks in advance

Kind regards

i cant subscribed topic

Observed Behavior

i have install threatbus threatbus-zeek threatbus-misp threatbus-inmem.
i can't subscribed to p2p_topic

  1. i don't have zmq on my centos. if i setup
    zmq:
    host: localhost
    port: 50000
    can it work?

  2. if i want to use kafka.
    kafka:
    topics:
    - misp_attribute
    poll_interval: 1.0
    config:
    bootstrap.servers: "x.x.x.x:9092"
    group.id: "threatbus"
    auto.offset.reset: "earliest"
    i get error : Kafka error: KafkaError{code=UNKNOWN_TOPIC_OR_PART,val=3,str="Subscribed topic not available: misp_attribute: Broker: Unknown topic or partition"}

Environment Context

zeek version 3.0.8
full config.yml:

logging:
console: true
console_verbosity: DEBUG
file: false
file_verbosity: DEBUG
filename: threatbus.log

plugins:
backbones:
inmem:

apps:
zeek:
host: "localhost"
port: 47761
module_namespace: Tenzir
misp:
api:
host: http://x.x.x.x
ssl: false
key: xxxxxxxxxxxxxxxxxxxx
zmq:
host: localhost
port: 50000
# kafka:
# topics:
# - misp_attribute
# poll_interval: 1.0
# config:
# bootstrap.servers: "x.x.x.x:9092"
# group.id: "threatbus"
# auto.offset.reset: "earliest"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.