Advertisement
AZZATSSINS_CYBERSERK

admin finder

Apr 2nd, 2017
1,574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.95 KB | None | 0 0
  1. # wordlist https://pastebin.com/5P9sj341
  2. # -*- coding: utf-8 -*-
  3. #!/usr/bin/env python
  4.  
  5. from __future__ import division
  6. import Queue
  7. import threading
  8. import time
  9. import urllib
  10. import os
  11. import re
  12. import sys
  13.  
  14. stateLock = threading.Lock()
  15.  
  16.  
  17. class website:
  18.     """
  19.    This class handles URL formatting
  20.    And checking if the website is online
  21.    """
  22.  
  23.     def __init__(self, data):
  24.         site = data
  25.         if not data.startswith("http"):
  26.             site = "http://" + site
  27.         if not site.endswith("/"):
  28.             site = site + "/"
  29.         self.address = site
  30.  
  31.         print("[?] Checking if is website online")
  32.         statusCode = self.checkStatus(self.address)
  33.         if statusCode == 200:
  34.             print("[+] Website seem online!")
  35.         elif statusCode == 404:
  36.             print("[-] Website seem down")
  37.             exit()
  38.         else:
  39.             print("[?] Received HTTP Code : ", statusCode)
  40.             exit()
  41.  
  42.         self.checkRobot(self.address)
  43.  
  44.     def checkStatus(self, address):
  45.         """ This function returns the status of the website """
  46.         try:
  47.             return urllib.urlopen(address).getcode()
  48.         except IOError:
  49.             print("[!] Something wrong with your address")
  50.             exit()
  51.  
  52.  
  53.     def checkRobot(self,address):
  54.         """
  55.        This function is to check if robots.txt/robot.txt exist and see if the
  56.        Admin path is already in there
  57.        """
  58.         print("[?] Checking for robot file")
  59.         path = ["robot.txt","robots.txt"]
  60.         urls = [address + i for i in path]
  61.  
  62.         for url in urls:
  63.             statusCode = self.checkStatus(url)
  64.             if statusCode == 200:
  65.                 print("\n[+] %s \n[+] Exists, reading content" % url)
  66.                 info = self.parseDir(url)
  67.                 if info:
  68.                     print("[=] Interesting Information found in robot file")
  69.                     print("="*80)
  70.                     for line in info:
  71.                         print "\t"+line
  72.                     print("="*80)
  73.  
  74.                     try:
  75.                         raw_input("[+] Ctrl + C to stop")
  76.                     except KeyboardInterrupt:
  77.                         os._exit(1)
  78.                 else:
  79.                     print("[-] Nothing useful found in robot file")
  80.  
  81.     def getPage(self, address):
  82.         return urllib.urlopen(address).readlines()
  83.  
  84.     def parseDir(self, address):
  85.         DirPattern = re.compile(r".+: (.+)\n")
  86.         interestingInfo = []
  87.         dirs = []
  88.         keyword = ["admin","Administrator","login","user","controlpanel",
  89.                    "wp-admin","cpanel","userpanel","client","account"]
  90.  
  91.         page = self.getPage(address)
  92.         # Parsing the robot file content for directory
  93.         for line in page:
  94.             if DirPattern.findall(line):
  95.                 dirs.append(DirPattern.findall(line)[0])
  96.  
  97.         # Checking if the directory contains juicy information
  98.         for key in keyword:
  99.             for directory in dirs:
  100.                 if key in directory:
  101.                     interestingInfo.append(directory)
  102.         return interestingInfo
  103.  
  104. class wordlist:
  105.     """ This function loads the wordlsit """
  106.     def __init__(self):
  107.         try:
  108.             # read the file and remove \n at the line ending
  109.             self.load = [i.replace('\n', '') for i in open('wordlist.txt').readlines()]
  110.         except IOError:
  111.             print("[!] I/O Error, wordlist.txt not found")
  112.  
  113.  
  114. class scanThread(threading.Thread):
  115.     """ This class is the blueprint used to generate threads """
  116.     def __init__(self, q):
  117.         threading.Thread.__init__(self)
  118.         self.queue = q
  119.  
  120.     def run(self):
  121.         while not self.queue.empty():
  122.         # While queue is not empty, which means there is work to do
  123.             stateLock.acquire()
  124.             url = self.queue.get()
  125.             stateLock.release()
  126.             if self.online(url):
  127.                 stateLock.acquire()
  128.                 print("\n\n[+] Admin page found in %.2f seconds" % (time.time() - starttime))
  129.                 print("[=] %s" % url)
  130.                 raw_input("[+] Press Enter to exit")
  131.                 print("[+] Exiting Program")
  132.                 os._exit(1)
  133.  
  134.             else:
  135.                 stateLock.acquire()
  136.                 #print("[-] Tried : %s" % url)
  137.                 stateLock.release()
  138.             self.queue.task_done()
  139.             # Release task completed status
  140.  
  141.     def online(self, url):
  142.         """ Returns True if the url is online AKA HTTP status code == 200 """
  143.         try:
  144.             return urllib.urlopen(url).getcode() == 200
  145.         except IOError:
  146.             stateLock.acquire()
  147.             print("[!] Name Resolution Error")
  148.             stateLock.release()
  149.  
  150.  
  151. def main():
  152.     try:
  153.         pathlist = wordlist().load
  154.         # loads the wordlist
  155.         address = website(raw_input("[+] Website to scan : ")).address
  156.         mainApp(address, pathlist)
  157.         # Runs the main Application
  158.     except KeyboardInterrupt:
  159.         print("\n[-] Ctrl + C Detected")
  160.         print("[-] Exiting")
  161.         os._exit(1)
  162.  
  163.  
  164. def progressBar(q):
  165.     symbol = "="
  166.     emptySymbol = "-"
  167.     maxJob = q.qsize()
  168.     maxlinesize = 20
  169.     while not q.empty():
  170.         current = q.qsize()
  171.         currentProgress = 100 - ((current / maxJob) * 100)
  172.         #print "Current : %s, progress = %s, maxJob = %s" % (current,currentProgress,maxJob)
  173.         if currentProgress < 95:
  174.             bar = symbol * int(currentProgress/(100/maxlinesize))
  175.         elif currentProgress > 95:
  176.             bar = symbol * maxlinesize
  177.         remaining = emptySymbol * (maxlinesize - len(bar))
  178.         line = "\rProgress : [%s%s] %.2f%%" % (bar,remaining,currentProgress)
  179.         #line = "\rو︻̷┻̿═━一 [%s%s] %.2f%%" % (bar, remaining,currentProgress)
  180.         threading.Thread(target=printoutput,args=(line,)).start()
  181.         # sys.stdout.write(line)
  182.         # sys.stdout.flush()
  183.         # time.sleep(1)
  184.  
  185. def printoutput(data):
  186.     stateLock.acquire()
  187.     sys.stdout.write(data)
  188.     sys.stdout.flush()
  189.     stateLock.release()
  190.     time.sleep(0.5)
  191.  
  192.  
  193.  
  194. class mainApp:
  195.     def __init__(self,address,plist):
  196.         self.address = address
  197.         self.wordlist = plist
  198.         self.createJobs()
  199.         self.run()
  200.  
  201.     def createJobs(self):
  202.         """
  203.        Joins website address with the admin paths from wordlist
  204.        and add it to queue
  205.        """
  206.         self.queue = Queue.Queue()
  207.         stateLock.acquire()
  208.         for path in self.wordlist:
  209.             self.queue.put(self.address + path)
  210.         stateLock.release()
  211.  
  212.     def run(self):
  213.         try:
  214.             print("[!] Press Ctrl + Z to stop while scanning")
  215.             threadCount = raw_input("[+] Enter number of threads [10]: ")
  216.             if not threadCount:
  217.                 print("[=] Number of threads = 10")
  218.                 threadCount = 20
  219.             else:
  220.                 print("[=] Number of threads = %d" % int(threadCount))
  221.  
  222.             threadList = []
  223.             global starttime
  224.             starttime = time.time()
  225.  
  226.             progressbar = threading.Thread(target=progressBar,args=(self.queue,))
  227.             progressbar.daemon = True
  228.             progressbar.start()
  229.  
  230.             for i in range(0, int(threadCount)):
  231.                 thread = scanThread(self.queue)
  232.                 #thread.daemon = True
  233.                 threadList.append(thread)
  234.                 thread.start()
  235.             # Waiting for all threads to finish
  236.             self.queue.join()
  237.             print("\n\n[=] Time elasped : %.2f seconds" % float(time.time()-starttime))
  238.             print("[-] Admin page not found!")
  239.             progressbar.join()
  240.             for thread in threadList:
  241.                 thread.join()
  242.         except KeyboardInterrupt:
  243.             stateLock.acquire()
  244.             print("\n[~] Ctrl + C Detected!")
  245.             print("[~] Exiting")
  246.             os._exit(1)
  247.  
  248. if __name__ == "__main__":
  249.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement