Tuanxhxjxjxjxjxjdjd commited on
Commit
b238c4f
·
verified ·
1 Parent(s): c39a86f

Add code/1753530028471_a_1.js

Browse files
Files changed (1) hide show
  1. code/1753530028471_a_1.js +239 -0
code/1753530028471_a_1.js ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const deviceID = require('uuid');
2
+ const adid = require('uuid');
3
+ const { TOTP } = require("totp-generator");
4
+ const axios = require("axios");
5
+ const logger = require("./b");
6
+
7
+ const ANDROID_DEVICES = [
8
+ { model: "Pixel 6", build: "SP2A.220505.002" },
9
+ { model: "Pixel 5", build: "RQ3A.210805.001.A1" },
10
+ { model: "Samsung Galaxy S21", build: "G991USQU4AUDA" },
11
+ { model: "OnePlus 9", build: "LE2115_11_C.48" },
12
+ { model: "Xiaomi Mi 11", build: "RKQ1.200826.002" }
13
+ ];
14
+
15
+ function getRandomDevice() {
16
+ const device = ANDROID_DEVICES[Math.floor(Math.random() * ANDROID_DEVICES.length)];
17
+ return {
18
+ userAgent: `Dalvik/2.1.0 (Linux; U; Android 11; ${device.model} Build/${device.build})`,
19
+ device
20
+ };
21
+ }
22
+
23
+ async function getCookie({ username, password, twofactor = '0', _2fa, i_user }) {
24
+ try {
25
+ const androidDevice = getRandomDevice();
26
+ const device_id = deviceID.v4();
27
+ const family_device_id = deviceID.v4();
28
+ const machine_id = randomString(24);
29
+ const form = {
30
+ adid: adid.v4(),
31
+ email: username,
32
+ password: password,
33
+ format: 'json',
34
+ device_id: device_id,
35
+ cpl: 'true',
36
+ family_device_id: family_device_id,
37
+ locale: 'en_US',
38
+ client_country_code: 'US',
39
+ credentials_type: 'device_based_login_password',
40
+ generate_session_cookies: '1',
41
+ generate_analytics_claim: '1',
42
+ generate_machine_id: '1',
43
+ currently_logged_in_userid: '0',
44
+ irisSeqID: 1,
45
+ try_num: "1",
46
+ enroll_misauth: "false",
47
+ meta_inf_fbmeta: "NO_FILE",
48
+ source: 'login',
49
+ machine_id: machine_id,
50
+ fb_api_req_friendly_name: 'authenticate',
51
+ fb_api_caller_class: 'com.facebook.account.login.protocol.Fb4aAuthHandler',
52
+ api_key: '882a8490361da98702bf97a021ddc14d',
53
+ access_token: '350685531728|62f8ce9f74b12f84c123cc23437a4a32',
54
+ advertiser_id: adid.v4(),
55
+ device_platform: 'android',
56
+ app_version: '392.0.0.0.66',
57
+ network_type: 'WIFI'
58
+ };
59
+
60
+ form.sig = encodesig(sort(form));
61
+
62
+ const options = {
63
+ url: 'https://b-graph.facebook.com/auth/login',
64
+ method: 'post',
65
+ data: form,
66
+ transformRequest: [(data) => require('querystring').stringify(data)],
67
+ headers: {
68
+ 'content-type': 'application/x-www-form-urlencoded',
69
+ 'x-fb-friendly-name': form["fb_api_req_friendly_name"],
70
+ 'x-fb-http-engine': 'Liger',
71
+ 'user-agent': androidDevice.userAgent,
72
+ 'x-fb-connection-type': 'WIFI',
73
+ 'authorization': `OAuth ${form.access_token}`
74
+ }
75
+ };
76
+
77
+ return new Promise((resolve) => {
78
+ axios.request(options).then(async(response) => {
79
+ try {
80
+ const appstate = response.data.session_cookies.map(cookie => ({
81
+ key: cookie.name,
82
+ value: cookie.value,
83
+ domain: cookie.domain,
84
+ path: cookie.path
85
+ }));
86
+
87
+ // ✅ Chỉ thêm i_user nếu được truyền vào
88
+ if (i_user) {
89
+ appstate.push({
90
+ key: 'i_user',
91
+ value: i_user,
92
+ domain: '.facebook.com',
93
+ path: '/'
94
+ });
95
+ }
96
+
97
+ const tokenOptions = {
98
+ url: `https://api.facebook.com/method/auth.getSessionforApp?format=json&access_token=${response.data.access_token}&new_app_id=275254692598279`,
99
+ method: 'get',
100
+ headers: {
101
+ 'user-agent': androidDevice.userAgent,
102
+ 'authorization': `OAuth ${response.data.access_token}`
103
+ }
104
+ };
105
+
106
+ const tokenV6D7Response = await axios.request(tokenOptions);
107
+
108
+ resolve({
109
+ appstate,
110
+ access_token: response.data.access_token,
111
+ access_token_eaad6v7: tokenV6D7Response.data.access_token,
112
+ device_info: {
113
+ model: androidDevice.device.model,
114
+ user_agent: androidDevice.userAgent
115
+ }
116
+ });
117
+ } catch (e) {
118
+ logger(`Login error: ${e.message}`, '[ LOGIN ERROR ]');
119
+ resolve({ status: false, message: "Please enable 2FA and try again!" });
120
+ }
121
+ }).catch(async (error) => {
122
+ try {
123
+ const data = error.response.data.error.error_data;
124
+ let twoFactorCode;
125
+ if (_2fa && _2fa !== "0") {
126
+ twoFactorCode = _2fa;
127
+ } else if (twofactor && twofactor !== "0") {
128
+ try {
129
+ logger('Đang xử lý 2FA', '[ AUTO LOGIN ]');
130
+ const cleanSecret = decodeURI(twofactor).replace(/\s+/g, '').toUpperCase();
131
+ const { otp } = TOTP.generate(cleanSecret);
132
+ twoFactorCode = otp;
133
+ } catch (e) {
134
+ resolve({ status: false, message: 'Invalid 2FA secret key' });
135
+ return;
136
+ }
137
+ } else {
138
+ resolve({ status: false, message: 'Please provide 2FA code or secret key' });
139
+ return;
140
+ }
141
+
142
+ const twoFactorForm = {
143
+ ...form,
144
+ twofactor_code: twoFactorCode,
145
+ encrypted_msisdn: "",
146
+ userid: data.uid,
147
+ machine_id: data.machine_id || machine_id,
148
+ first_factor: data.login_first_factor,
149
+ credentials_type: "two_factor"
150
+ };
151
+ twoFactorForm.sig = encodesig(sort(twoFactorForm));
152
+ options.data = twoFactorForm;
153
+
154
+ try {
155
+ const twoFactorResponse = await axios.request(options);
156
+ const appstate = twoFactorResponse.data.session_cookies.map(cookie => ({
157
+ key: cookie.name,
158
+ value: cookie.value,
159
+ domain: cookie.domain,
160
+ path: cookie.path
161
+ }));
162
+
163
+ if (i_user) {
164
+ appstate.push({
165
+ key: 'i_user',
166
+ value: i_user,
167
+ domain: '.facebook.com',
168
+ path: '/'
169
+ });
170
+ }
171
+
172
+ const tokenOptions = {
173
+ url: `https://api.facebook.com/method/auth.getSessionforApp?format=json&access_token=${twoFactorResponse.data.access_token}&new_app_id=275254692598279`,
174
+ method: 'get',
175
+ headers: {
176
+ 'user-agent': androidDevice.userAgent,
177
+ 'authorization': `OAuth ${twoFactorResponse.data.access_token}`
178
+ }
179
+ };
180
+
181
+ const tokenV6D7Response = await axios.request(tokenOptions);
182
+
183
+ resolve({
184
+ appstate,
185
+ access_token: twoFactorResponse.data.access_token,
186
+ access_token_eaad6v7: tokenV6D7Response.data.access_token,
187
+ device_info: {
188
+ model: androidDevice.device.model,
189
+ user_agent: androidDevice.userAgent
190
+ }
191
+ });
192
+ } catch (requestError) {
193
+ logger(`Lỗi request 2FA: ${requestError.message}`, '[ 2FA ERROR ]');
194
+ resolve({ status: false, message: 'Failed to authenticate with 2FA code. Please try again.' });
195
+ }
196
+ } catch (twoFactorError) {
197
+ logger(`Lỗi xử lý 2FA: ${twoFactorError.message}`, '[ 2FA ERROR ]');
198
+ resolve({ status: false, message: 'Two-factor authentication failed. Check your credentials.' });
199
+ }
200
+ });
201
+ });
202
+ } catch (e) {
203
+ logger(`Lỗi chung: ${e.message}`, '[ ERROR ]');
204
+ return { status: false, message: 'Incorrect username or password.' };
205
+ }
206
+ }
207
+
208
+ function randomString(length) {
209
+ length = length || 10;
210
+ let char = 'abcdefghijklmnopqrstuvwxyz';
211
+ let result = char.charAt(Math.floor(Math.random() * char.length));
212
+ for (let i = 0; i < length - 1; i++) {
213
+ result += 'abcdefghijklmnopqrstuvwxyz0123456789'.charAt(Math.floor(36 * Math.random()));
214
+ }
215
+ return result;
216
+ }
217
+
218
+ function encodesig(string) {
219
+ let data = '';
220
+ Object.keys(string).forEach((key) => {
221
+ data += `${key}=${string[key]}`;
222
+ });
223
+ return md5(data + '62f8ce9f74b12f84c123cc23437a4a32');
224
+ }
225
+
226
+ function md5(string) {
227
+ return require('crypto').createHash('md5').update(string).digest('hex');
228
+ }
229
+
230
+ function sort(string) {
231
+ const sortedKeys = Object.keys(string).sort();
232
+ let sortedData = {};
233
+ for (const key of sortedKeys) {
234
+ sortedData[key] = string[key];
235
+ }
236
+ return sortedData;
237
+ }
238
+
239
+ module.exports = getCookie;