-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathssh.py
executable file
·90 lines (76 loc) · 2.47 KB
/
ssh.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
#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 paramiko
def file2list(filename):
try:
list=[]
d=open(filename,'r')
data=d.readline().strip('\r\n')
while(data):
list.append(data)
data=d.readline().strip('\r\n')
except Exception,e:
if e[0]==2:
lock.acquire()
printRed("not such file:%s\r\n" %filename)
lock.release()
return list
def ssh_connect(ip,username,password,port):
crack=0
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip,port,username=username, password=password)
crack=1
client.close()
except Exception,e:
lock.acquire()
print "%s ssh service 's %s:%s login fail " %(ip,username,password)
lock.release()
return crack
pass
return crack
def ssh():
while True:
ip,port=sp.get()
flag=0
usernames=file2list('ssh_user.txt')
passwords=file2list('ssh_pass.txt')
for username in usernames:
for password in passwords:
if ssh_connect(ip,username,password,port)==1:
lock.acquire()
printGreen("%s ssh service at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,password))
result.append("%s ssh service at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,password))
lock.release()
flag=1
break
if flag==1:
flag=0
break
sp.task_done()
def ssh_main(ipdict,threads):
printPink("crack ssh now...")
print "[*] start crack ssh %s" % time.ctime()
starttime=time.time()
global sp
sp=Queue()
global lock
lock = threading.Lock()
global result
result=[]
for i in xrange(threads):
t = Thread(target=ssh)
t.setDaemon(True)
t.start()
for ip in ipdict['ssh']:
sp.put((str(ip).split(':')[0],int(str(ip).split(':')[1])))
sp.join()
print "[*] stop ssh serice %s" % time.ctime()
print "[*] crack ssh done,it has Elapsed time:%s " % (time.time()-starttime)
return result