Skip to content

Instantly share code, notes, and snippets.

@byt3bl33d3r
Last active February 21, 2020 19:41
Show Gist options
  • Save byt3bl33d3r/4d7a803c69d6491ce641 to your computer and use it in GitHub Desktop.
Save byt3bl33d3r/4d7a803c69d6491ce641 to your computer and use it in GitHub Desktop.
Simple packet manipulation with fqrouter's fork of python-netfilterqueue (https://github.com/fqrouter/python-netfilterqueue)
#! /usr/bin/env python2.7
from scapy.all import *
from netfilterqueue import NetfilterQueue
def modify(packet):
pkt = IP(packet.get_payload()) #converts the raw packet to a scapy compatible string
#modify the packet all you want here
packet.set_payload(str(pkt)) #set the packet content to our modified version
packet.accept() #accept the packet
nfqueue = NetfilterQueue()
#1 is the iptabels rule queue number, modify is the callback function
nfqueue.bind(1, modify)
try:
print "[*] waiting for data"
nfqueue.run()
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment