GithubHelp home page GithubHelp logo

secynic / nfsinkhole Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 3.0 137 KB

nfsinkhole is a Python library and scripts for setting up a Linux server as a sinkhole (monitor, log/capture, and drop all traffic to a secondary interface).

License: BSD 2-Clause "Simplified" License

Python 82.42% Makefile 5.98% Batchfile 5.69% HTML 0.16% Shell 5.75%
networking network iptables firewalld sinkhole linux syslog rsyslog syslog-ng tcpdump

nfsinkhole's Introduction

nfsinkhole

https://travis-ci.org/secynic/nfsinkhole.svg?branch=master https://coveralls.io/repos/github/secynic/nfsinkhole/badge.svg?branch=master&dummy=none

https://img.shields.io/badge/docs-release%20v0.1.0-green.svg?style=flat https://readthedocs.org/projects/pip/badge/?version=latest https://img.shields.io/badge/docs-dev-yellow.svg?style=flat

Summary

nfsinkhole is a Python library and scripts for setting up a Linux server as a sinkhole (monitor, log/capture, and drop all traffic to a secondary interface).

The default setup arguments monitor/capture all traffic. Setup arguments are provided to configure protocols, ports, rate limiting, logging, source IP/CIDR exclusions from logging, and optional packet capture.

All sinkhole events are written to /var/log/nfsinkhole-events.log. Optionally, you can enable tcpdump to output packet capture text to /var/log/nfsinkhole-pcap.log if your version of tcpdump supports packet printing; otherwise reverts to /var/log/nfsinkhole.pcap.

Warning

This version is considered experimental. Do not attempt to use this library in production until tests via travis and docker are setup, stable, and sufficiently covered.

Attention!

You are responsible for rotating log files (/var/log/nfsinkhole*), and syslog forwarding must be configured manually (automation pending).

Features

  • Simple install script
  • Installs as a init.d/systemctl service
  • Service modifies iptables on start/stop, no need to persist iptables
  • rsyslog and syslog-ng supported
  • RedHat/CentOS 6/7 tested
  • Python 2.6+ and 3.3+ supported
  • Built-in support for dealing with SELinux/AppArmor
  • Packet capture of sinkhole traffic (printed output to log for tcpdump v4.5+)
  • Useful set of utilities
  • Detailed logging to /var/log/nfsinkhole-*
  • Syslog forwarding configuration (pending)
  • BSD license

