#!/usr/bin/env python
# -*- coding: utf-8 -*-"
"""
UFONet - (DDoS botnet + DoS tool) via Web Abuse - 2013/2014/2015/2016/2017/2018 - by psy (epsylon@riseup.net)
You should have received a copy of the GNU General Public License along
with UFONet; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
import socket, threading, logging, datetime
import zombie
import sys, os, re
from urlparse import urlparse
# zombie tracking class
class Herd(object):
# basic constructor
def __init__(self,ufonet):
super(Herd, self).__init__()
self.ufonet=ufonet
self.reset()
self.total_connections=0
self.total_hits=0
self.total_fails=0
self.total_time=0
self.total_size=0
self.total_connection_fails=0
self.living=threading.active_count()
self.stats={}
self.zombies_ready = []
# property setup
def reset(self):
self.active = []
self.done = []
self.lock = threading.Lock()
self.result={}
self.connection={}
# clean temporary statistic files
def cleanup(self):
try:
if os.path.exists("/tmp/ufonet.html"):
os.remove("/tmp/ufonet.html")
if os.path.exists("/tmp/ufonet.html.tmp"):
os.remove("/tmp/ufonet.html.tmp")
except:
pass
# got a new one !
def new_zombie(self, zombie):
self.total_connections+=1
if zombie not in self.stats:
self.stats[zombie]=[]
with self.lock:
self.active.append(zombie)
# give me your report & byebye
def kill_zombie(self, zombie, result, connection_failed):
with self.lock:
try:
self.result[zombie]=str(result)
self.connection[zombie]=connection_failed
self.done.append(zombie)
if result[0]==200 :
self.total_hits+=1
else:
self.total_fails+=1
if connection_failed:
self.total_connection_fails+=1
self.active.remove(zombie)
self.total_time+=result[1]
self.total_size+=result[2]
if zombie in self.stats:
self.stats[zombie].append(result)
else:
pass
except:
pass
# head count (+/- headless zombies)
# active thread count = 1 principal + 1/zombie
def no_more_zombies(self):
ac=threading.active_count()
options = self.ufonet.options
if options.verbose == True:
if ac>self.living:
print "[Control] Active zombies:", ac-self.living, ", waiting for them to return..."
else:
print "="*41
print "\n[Control] All zombies returned to the master ;-)"
print "-"*21
with self.lock:
return ac==self.living
# retrieve result by zombie name
def get_result(self,zombie):
return self.result[zombie] or False
# retrieve connection status by zombie name
def connection_failed(self,zombie):
return self.connection[zombie] or False
# retrieve size on correct format
def sizeof_fmt(self, size, suffix='B'):
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(size) < 1024.0:
return "%3.1f%s%s" % (size, unit, suffix)
size /= 1024.0
return "%.1f%s%s" % (size, 'Yi', suffix)
# generate html statistics
def dump_html(self,final=False):
buf=""
out=self.get_stat()
if os.path.exists("/tmp/ufonet.html.tmp"):
print 'tmp file found, html output abort !!!'
return
buf += "
" + os.linesep
if out['err'] is not None:
buf += "
"
if len(out['data'])==0:
buf += "waiting..."
for l in out["data"] :
hits=''+str(out['data'][l]['hits'])+''
fails=str(out['data'][l]['fails'])
buf += ""+os.linesep
buf += "