-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsmb.py
executable file
·116 lines (101 loc) · 3.97 KB
/
smb.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
#coding=utf-8
import time
import re
import threading
from threading import Thread
from lib.printers import printPink,printRed,printGreen
from Queue import Queue
from impacket import smb
from impacket.smbconnection import *
from impacket.smb3structs import *
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 smb_connect(ip,username,password):
crack =0
try:
smb = SMBConnection('*SMBSERVER', ip)
smb.login(username,password)
smb.logoff()
crack =1
except Exception, e:
lock.acquire()
print "%s smb 's %s:%s login fail " %(ip,username,password)
lock.release()
return crack
pass
return crack
def smb():
while True:
ip,port=sp.get()
flag=0
usernames=file2list('smb_user.txt')
passwords=file2list('smb_pass.txt')
for username in usernames:
if smb_connect(ip,username,username)==1:
lock.acquire()
printGreen("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username))
result.append("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username))
lock.release()
break
if smb_connect(ip,username,username+'123')==1:
lock.acquire()
printGreen("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123'))
result.append("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123'))
lock.release()
break
if smb_connect(ip,username,username+'123456')==1:
lock.acquire()
printGreen("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123456'))
result.append("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123456'))
lock.release()
break
if smb_connect(ip,username,'')==1:
lock.acquire()
printGreen("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,username,''))
result.append("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,''))
lock.release()
break
for password in passwords:
if smb_connect(ip,username,password)==1:
lock.acquire()
printGreen("%s smb at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,password))
result.append("%s smb 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 smb_main(ipdict,threads):
printPink("crack smb now...")
print "[*] start crack smb serice %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=smb)
t.setDaemon(True)
t.start()
for ip in ipdict['smb']:
sp.put((str(ip).split(':')[0],int(str(ip).split(':')[1])))
sp.join()
print "[*] stop smb serice %s" % time.ctime()
print "[*] crack smb done,it has Elapsed time:%s " % (time.time()-starttime)
return result