Planned Improvements

  • API/class documentation
  • Tests via travis-ci/docker
  • Exception handling overhaul
  • Set logging level (currently debug)
  • BIND/Microsoft/etc DNS server configuration documentation/examples
  • Monitoring use case examples
  • Automatic configuration for syslog forwarding
  • SIEM parsers/apps/plugins
  • Official support/testing for more OS environments
  • Support handling exceptions for HIPS and other endpoint security products
  • Intelligent handling/handshakes (inspired by iptrap - https://github.com/jedisct1/iptrap)

Links

Documentation

Release v0.1.0

https://nfsinkhole.readthedocs.io/en/v0.1.0

GitHub master

https://nfsinkhole.readthedocs.io/en/latest

GitHub dev

https://nfsinkhole.readthedocs.io/en/dev

Examples

Pending

Github

https://github.com/secynic/nfsinkhole

Pypi

https://pypi.python.org/pypi/nfsinkhole

Changes

https://nfsinkhole.readthedocs.io/en/latest/CHANGES.html

Dependencies

OS:

iptables (likely already included in base OS)
tcpdump (optional - likely already included in base OS)

Python 2.6:

argparse

Python 2.7, 3.3+:

None!

Installing

Attention!

The nfsinkhole service, iptables rules, and tcpdump must run as root. You can still use user/virtualenv Python environments, for the library, but ultimately, the core sinkhole will be run as root.

Note

Replace any below occurence of <INTERFACE> with the name of your sinkhole network interface name.

Base OS (pip) -- RECOMMENDED

If pip is not installed, you will first need to add the EPEL repo and install:

sudo yum install epel-release
sudo yum install python-pip

RHEL/CentOS 6/7

Basic:

pip install --user --upgrade nfsinkhole
python ~/.local/bin/nfsinkhole-setup.py --interface <INTERFACE> --install --pcap

virtualenv:

pip install virtualenv
virtualenv nfsinkhole
source nfsinkhole/bin/activate
nfsinkhole/bin/pip install nfsinkhole
nfsinkhole/bin/python nfsinkhole/bin/nfsinkhole-setup.py --interface <INTERFACE> --install --pcap

Base OS (no pip)

RHEL/CentOS 6

GitHub - Stable:

wget -O argparse.tar.gz https://github.com/ThomasWaldmann/argparse/tarball/master
tar -C argparse -zxvf argparse.tar.gz
cd argparse
python setup.py install --user prefix=
cd ..
rm -Rf argparse
wget -O nfsinkhole.tar.gz https://github.com/secynic/nfsinkhole/tarball/master
tar -C nfsinkhole -zxvf nfsinkhole.tar.gz
cd nfsinkhole
python setup.py install --user prefix=
cd ..
rm -Rf nfsinkhole
python ~/.local/bin/nfsinkhole-setup.py --interface <INTERFACE> --install --pcap

RHEL/CentOS 7

GitHub - Stable:

wget -O nfsinkhole.tar.gz https://github.com/secynic/nfsinkhole/tarball/master
tar -C nfsinkhole -zxvf nfsinkhole.tar.gz
cd nfsinkhole
python setup.py install --user prefix=
cd ..
rm -Rf nfsinkhole
python ~/.local/bin/nfsinkhole-setup.py --interface <INTERFACE> --install --pcap

Service

Once installed you need to start the nfsinkhole service.

RHEL/CentOS 6

sudo service nfsinkhole start

RHEL/CentOS 7

sudo systemctl start nfsinkhole.service

API

AppArmor

AppArmor documentation:

https://nfsinkhole.readthedocs.io/en/latest/apparmor.html

iptables

iptables documentation:

https://nfsinkhole.readthedocs.io/en/latest/iptables.html

rsyslog

rsyslog documentation:

https://nfsinkhole.readthedocs.io/en/latest/rsyslog.html

SELinux

SELinux documentation:

https://nfsinkhole.readthedocs.io/en/latest/selinux.html

Service

Service (systemd/init.d) documentation:

https://nfsinkhole.readthedocs.io/en/latest/service.html

syslog-ng

syslog-ng documentation:

https://nfsinkhole.readthedocs.io/en/latest/syslog_ng.html

tcpdump

tcpdump documentation:

https://nfsinkhole.readthedocs.io/en/latest/tcpdump.html

Utilities

Utilities documentation:

https://nfsinkhole.readthedocs.io/en/latest/utils.html

Contributing

https://nfsinkhole.readthedocs.io/en/latest/CONTRIBUTING.html

Special Thanks

Thank you JetBrains for the PyCharm open source support!

nfsinkhole's People

Contributors

secynic avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

nfsinkhole's Issues

Update travis

Update Travis build config for format changes and Python versions

Automatic configuration for syslog forwarding

Add argument during nfsinkhole-setup.py --install to set syslog forwarding (destination, protocol). Also add argument for which logs to send (/var/log/nfsinkhole-*.log -- 4 different files).

If your tcpdump doesn't support packet printing (< v4.5), nfsinkhole-pcap.log won't exist, and you won't be able to send the nfsinkhole.pcap file via syslog.

syslog-ng support

Finish syslog-ng logging and modify checks for both rsyslog and syslog-ng

Documentation

Using to track documentation improvements, and filling out the current .rst files that only contain "TODO".

Iron out docker tests

Docker tests are experimental, and run via the Travis tests for Python 2.7. What is needed:

  • More OS types/versions tested
  • Better tests (currently just makes sure that the rules/config are created correctly)
  • Re-evaluate how Travis handles the docker tests
  • Can I move the Python nosetests/coveralls to docker too?

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.