Python Port Knocking Script

Simple port knocking script using scapy because scapy is awesome and I’ll take any opportunity to use it. Also, Python lives on all of my devices, so I can use one tool across all of them. I found a script here that I then modified to suit my needs. The author, snj, seems to have made it for a CTF or something similar, so there was a lot there that I did not need.

Right now the IP and port numbers are hard-coded in. In the future, we could improve the script by getting them from arguments. Additionally, importing everything from scapy takes forever. The biggest improvement would be to either not use scapy, or figure out what, specifically, we need from scapy, and import only those things.



from scapy.all import *
import time

def knock(ports):
    print "[*] Knocking on ports "+str(ports)
    for dport in range(0, len(ports)):
        ip = IP(dst = "")
        SYN = ip/TCP(dport=ports[dport], flags="S", window=14600, options=[('MSS',1460)])

def execKnock(ports):
    print "Port opened"
    print "Port closed"

oports = [7303,40303,33528]
cports = [33528,40303,7303]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.