Skip to content

Instantly share code, notes, and snippets.

@gdog2u
Forked from thepacketgeek/08-xmas-tree-packet.py
Last active September 22, 2023 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdog2u/e3850901a3a384d02429503f3c144c77 to your computer and use it in GitHub Desktop.
Save gdog2u/e3850901a3a384d02429503f3c144c77 to your computer and use it in GitHub Desktop.
Scapy - Creating a TCP Christmas Tree Packet
#!/usr/bin/python3
import sys
import warnings
from cryptography.utils import CryptographyDeprecationWarning
warnings.filterwarnings("ignore", category=CryptographyDeprecationWarning)
from scapy.all import IP,TCP,send
from random import randint
'''
X-mas Tree Packet Sender
A simply cli tool to send a set amount of x-mas tree packets to a specified
IP address. Useful for testing how a remote host will react to such odd
packets.
NOTE: For research purposes only. User is solely responsible for consequences
of using this script.
Forked from: https://gist.github.com/thepacketgeek/6919352
'''
def send_packets(dst_ip, packet_count):
# Create the skeleton of our packet
template = IP(dst=dst_ip)/TCP()
# Start lighting up those bits!
template[TCP].flags = "UFP"
# Create a list with a large number of packets to send
# Each packet will have a random TCP dest port for attack obfuscation
xmas = []
for pktNum in range(0,int(packet_count)):
xmas.extend(template)
xmas[pktNum][TCP].dport = randint(1,65535)
# Send the list of packets
try:
send(xmas)
except PermissionError:
print("Cannot access interface as current user. Please try running as root.")
except Exception as e:
print("Encountered unexpected error")
print(e)
def print_help():
print("usage: xmas-packet {ip} {packet count - optional}")
exit(0)
if __name__ == "__main__":
# Get the destination IP
try:
dst_ip = sys.argv[1]
except IndexError:
print_help()
if dst_ip == "-h" or dst_ip == "--help":
print_help()
# Set up how many packets to send
packet_count = 50
try:
packet_count = sys.argv[2]
except IndexError:
pass
# Output our settings
print("Destination ip:", dst_ip)
print("Packets to send:", packet_count)
# Send the packets
send_packets(dst_ip, packet_count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment