ClavinJune

Dirhunter_v2

Apr 23rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.89 KB | None | 0 0
  1. """
  2.  
  3. """
  4.  
  5. #!/bin/bash/python
  6. #Library
  7. from string import ascii_lowercase
  8. import itertools, os, sys, time, requests, getopt, socket
  9.  
  10. #pre-defined variable
  11. arg_start = 1
  12. arg_end = 10
  13. file_name = "result.txt"
  14. word_list = "wordlist.lst"
  15. url = ""
  16. menu = -1
  17. guess = ""
  18. option = -1
  19. ext = ""
  20. #coloring
  21. class color:
  22.     VIOLET = '\033[95m'
  23.     BLUE = '\033[94m'
  24.     YELLOW = '\033[93m'
  25.     GREEN = '\033[92m'
  26.     RED = '\033[91m'
  27.     UNDERLINE = '\033[4m'
  28.     BOLD = '\033[1m'
  29.     NORMAL = '\033[0m'
  30.  
  31. #splash screen
  32. def splash_screen():
  33.     print (color.GREEN + color.BOLD + "\t\t ____  _                _   _             _            ")
  34.     print ("\t\t|  _ \(_)_ __          | | | |_   _ _ __ | |_ ___ _ __ ")
  35.     print ("\t\t| | | | | '__|  _____  | |_| | | | | '_ \| __/ _ \ '__|")
  36.     print ("\t\t| |_| | | |    |_____| |  _  | |_| | | | | ||  __/ |   ")
  37.     print ("\t\t|____/|_|_|            |_| |_|\__,_|_| |_|\__\___|_| v2   ")
  38.     print ("\t\tApoll0                                                       " + color.NORMAL)
  39.     print ("\t\t\t\t\t\t\t\t  " + color.BOLD + "By:" + color.UNDERLINE + "D4RK1T5UN3" + color.NORMAL + color.RED)
  40.     print ('-' * 80)
  41.     print (color.BLUE + '\t0x00 Input URL with "http://" or "https://"')
  42.     print ('\t0x01 Input URL without "/" behind')
  43.     print ('\t0x02 Input URL like this "http://localhost" or "https://facebook.com"')
  44.     print ('\t0x03 DO NOT input URL like this "localhost" or "facebook.com/"')
  45.     print ('\t0x04 Dir-Hunter speed depends on your connection speed')
  46.     print ('\t0x05 "CTRL + C" for reset || "CTRL + Z" for stop')
  47.     print ('\t0x06 HAPPY HUNTING' + color.NORMAL + color.RED)
  48.     print ('-' * 80 + color.NORMAL)
  49.  
  50. #usage
  51. def usage():
  52.     print('python dirhunter.py [options] [value]')
  53.     print(color.BOLD + 'OPTIONS' + color.NORMAL)
  54.     print('-s | --start')
  55.     print('\tif value is 2, so bruteforce will start from "aa"')
  56.     print('-e | --end')
  57.     print('\tif value is 3, so bruteforce will ends in "aaa"')
  58.     print('-o | --out')
  59.     print('\tif value is "a.txt", will make an output named "a.txt"')
  60.     print('-h | --help')
  61.     print('\twill show this help')
  62.     print('-u | --url')
  63.     print('\tif value is http://localhost, url will set on value ')
  64.     print('-w | --wordlist')
  65.     print('\tif value is "b.txt", will use "b.txt" as a wordlist')
  66.     print('-m | --menu')
  67.     print('\t1\t\tBruteforce Directory')
  68.     print('\t2\t\tBruteforce Subdomain')
  69.     print('\t3\t\tDictionary Attack Directory')
  70.     print('\t4\t\tDictionary Attack SubDomain')
  71.     print('\t7\t\tBruteforce file')
  72.     print('\t8\t\tRandom Guess')
  73.    
  74.    
  75.  
  76. #word generator
  77. def iter_all_strings():
  78.     size = arg_start
  79.     while size <= arg_end:
  80.         for directory in itertools.product(ascii_lowercase, repeat=size):
  81.             yield "".join(directory)
  82.         size += 1
  83.  
  84. #clear
  85. def clear():
  86.     for i in range(0,25):
  87.         print()
  88.  
  89. #checking robots.txt
  90. def check_robot():
  91.     if requests.get(url + "/robots.txt").status_code == 200:
  92.         return "True"
  93.     else:
  94.         return "None"
  95.  
  96. #Reading robots.txt
  97. def read_robot():
  98.     if check_robot() == "True":
  99.         print(color.GREEN + "Robots.txt here" + color.NORMAL)
  100.         print(requests.get(url + "/robots.txt").text)
  101.         print(color.RED + '-' * 80 + color.NORMAL)
  102.  
  103. #getting_ip
  104. def getting_ip():
  105.     domain = url.split('://')
  106.     domain = domain[1]
  107.     domain = domain.split('/')
  108.     domain = domain[0]
  109.     return socket.gethostbyname(domain)
  110.  
  111. #getting_domain
  112. def getting_domain():
  113.     domain = url.split('://')
  114.     domain = domain[1]
  115.     return domain
  116.  
  117. #checking_luck
  118. def checking_luck():
  119.     try:
  120.         if requests.get(url+ "/" + guess).status_code == 200:
  121.             print(" [*] "+color.GREEN+url+ "/" + guess+" "+color.BOLD+"\t\tFOUND"+color.NORMAL)
  122.             file.write(url+ "/" + guess + "\n")
  123.         else:
  124.             print(" [*] "+color.RED+url+ "/" + guess+" "+color.BOLD+"\tNOT FOUND"+color.NORMAL)
  125.  
  126.         #if requests.get("http://" + guess + "." +  getting_domain()).status_code == 200:
  127.         #   print(" [*] "+color.GREEN+"http://" + guess + "." +  getting_domain() +" "+color.BOLD+"\tFOUND"+color.NORMAL)
  128.         #   file.write("http://" + guess + "." +  getting_domain()+"\n")
  129.         #else:
  130.         #   print(" [*] "+color.GREEN+"http://" + guess + "." +  getting_domain() +" "+color.BOLD+"\tNOT FOUND"+color.NORMAL)
  131.  
  132.         if requests.get(url+ "/" + guess+".php").status_code == 200:
  133.             print(" [*] "+color.GREEN+url+ "/" + guess+".php"+" "+color.BOLD+"\tFOUND"+color.NORMAL)
  134.             file.write(url+ "/" + guess+".php\n")
  135.         else:
  136.             print(" [*] "+color.RED+url+ "/" + guess+".php"+" "+color.BOLD+"\tNOT FOUND"+color.NORMAL)
  137.  
  138.         if requests.get(url+ "/" + guess+".html").status_code == 200:
  139.             print(" [*] "+color.GREEN+url+ "/" + guess+".html"+" "+color.BOLD+"\tFOUND"+color.NORMAL)
  140.             file.write(url+ "/" + guess+".html\n")
  141.         else:
  142.             print(" [*] "+color.RED+url+ "/" + guess+".html"+" "+color.BOLD+"\tNOT FOUND"+color.NORMAL)
  143.  
  144.         if requests.get(url+ "/" + guess+".jsp").status_code == 200:
  145.             print(" [*] "+color.GREEN+url+ "/" + guess+".jsp"+" "+color.BOLD+"\tFOUND"+color.NORMAL)
  146.             file.write(url+ "/" + guess+".jsp\n")
  147.         else:
  148.             print(" [*] "+color.RED+url+ "/" + guess+".jsp"+" "+color.BOLD+"\tNOT FOUND"+color.NORMAL)
  149.  
  150.         if requests.get(url+ "/" + guess+".aspx").status_code == 200:
  151.             print(" [*] "+color.GREEN+url+ "/" + guess+".aspx"+" "+color.BOLD+"\tFOUND"+color.NORMAL)
  152.             file.write(url+ "/" + guess+".aspx\n")
  153.         else:
  154.             print(" [*] "+color.RED+url+ "/" + guess+".aspx"+" "+color.BOLD+"\tNOT FOUND"+color.NORMAL)
  155.  
  156.         if requests.get(url+ "/" + guess+".txt").status_code == 200:
  157.             print(" [*] "+color.GREEN+url+ "/" + guess+".txt"+" "+color.BOLD+"\tFOUND"+color.NORMAL)
  158.             file.write(url+ "/" + guess+".txt\n")
  159.         else:
  160.             print(" [*] "+color.RED+url+ "/" + guess+".txt"+" "+color.BOLD+"\tNOT FOUND"+color.NORMAL)
  161.     except:
  162.         sys.exit(2)
  163.  
  164. #getting_cms
  165. def getting_cms():
  166.     return
  167.  
  168. #setting info
  169. def set_info():
  170.     print(color.RED + '-' * 80 + color.NORMAL)
  171.     print("Bruteforce will starts from " + str(arg_start) + " character(s)")
  172.     print("Bruteforce will ends at " + str(arg_end) + " character(s)")
  173.     print("Output file is " + file_name)
  174.     print("Wordlist file is " + word_list)
  175.     print(color.RED + '-' * 80 + color.NORMAL)
  176.  
  177. #web info
  178. def web_info():
  179.     print (color.GREEN + color.BOLD + "\t\t ____  _                _   _             _            ")
  180.     print ("\t\t|  _ \(_)_ __          | | | |_   _ _ __ | |_ ___ _ __ ")
  181.     print ("\t\t| | | | | '__|  _____  | |_| | | | | '_ \| __/ _ \ '__|")
  182.     print ("\t\t| |_| | | |    |_____| |  _  | |_| | | | | ||  __/ |   ")
  183.     print ("\t\t|____/|_|_|            |_| |_|\__,_|_| |_|\__\___|_| v2   ")
  184.     print ("\t\tApoll0                                                       " + color.NORMAL)
  185.     print(color.RED + '-' * 80 + color.NORMAL)
  186.     print(color.GREEN + "Target     : " + color.NORMAL + url)
  187.     print(color.GREEN + "IP         : " + color.NORMAL + getting_ip())
  188.     print(color.GREEN + "CMS        : " + color.NORMAL )
  189.     print(color.GREEN + "Robots.txt : " + color.NORMAL + check_robot())
  190.     print(color.RED + '-' * 80 + color.NORMAL)
  191.     read_robot()
  192.  
  193. #getting argument
  194. try:
  195.     opts, args = getopt.getopt(sys.argv[1:], 'hs:e:o:u:w:m:', ['help','start=', 'end=', 'out=', 'url=', 'wordlist=', 'menu='])
  196. except getopt.GetoptError:
  197.     splash_screen()
  198.     usage()
  199.     sys.exit(2)
  200.  
  201. for opt,arg in opts:
  202.     if opt in ('-h', '--help'):
  203.         splash_screen()
  204.         usage()
  205.         sys.exit(2)
  206.     elif opt in ('-s', '--start'):
  207.         arg_start = int(arg)
  208.     elif opt in ('-e', '--end'):
  209.         arg_end = int(arg)
  210.     elif opt in ('-o', '--out'):
  211.         file_name = arg
  212.     elif opt in ('-u', '--url'):
  213.         url = arg
  214.     elif opt in ('-w', '--wordlist'):
  215.         word_list = arg
  216.     elif opt in ('-m', '--menu'):
  217.         menu = int(arg)
  218.  
  219. #checking length
  220. if arg_start > arg_end:
  221.     arg_end = arg_start + 2
  222.  
  223. #Main Program
  224. while True:
  225.     file = open(file_name, "w")
  226.     file.close()
  227.     clear()
  228.     splash_screen()
  229.     if url == "":
  230.         try:
  231.             url = input('[+] Input URL -- > ')
  232.         except:
  233.             sys.exit(2)
  234.     try:           
  235.         response= requests.get(url).status_code
  236.     except:
  237.         sys.exit(2)
  238.  
  239.     if response == 200:
  240.         print("Getting Info. . ")
  241.         while True:
  242.             clear()
  243.             web_info()
  244.             print(color.BLUE + "[1] Bruteforce Directory", end = '\t\t')
  245.             print("[2] Bruteforce Subdomain")
  246.             print("[3] Dictionary Attack Directory", end = '\t\t')
  247.             print("[4] Dictionary Attack Subdomain")
  248.             print("[5] Adding words to wordlist", end = '\t\t')
  249.             print("[6] View wordlist")
  250.             print("[7] Bruteforce file", end = '\t\t\t')
  251.             print("[8] Random Guess")
  252.             print("[9] Settings", end = '\t\t\t\t')
  253.             print("[0] Change Target" + color.NORMAL)
  254.             try:
  255.                 while menu < 0 or menu > 9:
  256.                     menu = eval(input("Choose --> "))
  257.             except:
  258.                 file.close()
  259.                 sys.exit(2)
  260.  
  261.             if menu == 1:
  262.                 clear()
  263.                 web_info()
  264.                 print("Starting. . .")
  265.                 file = open(file_name, "a")
  266.                 try:
  267.                     for directory in iter_all_strings():
  268.                         link = url + '/' + directory
  269.                         print(link, end = '\r')
  270.                         if requests.get(link).status_code == 200:
  271.                             print(" [*] " + color.GREEN + link + " " + color.BOLD + "\tFOUND" + color.NORMAL)
  272.                             file.write(link + '\n')
  273.                         elif requests.get(link).status_code == 403:
  274.                             print(" [*] " + color.RED + link + " " + color.BOLD + "\tFORBIDDEN" + color.NORMAL)
  275.                 except:
  276.                     print("\nEnd of Bruteforce in '"+ directory+"'")
  277.                     print("\n" + color.BOLD + color.GREEN + 'directory has stored in ' + file_name + color.NORMAL)
  278.                     try:
  279.                         input()
  280.                     except:
  281.                         file.close()
  282.                         sys.exit(2)
  283.                 file.close()
  284.                 menu = -1
  285.             elif menu == 2:
  286.                 clear()
  287.                 web_info()
  288.                 print("Soon")
  289.                 input()
  290.                 # print("Starting. . .")
  291.                 # file = open(file_name, "a")
  292.                 # try:
  293.                 #   for directory in iter_all_strings():
  294.                 #       link = "http://" + directory + "." + getting_domain()
  295.                 #       print(link, end = '\r')
  296.                 #       if requests.get(link).status_code == 200:
  297.                 #           print(" [*] " + color.GREEN + link + " " + color.BOLD + "\tFOUND" + color.NORMAL)
  298.                 #           file.write(link + '\n')
  299.                 #       elif requests.get(link).status_code == 403:
  300.                 #           print(" [*] " + color.RED + link + " " + color.BOLD + "\tFORBIDDEN" + color.NORMAL)
  301.                 # except:
  302.                 #   print("\nEnd of Bruteforce in '"+ directory+"'")
  303.                 #   print("\n" + color.BOLD + color.GREEN + 'directory has stored in ' + file_name + color.NORMAL)
  304.                 #   try:
  305.                 #       input()
  306.                 #   except:
  307.                 #       file.close()
  308.                 #       sys.exit(2)
  309.                 # file.close()
  310.                 menu = -1
  311.             elif menu == 3:
  312.                 clear()
  313.                 web_info()
  314.                 print("Starting. . .")
  315.                 file = open(file_name, "a")
  316.                 try:
  317.                     wl = open(word_list, "r")
  318.                 except:
  319.                     print("No File")
  320.                     input()
  321.                     menu = -1
  322.                     break
  323.                 words = wl.read().split('\n')
  324.                 try:
  325.                     for word in words:
  326.                         link = url + '/' + word
  327.                         if requests.get(link).status_code == 200:
  328.                             print(" [*] " + color.GREEN + link + " " + color.BOLD + "\tFOUND" + color.NORMAL)
  329.                             file.write(link + '\n')
  330.                         elif requests.get(link).status_code == 403:
  331.                             print(" [*] " + color.RED + link + " " + color.BOLD + "\tFORBIDDEN" + color.NORMAL)
  332.                 except:
  333.                     print("\nEnd of Bruteforce in '"+ directory+"'")
  334.                     print("\n" + color.BOLD + color.GREEN + 'directory has stored in ' + file_name + color.NORMAL)
  335.                     try:
  336.                         input()
  337.                     except:
  338.                         file.close()
  339.                         wl.close()
  340.                         sys.exit(2)
  341.                 print("End.")
  342.                 file.close()
  343.                 wl.close()
  344.                 try:
  345.                     input()
  346.                 except:
  347.                     sys.exit(2)
  348.                 menu = -1
  349.             elif menu == 4:
  350.                 clear()
  351.                 web_info()
  352.                 print("Soon")
  353.                 input()
  354.                 menu = -1
  355.             elif menu == 5:
  356.                 clear()
  357.                 web_info()
  358.                 try:
  359.                     temp_wl = input("Add word : ")
  360.                 except:
  361.                     sys.exit(2)
  362.                 wl = open(word_list, "a")
  363.                 wl.write(temp_wl + '\n')
  364.                 wl.close()
  365.                 menu = -1
  366.             elif menu == 6:
  367.                 clear()
  368.                 number_of_words=0
  369.                 try:
  370.                     wl = open(word_list, "r")
  371.                 except:
  372.                     print("No File")
  373.                     input()
  374.                     menu = -1
  375.                     break
  376.                 try:
  377.                     for string in wl.read():
  378.                         if string != '\n':
  379.                             print(string, end ='')
  380.                         elif string == '\n':
  381.                             print()
  382.                         else:
  383.                             print(string)
  384.                         time.sleep(0.01)
  385.                 except:
  386.                     print()
  387.                 try:
  388.                     a = open(word_list, "r")
  389.                     b = a.read().split('\n')
  390.                     a.close()
  391.                     for c in b:
  392.                         number_of_words += 1
  393.                 except:
  394.                     print()
  395.                 print(color.RED + '-' * 80 + color.NORMAL + "\nEnd of File. . .")
  396.                 print("Total " + str(number_of_words-1) + " words in wordlist")
  397.                 try:
  398.                     input()
  399.                 except:
  400.                     sys.exit(2)
  401.                 wl.close()
  402.                 menu = -1
  403.             elif menu == 7:
  404.                 clear()
  405.                 web_info()
  406.                 while ext != "php" and ext != "html" and ext != "jsp" and ext != "txt" and ext != "aspx":
  407.                     try:
  408.                         ext = input("What extension [php | html | jsp | aspx | txt]? ")
  409.                     except:
  410.                         sys.exit(2)
  411.                 file = open(file_name, "a")
  412.                 try:
  413.                     for directory in iter_all_strings():
  414.                         link = url + '/' + directory + '.' + ext
  415.                         print(link, end = '\r')
  416.                         if requests.get(link).status_code == 200:
  417.                             print(" [*] " + color.GREEN + link + " " + color.BOLD + "\tFOUND" + color.NORMAL)
  418.                             file.write(link + '\n')
  419.                         elif requests.get(link).status_code == 403:
  420.                             print(" [*] " + color.RED + link + " " + color.BOLD + "\tFORBIDDEN" + color.NORMAL)
  421.                 except:
  422.                     print("\nEnd of Bruteforce in '"+ directory+"'")
  423.                     print("\n" + color.BOLD + color.GREEN + 'directory has stored in ' + file_name + color.NORMAL)
  424.                     try:
  425.                         input()
  426.                     except:
  427.                         file.close()
  428.                         sys.exit(2)
  429.                 file.close()
  430.                 menu = -1
  431.             elif menu == 8:
  432.                 clear()
  433.                 web_info()
  434.                 try:
  435.                     guess = input("Give 1 keyword = ")
  436.                 except:
  437.                     file.close()
  438.                     sys.exit(2)
  439.                 print("Checking your luck. . .")
  440.                 file = open(file_name, "a")
  441.                 checking_luck()
  442.                 print("End. ")
  443.                 try:
  444.                     input()
  445.                 except:
  446.                     file.close()
  447.                     sys.exit(2)
  448.                 file.close()
  449.                 menu = -1
  450.             elif menu == 9:
  451.                 while option != 0:
  452.                     clear()
  453.                     set_info()
  454.                     print(color.BLUE + "[1] start number of bruteforce")
  455.                     print("[2] end number of bruteforce")
  456.                     print("[3] output file")
  457.                     print("[4] wordlist file")
  458.                     print("[5] Default")
  459.                     print("[0] Back to menu" + color.NORMAL)
  460.                     try:
  461.                         while option < 0 or option > 5:
  462.                             option = eval(input("Reset number? "))
  463.                     except:
  464.                         file.close()
  465.                         sys.exit(2)
  466.                     if option != 0 and option != 5:
  467.                         try:
  468.                             new_option = input("Replace with? ")
  469.                         except:
  470.                             file.close()
  471.                             sys.exit(2)
  472.                     if option == 1:
  473.                         try:
  474.                             arg_start = int(new_option)
  475.                         except:
  476.                             file.close()
  477.                             sys.exit(2)
  478.                     elif option == 2:
  479.                         try:
  480.                             arg_end = int(new_option)
  481.                         except:
  482.                             file.close()
  483.                             sys.exit(2)
  484.                     elif option == 3:
  485.                         file_name = new_option
  486.                     elif option == 4:
  487.                         word_list = new_option
  488.                     elif option == 5:
  489.                         arg_start = 1
  490.                         arg_end = 10
  491.                         file_name = "result.txt"
  492.                         word_list = "wordlist.lst"
  493.                     elif option == 0:
  494.                         menu = -1
  495.                         option = -1
  496.                         break
  497.  
  498.                     if arg_start > arg_end:
  499.                         arg_end = arg_start + 2
  500.                     option = -1
  501.             elif menu == 0:
  502.                 url = ""
  503.                 menu = -1
  504.                 break
Add Comment
Please, Sign In to add comment