./ircbots/crackbot_mysql.py

0.
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.
166.
167.
168.
169.
170.
171.
#!/usr/bin/env python
#Cracks mysql hash using wordlist, also can add words to the list from channel
#generate hashes and can check wordlist length.
 
#Fill in the information below
#---------------------------------------
HOST = "irc1.netgarage.org"
PORT = "6667"
NICK = "crackb0t_mysql"
CHAN = "#darkc0de"
wordlist = "/home/d3hydr8/words.txt"
#---------------------------------------
 
#Args: 
#!crack <hash>
#!insert <word>
#!hash <word>
#!length 
 
import sys, socket, string, hashlib, re
 
def load_words():
	try:
  		words = open(wordlist, "r").readlines()
	except(IOError): 
  		print "[!] Error: Check your wordlist path\n"
  		sys.exit(1)
	global words
 
def mysql323(clear): 
    # Taken almost verbatim from mysql's source 
    nr = 1345345333 
    add = 7 
    nr2 = 0x12345671 
    retval = "" 
    for c in clear: 
	if c == ' ' or c == '\t': 
	    continue 
	tmp = ord(c) 
	nr ^= (((nr & 63) + add) * tmp) + (nr << 8) 
	nr2 += (nr2 << 8) ^ nr 
	add += tmp 
    res1 = nr & ((1 << 31) - 1) 
    res2 = nr2 & ((1 << 31) - 1) 
    return "%08lx%08lx" % (res1, res2) 
 
def mysqlv5(word):
	s = hashlib.sha1()
	s.update(word)
	s2 = hashlib.sha1()
	s2.update(s.digest())
	return s2.hexdigest()
 
def crack(pw):
	output = ""
	for word in words: 
		word = word.rstrip("\n") 
		if pw == mysql323(word): 
			output = word 
	return output
 
def crack1(pw):
	output = ""
	for word in words:
		word = word.rstrip("\n") 
		if pw == mysqlv5(word): 
			output = word
	return output
 
def insert(word):
	add_list = open(wordlist, "a")
	if word not in words:
		add_list.writelines(word.replace("\n","")+"\n")
		add_list.close()
		load_words()
		return len(words)
	else:
		add_list.close()
		return "[-] word already present"
 
	words.close()
 
print "\n\t   d3hydr8[at]gmail[dot]com CrackBot MySQL v1.0"
print "\t--------------------------------------------------"
 
print "[+] CrackBot MySQL Loaded"
 
load_words()
 
print "[+] Words Loaded:",len(words)
 
readbuffer = ""
 
s=socket.socket( )
s.connect((HOST, int(PORT)))
print "[+] Connected:",HOST+":"+PORT
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s bla :%s\r\n" % (NICK, NICK, NICK))
s.send("JOIN :%s\r\n" % CHAN)
print "[+] Joined:",CHAN,"\n"
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[+] CrackBot MySQL Loaded"))
s.send("PRIVMSG %s :%s%s\r\n" % (CHAN, "[+] Wordlist Length: ",len(words)))
 
while 1:
	readbuffer=readbuffer+s.recv(1024)
    	temp=string.split(readbuffer, "\n")
    	readbuffer=temp.pop( )
 
    	for line in temp:
        	line=string.rstrip(line)
        	line=string.split(line)
		try:
			line[3] = line[3].lower()
 
			if line[3] == ":!crack":
				if line[4] != "None" and len(re.findall("[g-z!@#$%^&^*()<>?]", line[4])) == 0 and int(len(line[4])) in [16,40]:
					print "[+] Cracking:",line[4]
					if len(line[4]) == 16:
						output = crack(line[4])
					elif len(line[4]) == 40:
						output = crack1(line[4])
					else:
						s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[-] Error Occurred"))
					print "[+] Output:",output
					if output != "":
						s.send("PRIVMSG %s :%s%s\r\n" % (CHAN, "[+] cracked: ",output))
					else:
						s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[-] "+line[4]+" : Not Found"))
				else:
					s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[-] improper length"))
 
			if line[3] == ":!insert":
				if len(line[4]) <= 15:
					output = insert(line[4]+"\n")
					if output != "[-] word already present":
						print "[+] Insert:",line[4]
						s.send("PRIVMSG %s :%s%s\r\n" % (CHAN, "[+] insert: ",line[4]))
						s.send("PRIVMSG %s :%s%s\r\n" % (CHAN, "[+] new length: ",output))
					else:
						s.send("PRIVMSG %s :%s\r\n" % (CHAN, output))
				else:
					s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[-] word length to long"))
					s.send("PRIVMSG %s :%s%s\r\n" % (CHAN, "[-] length:", len(line[4])))
 
			if line[3] == ":!hash":
				output = mysqlv5(" ".join(line[4:]))
				s.send("PRIVMSG %s :%s%s%s%s\r\n" % (CHAN, "[+] mysqlv5: "," ".join(line[4:])," == ",output))
				print "[+]"," ".join(line[4:]),"==",output
				output = mysql323(" ".join(line[4:]))
				s.send("PRIVMSG %s :%s%s%s%s\r\n" % (CHAN, "[+] mysql323: "," ".join(line[4:])," == ",output))
				print "[+]"," ".join(line[4:]),"==",output
 
 
			if line[3] == ":!length":
				print "[+] Length:",len(words)
				s.send("PRIVMSG %s :%s%s\r\n" % (CHAN, "[+] wordlist length: ",len(words)))
 
			if line[3] == ":!help":
				s.send("PRIVMSG %s :%s\r\n" % (CHAN, "crackB0t options:"))
				s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[+] !crack <hash> | crack hash"))
				s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[+] !insert <word> | insert word into list"))
				s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[+] !hash <word> | generate hash"))
				s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[+] !length | check wordlist length"))
 
 
		except(IndexError):
			pass
 
        	if(line[0]=="PING"):
          		s.send("PONG %s\r\n" % line[1])
 
 

Back