Advertisement
betrayed

udp_amp_scanner.py

Apr 29th, 2024
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.26 KB | None | 0 0
  1. # Scanner for vulnerable UDP services that are subject to reflection/amplification DDoS attacks
  2. # This script supports both UDP and SYN stealth scans. Some UDP services accept or at least respond
  3. # to SYN requests, hence why it is included as an option in addition to generic UDP scans.
  4.  
  5. # So far I've found over a thousand vulnerable DNS, NTP, UBIQUITI, DVR, and WS-Discovry (WSD)
  6. # machines while using this tool.
  7.  
  8. # Known bugs: CTRL+C must be spammed a few times in order to abort your scan since I'm not a
  9. # master at python programming and the thread handling for this is garbage. Other than that,
  10. # you're set. Have fun crippling targets with your new lists.
  11.  
  12. # The script to generate IP addresses to scan will be posted following this tool. Stand by...
  13.  
  14.  
  15. import os, sys, time, socket
  16. from scapy.all import *
  17.  
  18. _abort = False
  19.  
  20. def main():
  21.     global _abort
  22.     os.system('clear')
  23.    
  24.     if len(sys.argv) != 6:
  25.         sys.exit('\r\n\033[1m\033[37m   USAGE: <IP-LIST.TXT> <OUTPUT.TXT> <TIMEOUT SEC> <WAIT SEC> <METHOD:SYN/UDP>')
  26.    
  27.     if not os.geteuid() == 0:
  28.         sys.exit('\r\n\033[1m\033[31m   SCRIPT REQUIRES ROOT ELEVATION!')
  29.  
  30.     if not (sys.argv[5].lower() == "udp" or sys.argv[5].lower() == "syn"):
  31.         sys.exit('\r\n\033[1m\033[31m ERROR! INVALID METHOD. EXITING...')
  32.  
  33.     print('''\033[1m\033[37m
  34.      █████╗   ███╗   ███╗  ██████╗        ███████╗   ██████╗ ██╗  ██╗
  35.    ██╔══██║  ████║▄████╔╝ ██╔══██║       ██╔═════╝  ██╔══██║ ██║ ██╔╝
  36.   ███████╔╝ ██╔████╔██╔╝ ███████╔╝█████╗███████╗   ██████╔═╝ ▀████╔╝
  37.  ██╔══██╔╝ ██╔╝██╔═██╔╝ ██╔═════╝ ╚════╝╚════██║  ██╔════╝    ██╔═╝
  38. ██╔╝ ██╔╝ ██╔╝ ╚═╝██╔╝ ██╔╝            ███████╔╝ ██╔╝        ██╔╝
  39. ╚═╝  ╚═╝  ╚═╝     ╚═╝  ╚═╝             ╚══════╝  ╚═╝         ╚═╝
  40. ''')
  41.  
  42.     _online = []
  43.     i = 0
  44.    
  45.     try:
  46.         with open(sys.argv[1], 'r') as f:
  47.             for line in f:
  48.                 if _abort == True:
  49.                     sys.exit("\033[1m\033[31m ABORTED BY USER...")
  50.                     break
  51.                 # retrieve IP:PORT
  52.                 try:
  53.                     _ip, _prt = line.strip().split(':')
  54.                 except:
  55.                     print('\033[1m\033[37m[{}]'.format(str(i)) + '\033[1m\033[34mANOMALY DETECTED @ LINE ENTRY "' + line + '"')
  56.  
  57.                 i +=1
  58.                 if sys.argv[5].lower() == "syn":
  59.                 #  ___ _   _ _ __  
  60.                 # / __| | | | '_ \
  61.                 # \__ \ |_| | | | |
  62.                 # |___/\__, |_| |_|
  63.                 #      |___/        
  64.                     try:
  65.                         response = sr1(IP(dst=_ip)/TCP(dport=int(_prt), flags="S"), timeout=int(sys.argv[3]), verbose=0)
  66.                         if response and response.haslayer(TCP):
  67.                             if response[TCP].flags == 0x12:
  68.                                 # open
  69.                                 print('\033[1m\033[37m[{}]'.format(str(i)) + '\033[1m\033[32m ------> OPEN @ ' + _ip + ':' + _prt)
  70.                                 success = _ip + ":" + _prt
  71.                                 _online.append(success)
  72.                             else:
  73.                                 # closed/filtered
  74.                                 print('\033[1m\033[37m[{}]'.format(str(i)) + '\033[1m\033[31m TIMEOUT @ ENDPOINT ' + _ip + ':' + _prt)
  75.                         else:
  76.                             print('\033[1m\033[37m[{}]'.format(str(i)) + '\033[22m\033[31m SYN/ACK NOT RECEIVED. REJECTED BY ENDPOINT ' + _ip + ':' + _prt)
  77.                     except KeyboardInterrupt:
  78.                         sys.exit()
  79.                     except:
  80.                         pass
  81.                    
  82.                 else:
  83.                 #            _      
  84.                 #  _   _  __| |_ __  
  85.                 # | | | |/ _` | '_ \
  86.                 # | |_| | (_| | |_) |
  87.                 #  \__,_|\__,_| .__/
  88.                 #             |_|  
  89.                     try:
  90.                         udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  91.                         udp_socket.settimeout(1)  # Set a timeout for the connection attempt
  92.                         udp_socket.sendto(b'', (_ip, int(_prt)))
  93.                         data, addr = udp_socket.recvfrom(1024)  # Receive response
  94.                         # open
  95.                         print('\033[1m\033[37m[{}]'.format(str(i)) + '\033[1m\033[32m ------> OPEN @ ' + _ip + ':' + _prt)
  96.                     except KeyboardInterrupt:
  97.                         sys.exit()
  98.                     except:
  99.                         print('\033[1m\033[37m[{}]'.format(str(i)) + '\033[22m\033[31m SYN/ACK NOT RECEIVED. REJECTED BY ENDPOINT ' + _ip + ':' + _prt)
  100.            
  101.     except KeyboardInterrupt:
  102.         # user abort via ctrl+c
  103.         _abort = True
  104.     except ValueError:
  105.         # malformed string formate
  106.         print('\033[1m\033[37m[{}]'.format(str(i)) + '\033[1m\033[34mANOMALY DETECTED @ LINE ENTRY "' + line + '"')
  107.     except:
  108.         # who knows lol
  109.         print('\033[1m\033[31mCRITICAL ERROR ENCOUNTERED!')
  110.    
  111.     # save all open ports to output file
  112.     print('\r\n\033[1m\033[37mDUMPING OPEN PORTS TO OUTPUT FILE. PLEASE STAND-BY...')
  113.     try:
  114.         with open(sys.argv[2], 'w') as file:
  115.             for item in _online:
  116.                 file.write(item + '\n')
  117.     except KeyboardInterrupt:
  118.         sys.exit()
  119.     except:
  120.         print('\033[1m\033[31mERROR ENCOUNTERED WHEN WRITING TO FILE!')
  121.    
  122.     # remove root file-attribute from output file
  123.     try:
  124.         current_mode = os.stat(sys.argv[2]).st_mode
  125.         new_mode = current_mode & ~0o4000
  126.         os.chmod(file_path, new_mode)
  127.     except:
  128.         pass
  129.  
  130.     sys.exit('\r\n\033[1m\033[37mJOB FINISHED.')
  131.          
  132. if __name__ == "__main__":
  133.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement