All Projects → milesrichardson → docker-nfqueue-scapy

milesrichardson / docker-nfqueue-scapy

Licence: other
Docker container for intercepting packets with scapy from a netfilter queue (nfqueue)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to docker-nfqueue-scapy

DrawBridge
Layer 4 Single Packet Authentication Linux kernel module utilizing Netfilter hooks and kernel supported Berkeley Packet Filters (BPF)
Stars: ✭ 81 (+3.85%)
Mutual labels:  iptables, netfilter
nDPI
Open Source Deep Packet Inspection Software Toolkit
Stars: ✭ 92 (+17.95%)
Mutual labels:  iptables, netfilter
go-nfqueue
c-binding free API for golang to communicate with the queue subsystem of netfilter
Stars: ✭ 37 (-52.56%)
Mutual labels:  netfilter, nfqueue
uppersafe-osfw
UPPERSAFE Open Source Firewall
Stars: ✭ 21 (-73.08%)
Mutual labels:  iptables, netfilter
xegtor
Xegtor - Network Attack & Scanning Tool for Red Teaming and Ethical Hacking
Stars: ✭ 19 (-75.64%)
Mutual labels:  scapy
dog
A firewall management system.
Stars: ✭ 67 (-14.1%)
Mutual labels:  iptables
k8s-custom-iptables
How to add custom iptables rules to a Kubernetes cluster
Stars: ✭ 52 (-33.33%)
Mutual labels:  iptables
dhcpcanon
DHCP client disclosing less identifying information.
Stars: ✭ 58 (-25.64%)
Mutual labels:  scapy
WireBirb
A scapy based module for programming offensive and defensive networking tools easier than before.
Stars: ✭ 16 (-79.49%)
Mutual labels:  scapy
ddos-mitigation
Tips to mitigate and secure your large-scale server against DDoS attacks.
Stars: ✭ 58 (-25.64%)
Mutual labels:  iptables
netfilter
Pure-Go Netfilter Netlink family implementation.
Stars: ✭ 51 (-34.62%)
Mutual labels:  netfilter
RogueAP-Detector
Rogue Access Point Detector
Stars: ✭ 28 (-64.1%)
Mutual labels:  scapy
go-ipset
🔥 Go bindings for the IPtables ipset http://ipset.netfilter.org userspace utility
Stars: ✭ 110 (+41.03%)
Mutual labels:  iptables
Mignis
Mignis is a semantic based tool for firewall configuration.
Stars: ✭ 43 (-44.87%)
Mutual labels:  iptables
blackip
IP Blocklist for Ipset / Squid-Cache
Stars: ✭ 81 (+3.85%)
Mutual labels:  iptables
http-request-capture
A simple tool for capturing http requests.
Stars: ✭ 18 (-76.92%)
Mutual labels:  scapy
xt NAT
Full Cone NAT module for Linux iptables
Stars: ✭ 65 (-16.67%)
Mutual labels:  iptables
DoNotSend
Sending messages by hacking the DNS protocol. See website for demo server usage instructions
Stars: ✭ 93 (+19.23%)
Mutual labels:  scapy
UnboundBL
🛑 DNSBL (adblock) on OPNsense with UnboundBL & Unbound DNS
Stars: ✭ 63 (-19.23%)
Mutual labels:  iptables
awesome-scapy
Great packages that use Scapy
Stars: ✭ 101 (+29.49%)
Mutual labels:  scapy

docker-nfqueue-scapy

Docker container with an example python script to listen for packets on a netfilter queue and manipulate them with scapy. You can listen on any queue number, and you can push packets into the queue from any iptables rule. This container gives you a powerful prototyping and debugging tool for monitoring, manipulating, dropping, accepting, requeing, or forwarding network packets in python. You can read from a queue on the host with --net=host --cap-add=NET_ADMIN. Or, you can run it within another container's namespace to listen for packets on an nfqueue in that container's network namespace.

This container includes a full installation of scapy and python netfilter queue (nfqueue) bindings, and an example python script nfqueue_listener.py to print incoming packets on the queue.

scapy: https://github.com/secdev/scapy python-netfilterqueue: https://github.com/kti/python-netfilterqueue

How to use

Clone this repository

git clone [email protected]:milesrichardson/docker-nfqueue-scapy.git

Build the docker container. This will take a while because it includes the full scapy install and all its dependencies. You can use any tag you want, but as an example here I'm using nfqueuelistener

cd docker-nfqueue-scapy
sudo docker build . -t nfqueuelistener

(Example)

Use iptables on the host to send TCP packets destined for port 9001 to nfqueue 1:

sudo iptables -t raw \
              -A PREROUTING \
              -p tcp --destination-port 9001 \
              -j NFQUEUE --queue-num 1

Run the docker container to listen for packets and print then accept any received packets.

sudo docker run -it --rm \
                --cap-add=NET_ADMIN \
                --net=host \
                --name=nfqueuelistener nfqueuelistener

From another machine, send some packets to test:

echo "Hello" | nc -v $HOST_IP_ADDRESS 9001

You should see something like this:

miles@box:~/testing$ sudo docker run -it --rm --cap-add=NET_ADMIN --net=host --name=nfqueuelistener nfqueuelistener
Listening on NFQUEUE queue-num 1...
<IP  version=4L ihl=5L tos=0x0 len=64 id=6387 flags=DF frag=0L ttl=55 proto=tcp chksum=0x6850 src=11.22.33.44 dst=44.55.66.77 options=[] |<TCP  sport=58164 dport=9001 seq=4038873318 ack=0 dataofs=11L reserved=0L flags=S window=65535 chksum=0x67be urgptr=0 options=[('MSS', 1452), ('NOP', None), ('WScale', 5), ('NOP', None), ('NOP', None), ('Timestamp', (2615879909, 0)), ('SAckOK', ''), ('EOL', None)] |>>

Setting the queue number

The default queue number is 1. You can override this by setting the environment variable QUEUE_NUM when running the container. For example, for queue 2:

sudo docker run -it --rm \
                -e 'QUEUE_NUM=2' \
                --cap-add=NET_ADMIN \
                --net=host \
                --name=nfqueuelistener nfqueuelistener

Editing the nfqueue_listener.py file

One way to edit the nfqueue_listener.py file is to simply edit it and then rebuild the container with sudo docker build . -t nfqueuelistener. Since you are only editing the python file, building will not take as long as the first build.

You can find the documentation for the nfqueue library used at https://github.com/kti/python-netfilterqueue

Listening in another container's namespace

I have not tested this, but it should work.

Say you have another container $CONTAINER_ID and you want to intercept incoming packets in its namespace. You can run this docker container like:

sudo docker run -it --rm \
                --net=container:$CONTAINER_ID \
                --name=nfqueuelistener nfqueuelistener

Note that you will need to run your iptables rules to send packets to the queue from within the $CONTAINER_ID container.

Other notes

scapy is hardcoded version 2.3.2 because there is a bug in 2.3.3 causing scapy to fail on openstack deployments. The bug is actually upstream in openstack, and has been fixed, but this caused problems for me testing on packet.net where they have apparently not updated openstack yet.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].