Skip to main content

Python Dnstap to JSON stream receiver

Project description

Dnstap to JSON stream receiver

License: MIT PyPI - Python Version

This Python module acts as a DNS tap receiver and streams as JSON payload to remote address or stdout.

Table of contents

Installation

Deploy the dnstap receiver in your DNS server with the pip command.

pip install dnstap_receiver

Show help usage

dnstap_receiver --help
usage: dnstap_receiver.py [-h] -u U -j J

optional arguments:
  -h, --help  show this help message and exit
  -u U        read dnstap payloads from unix socket
  -j J        write JSON payload to tcp/ip address 

Start dnstap receiver

The 'dnstap_receiver' binary takes in input a unix socket

dnstap_receiver -u /var/run/dnstap.sock

You can also add a remote tcp json collector to forward the log to another destination

dnstap_receiver -u /var/run/dnstap.sock -j 10.0.0.2:8192

Output JSON format

CLIENT_QUERY / FORWARDER_QUERY / RESOLVER_QUERY

{
    "message": "CLIENT_QUERY",
    "s_family": "IPv4",
    "s_proto": "TCP",
    "q_addr": "127.0.0.1",
    "q_port": 43935, 
    "dt_query": "2020-09-12 10:41:36.591",
    "q_name": "www.google.com.",
    "q_type": "A"
}

CLIENT_RESPONSE / FORWARDER_RESPONSE / RESOLVER_RESPONSE

{
    "r_code": "NOERROR",
    "port": 52782,
    "q_name":"rpc.gandi.net.",
    "s_family":"IPv4",
    "r_bytes": 47,
    "dt_reply": "2020-05-24 03:30:01.411",
    "q_addr": "10.0.0.235",
    "host": "10.0.0.97",
    "message": "CLIENT_RESPONSE",
    "q_type": "A",
    "s_proto": "UDP",
    "dt_query": "2020-05-24 03:30:01.376",
    "q_port": 40311,
    "q_time": 0.035
}

Systemd service file configuration

System service file for CentOS:

vim /etc/systemd/system/dnstap_receiver.service

[Unit]
Description=Python DNS tap Service
After=network.target

[Service]
ExecStart=/usr/local/bin/dnstap_receiver -u /etc/dnsdist/dnstap.sock -j 10.0.0.2:8192
Restart=on-abort
Type=simple
User=root

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start dnstap_receiver
systemctl status dnstap_receiver
systemctl enable dnstap_receiver

Tested DNS servers

This dnstap receiver has been tested with success with the following dns servers:

  • PowerDNS - dnsdist
  • NLnet Labs - unbound

dnsdist

dnsdist 1.4.0

The following file /etc/dnsdist/dnsdist.conf must be updated like below:

fsul = newFrameStreamUnixLogger("/var/run/dnstap.sock")
addAction(AllRule(), DnstapLogAction(fsul))
addResponseAction(AllRule(), DnstapLogResponseAction(fsul))

unbound

unbound 1.11.0

Unbound must build with dnstap support ./configure --enable-dnstap. The following file /etc/unbound/unbound.conf must be updated too:

dnstap:
    dnstap-enable: yes
    dnstap-socket-path: "dnstap.sock"
    dnstap-send-identity: yes
    dnstap-send-version: yes
    dnstap-log-resolver-query-messages: yes
    dnstap-log-resolver-response-messages: yes
    dnstap-log-client-query-messages: yes
    dnstap-log-client-response-messages: yes
    dnstap-log-forwarder-query-messages: yes
    dnstap-log-forwarder-response-messages: yes

Tested Logs Collectors

Logstash

vim /etc/logstash/conf.d/00-dnstap.conf

input {
  tcp {
      port => 8192
      codec => json
  }
}

filter {
  date {
     match => [ "dt_query" , "yyyy-MM-dd HH:mm:ss.SSS" ]
     target => "@timestamp"
  }
}

output {
   elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "dnstap-lb"
  }
}

About

Author Denis Machard d.machard@gmail.com
License MIT
PyPI https://pypi.org/project/dnstap_receiver/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnstap_receiver-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dnstap_receiver-0.2.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file dnstap_receiver-0.2.0.tar.gz.

File metadata

  • Download URL: dnstap_receiver-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for dnstap_receiver-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bbc8ede94b6109653762010ef016cc1a2f06f4c986f3277e4d3b725ebcd8fb1c
MD5 47f11c9946a243b906061517c50e11e5
BLAKE2b-256 c4335b970d9845e99ae19268dd0bc4f18b9aeaf73aaaa038b5e4ed8de6b14e50

See more details on using hashes here.

File details

Details for the file dnstap_receiver-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dnstap_receiver-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for dnstap_receiver-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8ec6a3a5848916eaa951506643c1ada0645b2de3cb4c8a84397d779732e136e
MD5 17ad9dcb32d1e3a24937217404a42691
BLAKE2b-256 c9f90824be70d1549ebfbbbed39d2739ea929644e30cbd3fddfd0cc696321189

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page