zisong

Netool v2

Nov 16th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 23.73 KB | None | 0 0
  1. try:
  2. #────────────────────────────────────────────────────────────────────────────────────────────────────────────
  3.     import os,sys
  4.     from datetime import datetime
  5.     from time import time, strftime,gmtime
  6.    
  7.     import argparse
  8.     from argparse import RawTextHelpFormatter
  9.    
  10.     from socket import socket, AF_INET, SOCK_STREAM, SOCK_DGRAM, gethostbyname,getaddrinfo,gethostbyaddr,gethostbyaddr
  11.     import requests,lxml
  12.    
  13.     from bs4 import BeautifulSoup
  14.     from googlesearch import search
  15.    
  16.     import urllib3
  17.     import urllib3.request
  18.     import urlparse3
  19.  
  20.     import base64
  21.  
  22.     from ipwhois import IPWhois
  23.     import warnings
  24.  
  25.  
  26.     func_dicts = {
  27.         'ports':'get_OpenPorts',
  28.         'links':"get_Links",
  29.         'robots':'get_Robots',
  30.         'search':'get_Dorks',
  31.         'scrap':'get_Sources',
  32.         'sitemap':'get_SitemapXML',
  33.         'sql':'check_SQLInjection',
  34.         'admin':'check_AdminLogin',
  35.         'ipLookup':'ip_Lookup'
  36.         }
  37.     d1 = list(func_dicts)
  38. #────────────────────────────────────────────────────────────────────────────────────────────────────────────
  39.     def get_OpenPorts(c,t,m): # -----------------------------[     OPEN PORTS      ]--------------------
  40.         port_dict = {
  41.             20:'FTP (default data channel)',    21:'FTP (control channel)',                         23:'Telnet',
  42.             43:'Whois',                         53:'Domain Name System',                            67:'Bootp server',
  43.             68:'Bootp client',                  69:'Trivial FTP',                                   70:'Gopher',                        
  44.             80:'HYPERTEXT TRANSFER PROTOCOL',   88:'Kerberos',                                      109:'POP-2 (Post Office Protocol)',
  45.             110:'POP-3',                        119:'NNTP (Network News Transfer Protocol)',        123:'NTP (Network Time Protocol)',  
  46.             135:'NT RPC endpoint mapper',       137:'NetBIOS Name Service',                         138:'NetBIOS Datagram Service',    
  47.             139:'NetBIOS Session Service',      143:'IMAP (Internet Message Access Protocol)',      161:'SNMP',                        
  48.             162:'SNMP Trap',                    179:'BGP (Border Gateway Protocol)',                194:'IRC (Internet Relay Chat)',    
  49.             216:'Computer Associates License',  256:'Checkpoint Firewall Management',               257:'Checkpoint Firewall Log Management',
  50.             258:'CheckP Firewall Management',   259:'Checkpoint VPN-1 FWZ Key Management',          260:'Checkpoint Alternate SNMP',
  51.             261:'CheckP Firewall Management',   264:'Checkpoint Firewall Topology Download',        265:'Checkpoint VPN-1 Public Key Transfer Protocol',
  52.             270:'Microsoft Operations Manager ',389:'LDAP (Lightweight Directory Access Protocol)', 443:'HTTP over SSL',                
  53.             444:'SNPP(Network Paging Protocol)',500:'IKE (IPSEC Internet Key Exchange)',            520:'Routing Information Protocol',
  54.             524:'Netware Core Protocol',        543:'Kerberos Login',              
  55.             544:'Kerberos Shell',               563:'NNTPS (Secure NNTP)',                          599:'HTTP RPC Endpoint ',
  56.             1080:'SOCKS Proxy',                 1081:'SOCKS Proxy alternate',                       1214:'Kazaa Network',
  57.             1241:'Nessus',                      1433:'Microsoft SQL Server',                        1434:'Microsoft SQL MonitorService',
  58.             1494:'Citrix',                      1498:'Sybase',                                      1521:'Oracle TNS Listener',
  59.             1723:'Point-to-Point Tunneling Protocol (PPTP)',                                        1745:'Winsock-proxy',
  60.             2000:'Remotely Anywhere',           2001:'Cisco device management, Remotely Anywhere',  2301:'Compaq Insight Manager',
  61.             2381:'Secure Cpq Insight Manager',  3389:'Terminal Services',                           4001:'Cisco device management',
  62.             5631:'PC Anywhere'
  63.             }
  64.  
  65.         port_len = len(port_dict)
  66.         ports_range  = list(port_dict.keys())    
  67.  
  68.         try:
  69.             _adress = str(c)
  70.             _timeout = int(t)
  71.             _range = ports_range
  72.  
  73.             ip = gethostbyname(_adress)
  74.  
  75.             startTime = time()
  76.             print('''[!] Starting Port scan ({1}) \nPort scan report for ({0})'''.format(ip,datetime.now()))
  77.  
  78.             print("{0:<10} {1:<10} SERVICE".format("PORT","STATE"))
  79.  
  80.             for i in range(port_len):
  81.                 sock = socket(AF_INET, SOCK_STREAM) #OPEN TCP SOCKET
  82.                 sock.settimeout(_timeout)
  83.                 port = _range[i]
  84.                 if sock.connect_ex((ip, port)) == 0:                    
  85.                     print("{0:<10} {1:<10} {2}".format(port,"open",port_dict[port]))
  86.  
  87.                 sock.close() #CLOSE SOCKET
  88.             endTime  = time()
  89.  
  90.             elapsedTime = endTime-startTime
  91.             finalTime = strftime("%Hh:%Mm:%Ss", gmtime(elapsedTime))
  92.             print("[*] done: 1 IP address ({0}) scanned in {1}".format(ip,finalTime))
  93.         except Exception as error:
  94.             print(error,"critical")
  95.     def host_by_name (address):
  96.         try: return gethostbyname(address.split("www.")[1])
  97.         except:pass
  98.         try: return gethostbyname("https://%s"%address)
  99.         except:pass
  100.         try: return gethostbyname("www.%s"%address)
  101.         except:pass
  102.         try:
  103.             return gethostbyname("http://www.%s"%address)
  104.         except Exception as error:
  105.             print(error)
  106.    
  107.     def ip_Lookup (c,t,max): # ------------------------------[     IP LOOKUP       ]--------------------
  108.         with warnings.catch_warnings():
  109.             warnings.filterwarnings("ignore",category=UserWarning)
  110.             ip = str(c)
  111.            
  112.             add = host_by_name(ip)
  113.  
  114.             obj = IPWhois(add,5)
  115.             res = obj.lookup_whois()
  116.  
  117.             print("\n")
  118.             print("IP Lookup results for '{0}' [{1}]".format(ip,add))
  119.             for els in res:                                                 #GET OBJ RESULT
  120.                 val = "{0}".format(els)
  121.                 res_els = res[val]
  122.                 if res_els is not None:                                     #IF ACTUAL OBJECT HAVE CONTENT
  123.                     if val == 'nets':
  124.                         nets_D = res_els[0]
  125.                         for k in nets_D:                                    #GET KEYS OF DICTS TO VIEW CONTENT
  126.                             content = nets_D.get(k)
  127.                             result = "{0:<20} {1}".format(k,content)
  128.                             print(result)                                   #RESULTS OF NETS INFORMATIONS
  129.                     else:                                                   #GET CONTENT IF IS NOT DICT
  130.                         result = "{0:<20} {1}".format(els,res_els)
  131.                         print(result)                                       #RESULTS OF COMMOM INFORMATIONS
  132.             print("\n")
  133.     def get_Links (c,t,max): # ------------------------------[       LINKS         ]--------------------
  134.         _adress = str(c)
  135.         url = str(_adress)
  136.  
  137.         r = ""
  138.         try:
  139.             try:r = requests.get(url)
  140.             except:pass
  141.             try:r = requests.get("http://{0}".format(url))
  142.             except:pass
  143.             try:r = requests.get("https://{0}".format(url))
  144.             except:pass
  145.            
  146.             data = r.text
  147.             soup = BeautifulSoup(data, "lxml")
  148.  
  149.             for link in soup.find_all("a"):
  150.                 f_link = link.get('href')
  151.                 print(f_link)
  152.         except Exception as error:
  153.             print("{0}\nFile: {1}".format(error,os.path.basename(__file__)),"critical")      
  154.     def get_Robots (c,t,max): # -----------------------------[       ROBOTS        ]--------------------
  155.         http=True
  156.         https=True
  157.         wtp=True
  158.         adress = c
  159.         try:
  160.             rContent = " NULL "
  161.             try:
  162.                 rurl = '{0}/robots.txt'.format(adress)
  163.                 r = requests.get(rurl)
  164.                 rContent = r.text
  165.             except Exception as error:
  166.                 wtp=False
  167.                 pass
  168.  
  169.             try:
  170.                 rurl = 'http://{0}/robots.txt'.format(adress)
  171.                 r = requests.get(rurl)
  172.                 rContent = r.text
  173.             except Exception as error:
  174.                 http= False
  175.                 pass
  176.  
  177.             try:
  178.                 rurl = 'https://{0}/robots.txt'.format(adress)
  179.                 r = requests.get(rurl)
  180.                 rContent = r.text
  181.             except Exception as error:
  182.                 https=False
  183.  
  184.             print("-"*100)
  185.             print(rContent)
  186.             print("-"*100)
  187.  
  188.         except Exception as error:
  189.             print(error)
  190.  
  191.         print('''\nRobots open with following protocols
  192.     http://{site}       → {0}
  193.     https://{site}      → {1}
  194.     {site}              → {2}'''.format(http,https,wtp,site=adress))
  195.     def get_Dorks (c,t,max): # ------------------------------[       DORKS         ]--------------------
  196.         text = str(c)
  197.         print("Searching {m} results for '{0}'.. \nmaybe this take a bit longer to complete".format(text,m=max),"alert")
  198.         links = []
  199.         maxLinks = 0
  200.         try:
  201.             results = search(str(text),stop=int(max))
  202.             for urls in results:
  203.                 print(urls)
  204.                 # links.append("{0}".format(urls))
  205.                 maxLinks = maxLinks+1
  206.         except Exception as error:
  207.             print(error)
  208.         finally:
  209.             for i in links:
  210.                 print(i)
  211.             print("done!! {0} links found".format(maxLinks))
  212.     def get_Sources (c,t,max): # ----------------------------[ SOURCE CODE (SCRAP) ]--------------------
  213.         print(c)
  214.         _adress = str(c)
  215.         url = str(_adress)
  216.         r = ""
  217.  
  218.         try:
  219.             try:    r = requests.get(url)
  220.             except: pass
  221.             try:    r = requests.get("http://{0}".format(url))
  222.             except: pass                
  223.             try:    r = requests.get("https://{0}".format(url))
  224.             except: pass
  225.         except Exception as error:
  226.             print("{0}\n\nFile: {1}".format(error,os.path.basename(__file__)),"critical")
  227.        
  228.         data = r.text
  229.         print("\n\n{0}\n\n".format(data))
  230. #────────────────────────────────────────────────────────────────────────────────────────────────────────────
  231.     def getRequests (c):    # ---------- SUB FUNCTION XMLMAP 1 -----------
  232.         try:
  233.             get_url = requests.get(str("http://{0}/sitemap.xml".format(c)))
  234.             return get_url    
  235.         except:pass
  236.         try:
  237.             get_url = requests.get(str("https://{0}/sitemap.xml".format(c)))
  238.             return get_url
  239.         except:pass
  240.         try:
  241.             get_url = requests.get("{0}/sitemap.xml".format(c))
  242.             return get_url
  243.         except:pass
  244.     def xmlMapString (c):   # ---------- SUB FUNCTION XMLMAP 2 -----------
  245.         try:
  246.             get_url = getRequests(c)
  247.  
  248.             if get_url.status_code == 200:
  249.                 return get_url.text
  250.             else:
  251.                 print("Unable to fetch sitemap: %s ." % c)
  252.  
  253.         except Exception as error:
  254.             print(error)
  255.     def processSitemap (c): # ---------- SUB FUNCTION XMLMAP 3 -----------
  256.         sitemapText = xmlMapString(c)
  257.         soup = BeautifulSoup(sitemapText,'lxml')
  258.         results = []
  259.  
  260.         for loc in soup.find_all('loc'):
  261.             results.append(loc.text)
  262.         return results
  263.     def get_SitemapXML (c,t,max):#---------------------------[     SITEMAP  XML    ]--------------------
  264.         print("[!] Trying to request '/sitemap.xlm' wait until process complete.")
  265.         sitemapLinks = processSitemap(c)
  266.         lines = 0
  267.        
  268.         for l in range(len(sitemapLinks)):
  269.             print(sitemapLinks[l])
  270.             lines = lines+1
  271.         print("[!] done {0} links found in '{1}/sitemap.xml'".format(lines,c),"\n")
  272. #────────────────────────────────────────────────────────────────────────────────────────────────────────────
  273.     def check_SQLInjection(c,t,max): # ----------------------[    SQL INJECTION    ]--------------------
  274.         url = c
  275.         print("FINISHED SCAN")
  276.     def requestSiteContent (c):
  277.         try:
  278.             get_url = requests.get(str("http://{0}".format(c)))
  279.             return get_url.text
  280.         except:pass
  281.         try:
  282.             get_url = requests.get(str("https://{0}".format(c)))
  283.             return get_url.text
  284.         except:pass
  285.         try:
  286.             get_url = requests.get("{0}".format(c))
  287.             return get_url.text
  288.         except:pass
  289.     def check_AdminLogin (c,t,max):  # ----------------------[    ADMIN BRUTEFORCE ]--------------------
  290.         print("[!] Testing login with 420 words [04m:20s to test all words]")
  291.         link = str(c)
  292.         startTime = time()
  293.  
  294.         try:
  295.             try:
  296.                 urlGit = "raw.githubusercontent.com/zisongbr/Network-Tools/master/admin_wordlist.txt"
  297.                 req = str(requestSiteContent(urlGit))
  298.                 rcontent = req.split('\n')
  299.                
  300.                 for i in range(len(rcontent)):
  301.                     adLink = '{0}/{1}'.format(link,rcontent[i])
  302.                    
  303.                     try:adReq = requests.get('https://'+adLink)
  304.                     except:pass
  305.                     try:adReq = requests.get('http://'+adLink)
  306.                     except:pass
  307.                     try:adReq = requests.get(adLink)
  308.                     except:pass
  309.                    
  310.                     if adReq.status_code == 200:
  311.                         print("[*] login found → [%s] \n" %adLink)
  312.                         break
  313.                     else:
  314.                         print(adLink)
  315.  
  316.                 endTime  = time()
  317.                 elapsedTime = endTime-startTime
  318.                 finalTime = strftime("%Hh:%Mm:%Ss", gmtime(elapsedTime))
  319.                 print("[!] done!!, its take '{0}'".format(finalTime))
  320.  
  321.             except Exception as error:
  322.                 print(error)
  323.         except KeyboardInterrupt:
  324.             print("[!!!] [Ctrl+C] SCAN CANCELED BY spUSER")
  325. #────────────────────────────────────────────────────────────────────────────────────────────────────────────
  326.     def get_all_info(f):
  327.         dorks_url = 'raw.githubusercontent.com/zisongbr/Network-Tools/master/dorks.txt'
  328.         tmp_dorks = requestSiteContent(dorks_url)
  329.         dorkslist = list(tmp_dorks.split('\n'))
  330.     # ------ [DETAILED HELP PANEL '-info'] ---------
  331.         h_dict = {
  332.     #----- ADMIN --------------------
  333.         'admin':'''
  334.        Usage:
  335.        -f admin -in www.site.com -t 1
  336.  
  337.        Function Requeriments:
  338.        -in  -> site url to search for login page that is www.site.com to generate www.site.com/login.php
  339.        -t   -> connection timeout
  340.        ''',
  341.     #------ PORTS -----------------
  342.         'ports':'''
  343.        Usage:
  344.        -f ports -in www.site.com -t 1
  345.  
  346.        Function Requeriments:
  347.        -in  -> site to scan for open ports
  348.        -t   -> timeout betwen ports
  349.  
  350.        ''',
  351.     #------ SEARCH ---------------
  352.         'search':'''
  353.        Usage:
  354.        -f search -in inurl:login.php -max 10
  355.  
  356.        Function Requeriments:
  357.        -in  -> inurl dork or any other search results
  358.        -max -> Number of results to search for
  359.  
  360.        Real dorks examples:
  361.        -in view_items.asp?id=
  362.        -max 50
  363.  
  364.        [?] to see all available dorks
  365.        
  366.        search for dork wordlist                        > '-info dork_list'
  367.        view Advanced Operators of google dork search   > '-info adv_operators'
  368.        
  369.        '''
  370.         }
  371.    
  372.         dork_advOpt = '''    
  373.        Operator:      Purpose:                         Example:
  374.        intitle:       Search page title                ' Admin login'
  375.        allintitle:    Search page title                ' Admin login'
  376.        inurl:         Search URL                       ' addToCart.php?idProduct= / admin.php / users.php'
  377.        allinurl:      Search URL                       ' admin.php / users.php'
  378.        filetype:      Search specific files            ' .php / .txt / .xlcs / .html'
  379.        allintext:     Search text of page only         ' Admin directory / MySQL syntax error'
  380.        site:          Search specific site             ' SpecificSiteDomain'
  381.        link:          Search for links to pages        ' Admin/Login.php'
  382.        inanchor:      Search link anchor text          ' Dorks list / Leaked documents'
  383.        daterange:     Search in date range             ' 1 / 9 / 80'
  384.        numrange:      Locate number                    ' 1944 / 2018 / "29/10/2018"'
  385.        author:        Group author search              ' H.P Lovecraft / Eduardo Sphor'
  386.        group:         Group name search                ' Hacking / Health Care'
  387.        insubject:     Group subject search             ' Best seller '
  388.        msgid:         Group msgid search"              ' 10 / 90 / 99 / 101 / x  '
  389.  
  390.        [?] To use more than one operator try:
  391.            -f search -in "inurl:users_acess filetype:.php OR filetype:.html intitle:Users informations"
  392.            -f serach -in="inurl:passwords filetype:.txt or filetype:.php"
  393.        '''
  394.        
  395.         dorks_example = '''
  396.        Inurl Examples:
  397.            addcart.php?
  398.            addItem.php
  399.            add-to-cart.php?ID=
  400.        Usage:
  401.        -f search -in 'OPERATOR':DORK
  402.        -f serach -in
  403.        
  404.        '''
  405.  
  406.         cmd_info = ["dork_list","adv_operators","dork_examples"]
  407.  
  408.         if f == cmd_info[0]:
  409.             for line in range(len(dorkslist)):
  410.                 print(dorkslist[line])
  411.         if f == cmd_info[1]:
  412.             print(dork_advOpt)
  413.         if f == cmd_info[2]:
  414.             print()
  415.         if f not in cmd_info:
  416.             print(h_dict[str(f)])
  417. #────────────────────────────────────────────────────────────────────────────────────────────────────────────
  418.     if __name__ == "__main__":
  419.     # APP DESCRIP AND EPILOG
  420.         desc = '''
  421.    [?] This software provides a number of features for probing computer networks,
  422.    including host discovery and operating-system detection. These features are
  423.    extensible by one simple script that provide more advanced service detection,
  424.    vulnerability detection, and various others features.
  425.  
  426.    [!] legal disclaimer:
  427.    Usage of this program to cause problems to third parties is not permited by developer,
  428.    educational purposees only. I do not assume any responsibilities for damages caused by this program
  429.  
  430.    The source code is provided with this software because we believe that users have the right to
  431.    know exactly what a program will do before you run it.
  432.    This also allows you to audit the software for errors in the code and correct them
  433.        '''
  434.  
  435.         epilog = ''' Main Functions
  436.    - {a:<10} Check for open ports in specific site                    [-f {a:<8} -in www.site.com -t 1]
  437.    - {b:<10} Craw and return all href links                           [-f {b:<8} -in www.site.com ]
  438.    - {c:<10} Acess site's/robots.txt and return content               [-f {c:<8} -in www.site.com]
  439.    - {d:<10} Search for vulnerable dorks with google hacking          [-f {d:<8} -in 'YOU DORK HERE' -max 1]
  440.    - {e:<10} Scrap site's SourceCode                                  [-f {e:<8} -in www.site.com]
  441.    - {f:<10} Scrap sitemap.xml Code and return all links              [-f {f:<8} -in www.site.com]
  442.    - {g:<10} Check if website is classic SQL and if is vulnerable     [-f {g:<8} -in www.site.com/cart.php?id=1]
  443.    - {h:<10} Check connections in wordlist for admin url login        [-f {h:<8} -in www.site.com]
  444.    - {i:<10} Run a IP Lookup and return all host information          [-f {i:<8} -in www.site.com]
  445.  
  446.    [?] To see all documentation about an function. Use '-info function' or '--get_info=function'
  447.    [?] If you need to put 'SPACES' in function content use -f "function" -in "content"
  448.  
  449.    example:
  450.    -f search -in "FOO BAR" or
  451.    -f search -in="FOO BAR"
  452.  
  453.        '''.format(a=d1[0],b=d1[1],c=d1[2],d=d1[3],e=d1[4],f=d1[5],g=d1[6],h=d1[7],i=d1[8])
  454.         usage= "netool.py [-h] [-f FUNCTION] [-in ADRESS] [-t TIMEOUT] [-max MAX OPERATIONS]"
  455.        
  456.         parser = argparse.ArgumentParser(description=desc,epilog=epilog,usage=usage,formatter_class=RawTextHelpFormatter)
  457.        
  458.         parser._optionals.title = " arguments"
  459.  
  460.         parser.add_argument('-info','--get_info',default='None', nargs='?', help=' get more info about one specific module  [-info funcion',        dest='Info')
  461.         parser.add_argument('-f',"--function",   default='None', nargs='?', help=' use this argument follow by function     [-f function]',         dest='Function')
  462.         parser.add_argument('-in',"--target",    default='None', nargs='?', help=' use this argument follow by content      [-in adress]',          dest='Content')
  463.         parser.add_argument('-t',"--timeout",    default=1,      nargs='?', help=' Set function timeout                     [-t 1, default = 1]',   dest='Timeout')
  464.         parser.add_argument('-max',"--maximum",  default=10,     nargs='?', help=' Set an maximum value                     [-max 1, default = 10]',dest='Max')
  465.        
  466.     try:
  467.         args = parser.parse_args()
  468.  
  469.         if args.Info == 'None':        
  470.             arg_func=func_dicts[str(args.Function)]
  471.            
  472.             c = args.Content
  473.             t = args.Timeout
  474.             max = args.Max
  475.            
  476.             h = datetime.now()
  477.             st = strftime("%H:%M:%S")
  478.             print("─"*100,"\n[{0}] [START] Start '{f}' service at '{ctt}'".format(st,f=args.Function,ctt=c))
  479.            
  480.             f = globals()[arg_func](c,t,max)
  481.            
  482.             ct = strftime("%H:%M:%S")
  483.             print("[{0}] [COMPLETED] Completed '{f}' service in '{ctt}'\n".format(ct,f=args.Function,ctt=c),"─"*100)
  484.  
  485.         else:
  486.             sel_help_func = args.Info
  487.             st = strftime("%H:%M:%S")
  488.             print("─"*100,"\n[{0}] [START] Start 'info' in '{f}'".format(st,f=sel_help_func))
  489.  
  490.             get_all_info(sel_help_func)
  491.            
  492.             ct = strftime("%H:%M:%S")
  493.             print("[{0}] [COMPLETED] Completed 'info' in '{f}' \n".format(ct,f=sel_help_func),"─"*100)
  494.  
  495.     except Exception as error:
  496.         print(error,'[!!] you need a content first . ')
  497.  
  498. except KeyboardInterrupt:
  499.     print('''\n[!!!]          [Ctrl + C > KEYBOARD INTERRUPT]         [!!!]''')
Add Comment
Please, Sign In to add comment