-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtelnet.py
executable file
·165 lines (154 loc) · 5.02 KB
/
telnet.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
#coding=utf-8
import time
import re
import threading
from threading import Thread
from lib.printers import printPink,printRed,printGreen
from Queue import Queue
import telnetlib
usernames=[
'administrator',
'root',
'wilson',
'test',
'web',
'www',
'nobody',
]
passwords=[
'',
'1',
'12',
'123',
'1234',
'12345',
'123456',
'1234567',
'12345678',
'123456789',
'1234567890',
'654321',
'54321',
'00000000',
'88888888',
'pass',
'password',
'passwd',
'!@#$%^',
'1q2w3e',
'qawsed',
'pwd',
'1qaz2ws3e4',
'qazwsxedc',
'!@#$%^&*',
]
def telnet_test_login(ip,password,username,port):
crack=0
tn = telnetlib.Telnet(ip,port=port,timeout=5)
tn.read_until("login: ")
tn.write(username+ '\r')
#等一会再 输入密码
time.sleep(3)
#需要接受一下输出 - -|||
tn.read_very_eager()
tn.write(password + "\r")
#等一会再 接受数据
time.sleep(4)
msg=tn.read_some()
tn.close()
#判断msg是不是login fail 或者error
if msg.strip()=='':
lock.acquire()
print "%s telnet's %s:%s login fail " %(ip,username,password)
lock.release()
if re.search("(.*?)fail",msg,re.I):
lock.acquire()
print "%s telnet's %s:%s login fail " %(ip,username,password)
lock.release()
else:
if re.search("(.*?)incorrect",msg,re.I):
lock.acquire()
print "%s telnet's %s:%s login fail " %(ip,username,password)
lock.release()
else:
lock.acquire()
printGreen("%s telnet has weaken password!!-------%s:%s\r\n" %(ip,username,password))
result.append("%s telnet has weaken password!!-------%s:%s\r\n" %(ip,username,password))
lock.release()
crack=1
return crack
def telnet():
while True:
ip,port=sp.get()
flag=0
try:
#弱口令爆破
for username in usernames:
if telnet_test_login(ip,username,username,port)==1:
break
if telnet_test_login(ip,username+'123',username,port)==1:
break
if telnet_test_login(ip,username+'123456',username,port)==1:
break
for password in passwords:
tn = telnetlib.Telnet(ip,port=port,timeout=5)
tn.read_until("login: ")
tn.write(username+ '\r')
#等一会再 输入密码
time.sleep(3)
#需要接受一下输出 - -|||
tn.read_very_eager()
tn.write(password + "\r")
#等一会再 接受数据
time.sleep(4)
msg=tn.read_some()
tn.close()
if msg.strip()=='':
lock.acquire()
print "%s telnet's %s:%s login fail " %(ip,username,password)
lock.release()
#判断msg是不是login fail 或者error
if re.search("(.*?)fail",msg,re.I):
lock.acquire()
print "%s telnet's %s:%s login fail " %(ip,username,password)
lock.release()
else:
if re.search("(.*?)incorrect",msg,re.I):
lock.acquire()
print "%s telnet's %s:%s login fail " %(ip,username,password)
lock.release()
else:
lock.acquire()
printGreen("%s telnet has weaken password!!-------%s:%s\r\n" %(ip,username,password))
result.append("%s telnet has weaken password!!-------%s:%s\r\n" %(ip,username,password))
lock.release()
flag=1
break
if flag == 1:
flag=0
break
except Exception,e:
printPink(e)
sp.task_done()
def telnet_main(ipdict,threads):
if len(ipdict['telnet'])!=0:
printPink("crack telnet now...")
print "[*] start crack telnet %s" % time.ctime()
starttime=time.time()
global sp
sp=Queue()
global lock
crack=0
lock = threading.Lock()
global result
result=[]
for i in xrange(threads):
t = Thread(target=telnet)
t.setDaemon(True)
t.start()
for ip in ipdict['telnet']:
sp.put((str(ip).split(':')[0],str(ip).split(':')[1]))
sp.join()
print "[*] stop crack telnet %s" % time.ctime()
print "[*] crack telnet done,it has Elapsed time:%s " % (time.time()-starttime)
return result