-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathneutrosint.py
468 lines (378 loc) · 18.5 KB
/
neutrosint.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.common.exceptions import UnexpectedAlertPresentException, TimeoutException
import time
import os
import re
import json
import requests
import dns.resolver
from datetime import datetime
from colorama import Fore, Style
class NeutrOSINT():
def __init__(self):
self.driver = None
self.username = None
self.password = None
self.emails = []
self.time = 16
self.output_file = None
self.proxy = {}
self.light = False
self.max_retries = 0
def banner(self):
print("""
██████ █████ █████ ███████ █████████ █████ ██████ █████ ███████████ ████████
░░██████ ░░███ ░░███ ███░░░░░███ ███░░░░░███░░███ ░░██████ ░░███ ░█░░░███░░░█ ███░░░░███
░███░███ ░███ ██████ █████ ████ ███████ ████████ ███ ░░███░███ ░░░ ░███ ░███░███ ░███ ░ ░███ ░ █████ █████░░░ ░███
░███░░███░███ ███░░███░░███ ░███ ░░░███░ ░░███░░███░███ ░███░░█████████ ░███ ░███░░███░███ ░███ ░░███ ░░███ ███████
░███ ░░██████ ░███████ ░███ ░███ ░███ ░███ ░░░ ░███ ░███ ░░░░░░░░███ ░███ ░███ ░░██████ ░███ ░███ ░███ ███░░░░
░███ ░░█████ ░███░░░ ░███ ░███ ░███ ███ ░███ ░░███ ███ ███ ░███ ░███ ░███ ░░█████ ░███ ░░███ ███ ███ █
█████ ░░█████░░██████ ░░████████ ░░█████ █████ ░░░███████░ ░░█████████ █████ █████ ░░█████ █████ ░░█████ ░██████████
░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░ ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░░
""")
def setup(self):
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
if(len(self.proxy) != 0):
chrome_options.add_argument('--proxy-server=%s' % self.proxy)
service = Service(ChromeDriverManager().install())
try:
self.driver = webdriver.Chrome(service=service, options=chrome_options)
except:
print(f"{Fore.RED}[-] Error setting up the driver...\n")
exit()
self.driver.get('https://account.protonmail.com/login')
def set_email(self, email):
self.emails = [ email ]
def set_username(self, username):
self.username = username
def set_password(self, password):
self.password = password
def set_output_file(self, file):
self.output_file = file
def set_proxy(self, proxy):
self.proxy = proxy
def set_light_mode(self, light):
self.light = light
def load_emails(self, file):
try:
handle = open(file, 'r')
lines = handle.read().splitlines()
for line in lines:
self.emails.append(line)
handle.close()
#Tell the user the API limit will be exceeded
if(len(self.emails) > 100):
if(self.light):
print(f"{Fore.YELLOW}[?] Warning! There are more than 100 email addresses to check. The API's limit is 100 requests. All the email addresses won't be tested. You can either use the credentials mode (--username and --password) or use a proxy (--proxy)\n")
except:
print(f"{Fore.RED}[-] Unable to load emails")
exit()
def write_to_file(self, data):
try:
handle = open(self.output_file, "a")
handle.write(data)
handle.close()
except:
print(f"{Fore.RED}[-] Unable to save data to file")
exit()
def login(self):
try:
print(f"{Fore.YELLOW}[?] Connecting to ProtonMail with credentials...")
#Find the username field
element = WebDriverWait(self.driver, self.time).until(EC.presence_of_element_located((By.ID, 'username')))
user_element = self.driver.find_element(By.ID,'username')
user_element.send_keys(self.username)
#Find the password field
element = WebDriverWait(self.driver, self.time).until(EC.presence_of_element_located((By.ID, 'password')))
password_element = self.driver.find_element(By.ID,'password')
password_element.send_keys(self.password)
#Submit the form
password_element.submit()
#Wait to connect to our account
time.sleep(self.time)
print(f"{Fore.GREEN}[+] Connected to ProtonMail\n")
except:
print(f"{Fore.RED}[-] Error when connecting to ProtonMail...")
exit()
def clear_element(self, method, element_path):
try:
wait_element = WebDriverWait(self.driver, self.time).until(EC.presence_of_element_located((method, element_path)))
element = self.driver.find_element(method, element_path)
element.clear()
except:
print(f"{Fore.RED}[-] Unable to clear the element")
exit()
def new_email(self):
try:
print(f"{Fore.YELLOW}[?] Accessing 'New email' to check email addresses...")
#Retrieve the "New email" button
element = WebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//button[@class="button button-large button-solid-norm w100 no-mobile"]')))
new_email_element = self.driver.find_element(By.XPATH, '//button[@class="button button-large button-solid-norm w100 no-mobile"]')
new_email_element.click()
time.sleep(self.time)
#Retrieve the "To" field to insert emails
element = WebDriverWait(self.driver, self.time).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div[4]/div/div/div/div/div/div[2]/div/div/div/div/div/div/input')))
to_email_element = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[4]/div/div/div/div/div/div[2]/div/div/div/div/div/div/input')
print(f"{Fore.YELLOW}[?] Checking email addresses...{Style.RESET_ALL}\n")
#Create a copy of emails to avoid the modifications
tmp_emails_array = self.emails[:]
while(len(tmp_emails_array) > 100):
#Check the first 100 emails
emails_to_check_str = ','.join(tmp_emails_array[:100])
#Convert list to string + add "," at the end (for the last occurence to be updated)
emails_to_check_str += ','
#Write all emails in the "To" field and wait until protonmail detects if they exist or not
to_email_element.send_keys(emails_to_check_str)
self.check_emails(tmp_emails_array[:100])
#Remove the first 100 email addresses
tmp_emails_array = tmp_emails_array[100:]
#Clear the 'To' field
to_email_element.clear()
#If we are here it means there are less than 100 email addresses
emails_to_check_str = ','.join(tmp_emails_array)
#Convert list to string + add "," at the end (for the last occurence to be updated)
emails_to_check_str += ','
#Write all emails in the "To" field and wait until protonmail detects if they exist or not
to_email_element.send_keys(emails_to_check_str)
self.check_emails(tmp_emails_array)
except TimeoutException:
if(self.max_retries == 1):
print(f"{Fore.RED}[-] Too many retries. Try to launch the script again")
exit()
self.max_retries = self.max_retries + 1
print(f"{Fore.RED}[-] Unable to access new email to check email addresses. Trying again...")
self.new_email()
def extract_timestamp(self, email):
#We use requests here because selenium doesn't work???
source_code = requests.get('https://api.protonmail.ch/pks/lookup?op=index&search=' + email)
try:
timestamp = re.sub(':', '', re.search(':[0-9]{10}::', source_code.text).group(0))
creation_date = datetime.fromtimestamp(int(timestamp))
return creation_date
except AttributeError:
#print(Fore.RED + "[-] Error! Impossible to retrieve the creation date. Maybe API restriction...")
return None
def is_syntax_correct(self, email):
return re.match('([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+', email)
def is_proton_domain(self, email):
return email.split("@")[1] in ["protonmail.com", "proton.me"]
def check_domain(self, email):
try:
if(not self.is_proton_domain(email)):
for data in dns.resolver.query(email.split("@")[1], "MX"):
if("protonmail" in data.to_text()):
return True
return False
except dns.resolver.NXDOMAIN:
print(f"{Fore.RED}[-] Domain doesn't exist...")
exit()
#Pass emails as argument to use for printing (pass tmp_emails_array)
def check_emails(self, emails):
try:
#Retrieve the emails we inserted in the input field
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div[4]/div/div/div/div/div/div[2]/div/div/div/div/div/div')))
elements_to_loop = self.driver.find_elements(By.XPATH, '/html/body/div[1]/div[4]/div/div/div/div/div/div[2]/div/div/div/div/div/div')
#Remove the last div (which is always null)
elements_to_loop = elements_to_loop[:-1]
count = 0
time.sleep(1)
#Loop over all divs
for item in elements_to_loop:
if(not self.is_syntax_correct(emails[count])):
print(f"{Fore.RED}[-] Invalid format: {Style.RESET_ALL}{emails[count]}")
count = count + 1
continue
#foreach retrieve their classes
class_str = item.get_attribute('class')
print()
if("invalid" in class_str):
if(self.output_file != None):
self.write_to_file(f"Proton email does not exist: {emails[count]}\n")
print(f"{Fore.RED}[-] Proton email does not exist: {Style.RESET_ALL}{emails[count]}")
#Check if domain is linked to protonmail
if(self.check_domain(emails[count])):
domain = emails[count].split("@")[1]
if(self.output_file != None):
self.write_to_file(f"Valid business domain: {domain}, catch-all is not configured\n")
print(f"{Fore.GREEN}[+] Valid business domain: {Style.RESET_ALL}{domain}, {Fore.RED}catch-all is not configured{Style.RESET_ALL}")
count = count + 1
continue
else:
creation_date = self.extract_timestamp(emails[count])
if(creation_date == None and not self.check_domain(emails[count])):
if(self.output_file != None):
self.write_to_file(f"Not protonmail address, can't determine validity: {emails[count]}\n")
print(f"{Fore.YELLOW}[?] Not protonmail address, can't determine validity: {Style.RESET_ALL}{emails[count]}")
count = count + 1
continue
else:
#Check if business domain
if(self.check_domain(emails[count])):
domain = emails[count].split("@")[1]
if(self.output_file != None):
self.write_to_file(f"Valid business domain: {domain}\n")
print(f"{Fore.GREEN}[+] Valid business domain: {Style.RESET_ALL}{domain}")
print(f"{Fore.YELLOW}[?] Checking catch-all setup...{Style.RESET_ALL}")
result_email = self.get_catch_all_address(emails[count])
#If catch-all functionality is enabled
if(result_email != None):
#If email is already a source address of catch-all configuration
if(result_email == True):
if(self.output_file != None):
self.write_to_file(f"Valid email: {emails[count]} - Creation date: {str(creation_date)}\n")
print(f"{Fore.GREEN}[+] Valid email: {Style.RESET_ALL}{emails[count]} - Creation date: {str(creation_date)}")
else:
if(self.output_file != None):
self.write_to_file(f"Catch-all configured. Here is the source address: {result_email} - Creation date: {str(creation_date)}\n")
print(f"{Fore.GREEN}[+] Catch-all configured. Here is the source address: {Style.RESET_ALL}{result_email} - Creation date: {str(creation_date)}")
else:
if(self.output_file != None):
self.write_to_file(f"Valid email: {emails[count]} - Creation date: {str(creation_date)}\n")
print(f"{Fore.GREEN}[+] Valid email: {Style.RESET_ALL}{emails[count]} - Creation date: {str(creation_date)}")
count = count + 1
continue
#Basic protonmail accounts
if(self.output_file != None):
self.write_to_file(f"Valid email: {emails[count]} - Creation date: {str(creation_date)}\n")
print(f"{Fore.GREEN}[+] Valid email: {Style.RESET_ALL}{emails[count]} - Creation date: {str(creation_date)}")
count = count + 1
except UnexpectedAlertPresentException:
print(f"{Fore.RED}[-] Unable to check emails addreses...")
exit()
except IndexError:
pass
def close(self):
self.driver.close()
def get_catch_all_address(self, email):
url = "https://mail-api.proton.me/pks/lookup?op=index&search="
catch_all_trigger = "lxitpwo308p3dacnsjsq"
domain = email.split("@")[1]
built_url = f"{url}{catch_all_trigger}@{domain}"
response = requests.get(built_url)
if(response.status_code == 2028):
print(f"{Fore.RED}[-] Too many requests. Try with a proxy/VPN or wait some time...")
exit()
if(catch_all_trigger in response.text):
return None
else:
source_email = response.text.split("uid:")[1].split(" ")[0]
if(source_email == email):
return True
else:
return source_email
def generate_auth_cookie(self):
url_session = "https://account.proton.me/api/auth/v4/sessions"
url_cookies = "https://account.proton.me/api/core/v4/auth/cookies"
data_session = {
"x-pm-appversion":"web-account@5.0.153.3",
"x-pm-locale":"en_US",
"x-enforce-unauthsession":"true"
}
response = requests.post(url_session, headers=data_session)
json_dump = json.loads(response.text)
access_token = json_dump['AccessToken']
refresh_token = json_dump['RefreshToken']
uid = json_dump['UID']
data_cookie = {
"x-pm-appversion":"web-account@5.0.153.3",
"x-pm-locale":"en_US",
"x-pm-uid":uid,
"Authorization":f"Bearer {access_token}"
}
request_data = {
"GrantType": "refresh_token",
"Persistent": 0,
"RedirectURI": "https://protonmail.com",
"RefreshToken": refresh_token,
"ResponseType": "token",
"State": "C72g4sTNltu4TAL5bUQlnvUT",
"UID": uid
}
response = requests.post(url_cookies, headers=data_cookie, json=request_data)
for cookie in response.cookies:
if("AUTH" in str(cookie)):
auth_cookie = str(cookie).split(" ")[1]
break
return uid,auth_cookie
def request_api(self):
for email in self.emails:
#First check if syntax is correct
if(not self.is_syntax_correct(email)):
if(self.output_file != None):
self.write_to_file(f"Invalid format: {email}\n")
print(f"{Fore.RED}[-] Invalid format: {Style.RESET_ALL}{email}")
continue
try:
uid, auth_cookie = self.generate_auth_cookie()
request = requests.get("https://account.proton.me/api/core/v4/users/available",
headers={
"x-pm-appversion":"web-account@5.0.153.3",
"x-pm-locale":"en_US",
"x-pm-uid":uid,
"Cookie":auth_cookie
},
params={
"Name":email,
"ParseDomain":"1"
},
proxies=self.proxy)
#Detected as valid but no suggestion means it doesn't exist
if('"Suggestions":[]' in request.text):
if(self.output_file != None):
self.write_to_file(f"Proton email not exists: {email}\n")
print(f"{Fore.RED}[-] Proton email not exists: {Style.RESET_ALL}{email}")
elif(request.status_code == 409):
creation_date = self.extract_timestamp(email)
if(self.output_file != None):
self.write_to_file(f"Valid email: {email} - Creation date: {str(creation_date)}\n")
print(f"{Fore.GREEN}[+] Valid email: {Style.RESET_ALL}{email} - Creation date: {str(creation_date)}")
#Return code 429 = API limit exceeded
elif(request.status_code == 429):
print(f"{Fore.RED}[-] API requests limit exceeded... Try with the credentials mode (--username and --password) or use a proxy (--proxy)")
else:
if(self.check_domain(email)):
result_email = self.get_catch_all_address(email)
if(result_email != None):
creation_date = self.extract_timestamp(email)
if(result_email == True):
if(self.output_file != None):
self.write_to_file(f"Valid email (custom domain): {email} - Creation date: {str(creation_date)}\n")
print(f"{Fore.GREEN}[+] Valid email (custom domain): {Style.RESET_ALL}{email} - Creation date: {str(creation_date)}")
else:
if(self.output_file != None):
self.write_to_file(f"Business protonmail domain. Catch-all configured. Here is the source address: {result_email} - Creation date: {str(creation_date)}\n")
print(f"{Fore.GREEN}[+] Business protonmail domain. Catch-all configured. Here is the source address: {Style.RESET_ALL}{result_email} - Creation date: {str(creation_date)}")
else:
if(self.output_file != None):
self.write_to_file(f"Valid proton domain (business), can't check validity of email: {email}\n")
print(f"{Fore.GREEN}[+] Valid proton domain (business), can't check validity of email: {Style.RESET_ALL}{email}")
continue
if(self.output_file != None):
self.write_to_file(f"Proton email not exists: {email}\n")
print(f"{Fore.RED}[-] Proton email not exists: {Style.RESET_ALL}{email}")
except:
print(f"{Fore.RED}[-] Error when requesting the API")
exit()
def run(self):
try:
self.banner()
#Check if we are running in light mode
if(self.light):
self.request_api()
print(f"\nFor business emails, please use the selenium mode to check the validity (-u/-p).")
else:
self.setup()
self.login()
self.new_email()
self.close()
except KeyboardInterrupt:
print(f"{Fore.YELLOW}[?] Exiting...{Style.RESET_ALL}\n")
return