#/usr/bin/python import os,sys import nfqueue from scapy.all import * import socket class MyQueue: def __init__(self): self.q = nfqueue.queue() def process(self, i, payload): data = payload.get_data() p = IP(data) #SYN-ACK if not p[TCP].flags == 18: return 0 print "Crafting Fake ACK" fake = IP(src=p[IP].dst, dst=p[IP].src)/TCP(sport=p[TCP].dport, dport=p[TCP].sport, flags="A", seq=p[TCP].ack+1, ack=p[TCP].seq+2) print "Sending..." send(fake) #Accept the final SYN-ACK print "Accepting real ACK" payload.set_verdict(nfqueue.NF_ACCEPT) def main(self): self.q.open() self.q.bind(socket.AF_INET) self.q.set_callback(self.process) self.q.create_queue(0) try: self.q.try_run() except KeyboardInterrupt: print "Exiting..." self.q.unbind(socket.AF_INET) self.q.close() sys.exit(1) MyQueue().main()