Skip to content

Instantly share code, notes, and snippets.

@zbetcheckin
Last active June 6, 2023 14:36
Show Gist options
  • Save zbetcheckin/617a380fe82fe86f1f3add27cfb48513 to your computer and use it in GitHub Desktop.
Save zbetcheckin/617a380fe82fe86f1f3add27cfb48513 to your computer and use it in GitHub Desktop.
Fun Python & Scapy script that will answer 'SYN ACK' to any TCP 'SYN' packet received on any port

Python - Scapy - Show all your ports as open

#!/usr/local/bin/python2
from scapy.all import *
os.system("iptables -A OUTPUT -p tcp -o eth0 --sport 1:65535 --tcp-flags RST RST -j DROP")
def packet(pkt):
    if pkt[TCP].flags == 2:
        print('SYN packet detected port : ' + str(pkt[TCP].sport) + ' from IP Src : ' + pkt[IP].src)
        send(IP(dst=pkt[IP].src, src=pkt[IP].dst)/TCP(dport=pkt[TCP].sport, sport=pkt[TCP].dport,ack=pkt[TCP].seq + 1, flags='SA'))
sniff(iface="eth0", prn=packet, filter="tcp[0xd]&18=2",count=100)
os.system("iptables -D OUTPUT -p tcp -o eth0 --sport 1:65535 --tcp-flags RST RST -j DROP")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment