-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·117 lines (95 loc) · 3.52 KB
/
main.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
#!/usr/bin/env python3
import asyncio
import configparser
import random
import mintotp
from pyppeteer import launch
# protonmail login site url
url = 'https://mail.protonmail.com/login'
# parsing values from secrets.cfg file
config = configparser.ConfigParser()
config.read('.secrets.cfg')
username = config.get("credentials", "username")
password = config.get("credentials", "password")
# otp_seet = None if no value has been set on secrets.cfg
try:
otp_seed = config.get("credentials", "otp_seed")
except Exception:
otp_seed = None
# css selectors definition
username_selector = '#username'
password_selector = '#password'
otp_selector = '#twoFactorCode'
loginBtn_selector = '#login_btn'
loginBtn2fa_selector = '#login_btn_2fa'
firstMessage_selector = 'div.conversation:nth-child(1) > \
div:nth-child(5) > h4:nth-child(1)'
# screenshot file name settings
screenshotName = 'protonmail'
screenshotPath = "./screenshots/"
screenshotFileName = None
screenshotCount = 1
# pyppeteer settings
windowWidth = 1768
windowHeigth = 1024
minClickTime = 700 # Min click delay (ms)
maxClickTime = 2000 # Max click delay (ms)
def randomNum(minTime, maxTime):
clickDelayMs = random.randrange(minClickTime, maxClickTime, 1)
return clickDelayMs
def takeScreenshot():
global screenshotCount
global screenshotFileName
screenshotFileName = screenshotPath + str(screenshotCount) + \
'-' + screenshotName + '.png'
print(' > Screenshot ' + str(screenshotCount) +
': ' + screenshotFileName)
screenshotCount = screenshotCount + 1
return
async def main():
browser = await launch(headless=True)
page = await browser.newPage()
await page.setViewport({'width': windowWidth, 'height': windowHeigth})
await page.emulateMedia('screen')
# Open login site
await page.goto(url)
takeScreenshot()
await page.screenshot({'path': screenshotFileName,
'fullPage': False,
'webkit-print-color-adjust': True})
# Enter username
await page.click(username_selector,
delay=randomNum(minClickTime, maxClickTime))
await page.keyboard.type(username)
# Enter password
await page.click(password_selector,
delay=randomNum(minClickTime, maxClickTime))
await page.keyboard.type(password)
# Click login button
await page.click(loginBtn_selector,
delay=randomNum(minClickTime, maxClickTime))
# Enters otp if opt_seed properly configured
if otp_seed is not None:
await page.waitForSelector(otp_selector)
await page.click(otp_selector,
delay=randomNum(minClickTime, maxClickTime))
currentOtp = mintotp.totp(otp_seed)
await page.keyboard.type(currentOtp)
print(" > OTP: " + currentOtp)
takeScreenshot()
await page.screenshot({'path': screenshotFileName,
'fullPage': False,
'webkit-print-color-adjust': True})
await page.click(loginBtn2fa_selector,
delay=randomNum(minClickTime, maxClickTime))
else:
print(" > No otp_seed found")
# Opening inbox
await page.waitForSelector(firstMessage_selector)
takeScreenshot()
await page.screenshot({'path': screenshotFileName,
'fullPage': False,
'webkit-print-color-adjust': True})
await browser.close()
print(" > Browser closed")
asyncio.get_event_loop().run_until_complete(main())