-
Notifications
You must be signed in to change notification settings - Fork 15
/
gen.py
370 lines (288 loc) · 13.5 KB
/
gen.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
import datetime
import config
import traceback
from logging import info, error, basicConfig, INFO, ERROR
from datetime import date
import time
import pathlib
import uuid
import cloudscraper
import os
class RevGen:
def __init__(self) -> None:
self.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36"
if config.DEVICE_ID == "":
config.DEVICE_ID = str(uuid.uuid4())
self.headers_post = {
'pragma': 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101"',
'accept': 'application/json, text/plain, /',
'sec-ch-ua-mobile': '?0',
'user-agent': self.ua,
'x-device-id': config.DEVICE_ID,
'content-type': 'application/json;charset=UTF-8',
'origin': 'https://business.revolut.com/',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://business.revolut.com/',
'accept-language': 'en-US;q=0.9',
}
self.headers_get = {
'pragma': 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101"',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?0',
'user-agent': self.ua,
'x-device-id': config.DEVICE_ID,
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://business.revolut.com/',
'accept-language': 'en-US;q=0.9',
}
self.s = cloudscraper.create_scraper(requestPreHook=self.pre_hook)
self.csv_location = f'{pathlib.Path(__file__).parent.resolve()}\\cards.csv'
if config.EMAIL == "" or config.PASSWORD == "" and config.REV_TOKEN == "":
raise RuntimeError("Email and Password or Rev Token are empty, supply at least one")
if config.EMAIL != "" and config.PASSWORD != "":
self.login()
self.business_id = self.get_business()
if not self.business_id:
raise RuntimeError("Cannot Get Business API")
if self.kyc_status != "PASSED":
raise RuntimeError("Account Unverified")
self.BASE_URL = config.BASE_URL + f"business/{self.business_id}"
self.get_members()
if config.COPY_ONLY:
self.get_all_cards()
for key,value in self.cards.items():
self.card_id = key
self.card_name = value["name"]
self.card_exp_month = value["expiryDate"].split("/")[0]
self.card_exp_year = value["expiryDate"].split("/")[1]
self.log_info(f"Retrieved Card {self.card_name}")
if config.SMS_VERIFICATION:
self.get_card_details()
else:
for n in range(0, int(config.GEN_NUMBER)):
self.log_info(f"Generating Card {n+config.START_WITH_INDEX}")
self.gen_cards()
self.log_info(f"Generated Card {n+config.START_WITH_INDEX}")
labeled = self.label_cards(n+config.START_WITH_INDEX)
if labeled:
self.log_info(f"Labeled Card {n+config.START_WITH_INDEX}")
self.card_exp_month = f'0{str(date.today().month)}'
self.card_exp_year = str(date.today().year + 5)
if config.SMS_VERIFICATION:
self.get_card_details()
def pre_hook(self, request, method, url, *args, **kwargs):
if hasattr(self,"expires"):
if self.expires < time.time():
self.login()
if not self.s.cookies.get("token", domain="business.revolut.com") and config.REV_TOKEN != "":
self.s.cookies.set("token", config.REV_TOKEN, domain="business.revolut.com")
return method, url, args, kwargs
@staticmethod
def log_info(*args, **kwargs):
os.system("")
timestamp = datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]
st,en = '\033[92m','\033[0m '
output = f"{st}[{str(timestamp)}] {args[0]}{en}"
basicConfig(format="%(message)s", level=INFO)
info(output)
@staticmethod
def log_error(*args, **kwargs):
os.system("")
st,en = '\033[91m','\033[0m '
timestamp = datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]
output = f"{st}[{str(timestamp)}] {args[0]}{en}"
basicConfig(format="%(message)s", level=ERROR)
error(output)
def login(self):
self.log_info(f"Logging in")
json_data = {
'email': config.EMAIL,
'password': config.PASSWORD
}
response = self.s.post(
'https://business.revolut.com/api/signin',
headers=self.headers_post,
json=json_data
)
try:
parsed = response.json()
config.REV_TOKEN = self.s.cookies["token"]
except:
RuntimeError(f"Error Parsing API: {response.status_code} - {response.text}")
if "userId" not in parsed:
raise RuntimeError(f"Cannot Login: {parsed}")
response = self.s.post('https://business.revolut.com/api/2fa/signin/verify', headers=self.headers_post)
try:
parsed = response.json()
verification_token = parsed["verificationTokenId"]
except:
raise RuntimeError(f"Error Parsing API: {response.status_code} - {response.text}")
response = self.s.get(f'https://business.revolut.com/api/verification/{verification_token}/status', headers=self.headers_get)
parsed = response.json()
while parsed["state"] != "VERIFIED":
self.log_info(f"Waiting for App confirmation")
time.sleep(2)
response = self.s.get(f'https://business.revolut.com/api/verification/{verification_token}/status', headers=self.headers_get)
parsed = response.json()
code = parsed["code"]
headers = self.headers_post.copy()
headers["x-verify-code"] = code
verify = self.s.post('https://business.revolut.com/api/2fa/signin/verify', headers=headers)
try:
parsed = verify.json()
self.expires = parsed["expireAt"]
config.REV_TOKEN = self.s.cookies["token"]
except:
raise RuntimeError(f"Error Parsing API: {response.status_code} - {response.text}")
def get_business(self):
self.log_info("Getting Business")
response = self.s.get(
config.CURRENT_USER,
headers=self.headers_get
)
if "This action is forbidden" in response.text:
raise RuntimeError("Token Expired")
try:
parsed = response.json()
self.kyc_status = parsed["kyc"]
business_id = parsed["businessId"]
return business_id
except:
self.log_error(f"Error Parsing API: {response.status_code} - {response.text} - {traceback.format_exc()}")
def get_members(self):
self.log_info("Getting Team Members")
response = self.s.get(
f"{self.BASE_URL}/team/members",
headers=self.headers_get
)
if "This action is forbidden" in response.text:
raise RuntimeError("Token Expired")
try:
parsed = response.json()
self.current_member = [m for m in parsed if m["email"] == config.EMPLOYEE_EMAIL][0]
try:
self.employee_id = self.current_member["employee"]["id"]
except:
self.employee_id = ""
self.user_id = self.current_member["user"]["id"]
except:
self.log_error(f"Error Parsing API: {response.status_code} - {response.text} - {traceback.format_exc()}")
def get_all_cards(self):
response = self.s.get(
f'{self.BASE_URL}/team/members/current-member/cards',
headers=self.headers_get
)
if "This action is forbidden" in response.text:
raise RuntimeError("Token Expired")
try:
self.cards = {}
parsed = response.json()
for x in parsed:
self.cards[x["payload"]["id"]] = {
"name": x["payload"]["name"],
"expiryDate": x["payload"]["expiryDate"],
}
self.user_id = self.current_member["user"]["id"]
except:
self.log_error(f"Error Parsing API: {response.status_code} - {response.text} - {traceback.format_exc()}")
def gen_cards(self):
payload = {
"includedToExpenseManagement":True,
"linkAllAccounts":True,
"email": config.EMPLOYEE_EMAIL,
"employeeId": self.employee_id,
"userId": self.user_id,
"personal":True
}
response = self.s.post(
f'{self.BASE_URL}/card/virtual/order',
headers=self.headers_post,
json=payload
)
if "This action is forbidden" in response.text:
raise RuntimeError("Token Expired")
try:
self.card_id = response.json()["id"]
except:
self.log_error(f"Error Parsing API: {response.status_code} - {response.text} - {traceback.format_exc()}")
def label_cards(self, prefix):
self.log_info("Labeling Card")
payload = {"label": f"{config.CARD_PREFIX} {prefix}"}
self.card_name = f"{config.CARD_PREFIX}{prefix}"
response = self.s.patch(
f'{self.BASE_URL}/card/{self.card_id}/label',
headers=self.headers_post,
json=payload
)
try:
return response.json()["state"] == "ACTIVE"
except:
self.log_error(f"Error Parsing API: {response.status_code} - {response.text} - {traceback.format_exc()}")
def send_sms(self):
resp_code = 'resp'
print(f'[{self.card_name}] Sending SMS...')
while not '"Verification required","code":9014,"factor":"SMS"' in resp_code:
response = self.s.get(
f"{self.BASE_URL}/card/{self.card_id}/image/unmasked?encrypt=false",
headers=self.headers_get
)
resp_code = response.text
if '"Cannot create a new verification code at that moment","code":9015' in resp_code:
print(f'[{self.card_name}] Error sending SMS waiting 5 seconds...')
time.sleep(5)
print(f'[{self.card_name}] SMS code sent')
def get_card_details(self):
self.send_sms()
Resend = True
while Resend:
self.sms_code = input(f'[{self.card_name}] Enter sms code (type "1" to send sms again): ')
if self.sms_code == "1":
self.send_sms()
else:
Resend = False
self.verify_headers = {
'pragma': 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua': '"Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?0',
'user-agent': self.ua,
'x-device-id': config.DEVICE_ID,
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://business.revolut.com/',
'accept-language': 'en-US;q=0.9',
'cookie': f'token={config.REV_TOKEN}',
'x-verify-code': f'{self.sms_code}',
}
response = self.s.get(
f"{self.BASE_URL}/card/{self.card_id}/image/unmasked?encrypt=false",
headers=self.verify_headers
)
try:
self.card_num = response.json()["pan"]
self.card_cvv = response.json()["cvv"]
self.write_card_details()
except:
choice = input(f'[{self.card_name}] Wrong sms code wanna try again? y/n: ')
if choice == "y":
self.get_card_details()
else:
return
def write_card_details(self):
with open(self.csv_location, 'a') as fd:
fd.write(f'\n{self.card_name},{self.card_num},{self.card_exp_month},{self.card_exp_year},{self.card_cvv}')
if __name__ == "__main__":
pass
RevGen()