-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmysql.py
executable file
·130 lines (114 loc) · 4.4 KB
/
mysql.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
#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 MySQLdb
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 mysql_connect(ip,username,password,port):
crack =0
try:
db=MySQLdb.connect(ip,username,password,port=port)
if db:
crack=1
db.close()
except Exception, e:
if e[0]==1129:
lock.acquire()
printRed("%s has too many connect \r\n" %(ip))
lock.release()
if e[0]==1045:
lock.acquire()
print "%s mysql's %s:%s login fail " %(ip,username,password)
lock.release()
return crack
pass
return crack
def mysql():
while True:
ip,port=sp.get()
flag=0
usernames=file2list('mysql_user.txt')
passwords=file2list('mysql_pass.txt')
for username in usernames:
#test mysql is allow connect
try:
db=MySQLdb.connect(ip,username,password,port=port)
except Exception, e:
#print e
if e[0]==1130:
lock.acquire()
printRed("%s not allow to connect\r\n" %(ip))
lock.release()
break
if mysql_connect(ip,username,username,port)==1:
lock.acquire()
printGreen("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username))
result.append("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username))
lock.release()
break
if mysql_connect(ip,username,username+'123',port)==1:
lock.acquire()
printGreen("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123'))
result.append("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123'))
lock.release()
break
if mysql_connect(ip,username,username+'123456',port)==1:
lock.acquire()
printGreen("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123456'))
result.append("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,username+'123456'))
lock.release()
break
if mysql_connect(ip,username,'',port)==1:
lock.acquire()
printGreen("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,''))
result.append("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,''))
lock.release()
break
for password in passwords:
if mysql_connect(ip,username,password,port)==1:
lock.acquire()
printGreen("%s mysql at %s has weaken password!!-------%s:%s\r\n" %(ip,port,username,password))
result.append("%s mysql 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 mysql_main(ipdict,threads):
printPink("crack mysql now...")
print "[*] start crack mysql %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=mysql)
t.setDaemon(True)
t.start()
for ip in ipdict['mysql']:
sp.put((str(ip).split(':')[0],int(str(ip).split(':')[1])))
sp.join()
print "[*] stop crack mysql %s" % time.ctime()
print "[*] crack mysql done,it has Elapsed time:%s " % (time.time()-starttime)
return result