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