-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-mega.py
233 lines (202 loc) · 8.89 KB
/
generate-mega.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
#!/usr/bin/env python
import re
import json
import faker
import random
import string
import subprocess
import time
import argparse
import pickle
import requests
import logging
from base64 import urlsafe_b64decode
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from google.auth.transport.requests import Request
from email.utils import parseaddr
from datetime import datetime, timezone
MEGATOOLS = r"E:\megatools-1.11.1.20230212-win64\megatools.exe"
MAIL = "youremailbefore@sign"
email_data = {}
log_filename = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + '_mega.log'
logging.basicConfig(filename=log_filename, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Function to load credentials
def load_credentials():
try:
logging.info("Loading Credentials")
with open('token.pickle', 'rb') as token_file:
credentials_info = pickle.load(token_file)
client_id = credentials_info['client_id']
client_secret = credentials_info['client_secret']
refresh_token = credentials_info['refresh_token']
creds = Credentials(
None, # No access token
refresh_token=refresh_token,
token_uri="https://oauth2.googleapis.com/token",
client_id=client_id,
client_secret=client_secret
)
logging.info("Credentials Loaded")
# Refresh the token if it's expired
if creds.expired and creds.refresh_token:
logging.error("Credentials expired")
return "Rerun refresh-token.py file."
return creds
except FileNotFoundError:
error_message = "File 'token.pickle' not found."
logging.error(error_message)
return
# Function to generate fake email
def generate_fake_email():
global email_data
try:
logging.info("Generating Fake Email")
fake = faker.Faker()
real_name = fake.name()
random_thing = ''.join(random.choices(string.ascii_letters + string.digits, k=random.randint(5, 10)))
email = f"{MAIL}+{random_thing}@gmail.com" # Assuming MAIL is defined somewhere
password = fake.password()
email_data = {
"real_name": real_name,
"email": email,
"password": password
}
logging.info("Generated Fake Email Successfully")
logging.info(email_data)
except Exception as e:
error_message = f"{type(e).__name__}: {str(e)}"
logging.error(error_message)
return
# Function to register on Mega
def register_mega(name, email, password):
try:
logging.info("Registering on MEGA")
register_command = subprocess.run(fr'{MEGATOOLS} reg --scripted --register --email "{email}" --name "{name}" --password "{password}"', shell=True, capture_output=True, text=True)
logging.info(register_command)
register_output = register_command.stdout
register_error = register_command.stderr
if register_error:
logging.error("Couldn't Register MEGA Account")
raise ValueError(register_error)
logging.info("Registered MEGA Account Successfully")
return register_output
except Exception as e:
error_message = f"{type(e).__name__}: {str(e)}"
logging.error(error_message)
return
# Function to verify Mega registration
def verify_mega(register, link):
try:
logging.info("Verifying MEGA Account")
verify_replace_link = register.replace("megatools", MEGATOOLS).replace("@LINK@", link)
logging.info(verify_replace_link)
verify_command = subprocess.run(verify_replace_link, shell=True, capture_output=True, text=True)
verify_output = verify_command.stdout
verify_error = verify_command.stderr
if verify_error:
logging.error("Couldn't verify MEGA Account")
raise ValueError(verify_error)
logging.info(verify_output)
return json.dumps({
"email": email_data.get('email'),
"password": email_data.get('password'),
"real_name": email_data.get('real_name')
})
except Exception as e:
error_message = f"{type(e).__name__}: {str(e)}"
logging.error(error_message)
return
# Function to check email
def check_email(creds, email):
try:
logging.info("Checking Email for Verification Link")
# Build the Gmail service
service = build('gmail', 'v1', credentials=creds)
# Define the recipient email address
recipient_email = email
# List to store email details
emails = []
# Get messages from the inbox label
logging.info("Getting Emails")
results = service.users().messages().list(userId='me', labelIds=['INBOX'], q=f"to:{recipient_email}").execute()
messages = results.get('messages', [])
# Iterate over each message and get its content
for message in messages:
msg = service.users().messages().get(userId='me', id=message['id'], format='full').execute()
headers = msg['payload']['headers']
subject = next((header['value'] for header in headers if header['name'] == 'Subject'), None)
if subject and "MEGA email verification required" in subject:
payload = msg['payload']
if 'parts' in payload:
parts = payload['parts']
body = None
for part in parts:
if part['mimeType'] == 'text/plain':
body_data = part['body']['data']
body = urlsafe_b64decode(body_data).decode()
break
else:
body_data = payload['body']['data']
body = urlsafe_b64decode(body_data).decode()
if body:
urls = re.findall(r'(https?://\S+)', body)
for url in urls:
if 'mega.nz' in url:
email_details = {
"subject": subject,
"from": parseaddr(next(header['value'] for header in headers if header['name'] == 'From'))[1],
"to": parseaddr(next(header['value'] for header in headers if header['name'] == 'To'))[1],
"date": next(header['value'] for header in headers if header['name'] == 'Date'),
"url": url
}
emails.append(email_details)
return emails
except Exception as e:
error_message = f"{type(e).__name__}: {str(e)}"
logging.error(error_message)
return
# Function to store email data
def store_email_data(email_id, password):
try:
logging.info("Storing MEGA Account to accounts.txt")
with open('accounts.txt', 'a') as txtfile:
txtfile.write(f"{email_id}:{password}\n")
logging.info("Added MEGA Account to accounts.txt")
except Exception as e:
error_message = f"{type(e).__name__}: {str(e)}"
logging.error(error_message)
# Function to generate Mega accounts
def generate_mega_accounts(num):
try:
creds = load_credentials()
if creds is None:
raise Exception("Credentials not found or expired, run refresh-token.py file.")
start_time = time.time()
for i in range(num):
generate_fake_email() # Generate mails and password
name = email_data.get('real_name')
email_id = email_data.get('email')
password = email_data.get('password')
register = register_mega(name, email_id, password) # Register Mega account
verification_mail = None
while True:
verification_mail = check_email(creds ,email_data.get('email')) # Get Verification mail
if (len(verification_mail) != 0):
break
if time.time() - start_time >= 600:
raise ValueError("Timeout: 10 minutes elapsed. Exiting loop.")
time.sleep(10)
account = verify_mega(register, verification_mail[0].get('url')) # Verify Mega account
store_email_data(email_id, password) # Add account to json file
print(account)
email_data.clear() # Clear the dict
except Exception as e:
error_message = f"{type(e).__name__}: {str(e)}"
logging.error(error_message)
return
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate Mega Accounts")
parser.add_argument("--n", type=int, default=1, help="The number of mega accounts to generate")
args = parser.parse_args()
generate_mega_accounts(args.n)