-
Notifications
You must be signed in to change notification settings - Fork 10
/
moonbix-proxy.js
371 lines (319 loc) · 13.5 KB
/
moonbix-proxy.js
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
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const colors = require('colors');
const readline = require('readline');
const { HttpsProxyAgent } = require('https-proxy-agent');
class Binance {
constructor() {
this.headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5",
"Content-Type": "application/json",
"Origin": "https://www.binance.com",
"Referer": "https://www.binance.com/vi/game/tg/moon-bix",
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
};
this.game_response = null;
this.game = null;
this.proxies = this.loadProxies();
}
loadProxies() {
const proxyFile = path.join(__dirname, 'proxy.txt');
return fs.readFileSync(proxyFile, 'utf8').split('\n').filter(Boolean);
}
createAxiosInstance(proxy) {
const proxyAgent = new HttpsProxyAgent(proxy);
return axios.create({
headers: this.headers,
httpsAgent: proxyAgent
});
}
async checkProxyIP(proxy) {
try {
const proxyAgent = new HttpsProxyAgent(proxy);
const response = await axios.get('https://api.ipify.org?format=json', { httpsAgent: proxyAgent });
if (response.status === 200) {
return response.data.ip;
} else {
throw new Error(`Cannot check the proxy IP. Status code: ${response.status}`);
}
} catch (error) {
throw new Error(`Error checking the proxy IP: ${error.message}`);
}
}
log(msg, type = 'info') {
const timestamp = new Date().toLocaleTimeString();
switch(type) {
case 'success':
console.log(`[${timestamp}] [*] ${msg}`.green);
break;
case 'custom':
console.log(`[${timestamp}] [*] ${msg}`.magenta);
break;
case 'error':
console.log(`[${timestamp}] [!] ${msg}`.red);
break;
case 'warning':
console.log(`[${timestamp}] [*] ${msg}`.yellow);
break;
default:
console.log(`[${timestamp}] [*] ${msg}`);
}
}
async countdown(seconds) {
for (let i = seconds; i > 0; i--) {
const timestamp = new Date().toLocaleTimeString();
readline.cursorTo(process.stdout, 0);
process.stdout.write(`[${timestamp}] [*] Waiting ${i} seconds to continue...`);
await new Promise(resolve => setTimeout(resolve, 1000));
}
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 0);
}
async callBinanceAPI(queryString, axios) {
const accessTokenUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/third-party/access/accessToken";
const userInfoUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/user/user-info";
try {
const accessTokenResponse = await axios.post(accessTokenUrl, {
queryString: queryString,
socialType: "telegram"
});
if (accessTokenResponse.data.code !== "000000" || !accessTokenResponse.data.success) {
throw new Error(`Failed to get access token: ${accessTokenResponse.data.message}`);
}
const accessToken = accessTokenResponse.data.data.accessToken;
const userInfoHeaders = {
...this.headers,
"X-Growth-Token": accessToken
};
const userInfoResponse = await axios.post(userInfoUrl, {
resourceId: 2056
}, { headers: userInfoHeaders });
if (userInfoResponse.data.code !== "000000" || !userInfoResponse.data.success) {
throw new Error(`Failed to get user info: ${userInfoResponse.data.message}`);
}
return { userInfo: userInfoResponse.data.data, accessToken };
} catch (error) {
this.log(`API call failed: ${error.message}`, 'error');
return null;
}
}
async startGame(accessToken, axios) {
try {
const response = await axios.post(
'https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/game/start',
{ resourceId: 2056 },
{ headers: { ...this.headers, "X-Growth-Token": accessToken } }
);
this.game_response = response.data;
if (response.data.code === '000000') {
this.log("Game started successfully", 'success');
return true;
}
if (response.data.code === '116002') {
this.log("Not enough play attempts!", 'warning');
} else {
this.log("Error starting the game!", 'error');
}
return false;
} catch (error) {
this.log(`Cannot start the game: ${error.message}`, 'error');
return false;
}
}
async gameData() {
try {
const response = await axios.get('https://moonbix-server-9r08ifrt4-scriptvips-projects.vercel.app/moonbix/api/v1/play', {
params: { game_response: this.game_response },
timeout: this.timeout * 1000
});
if (response.data.message === 'success') {
this.game = response.data.game;
this.log("Game data received successfully", 'success');
return true;
}
this.log(response.data.message, 'warning');
return false;
} catch (error) {
this.log(`Error receiving game data: ${error.message}`, 'error');
return false;
}
}
async completeGame(accessToken, axios) {
try {
const response = await axios.post(
'https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/game/complete',
{
resourceId: 2056,
payload: this.game.payload,
log: this.game.log
},
{
headers: {
...this.headers,
"X-Growth-Token": accessToken
},
timeout: this.timeout * 1000
}
);
if (response.data.success) {
this.log(`Game completed successfully | Earned ${this.game.log} points`, 'custom');
return true;
}
this.log(`Cannot complete the game: ${response.data.message}`, 'error');
return false;
} catch (error) {
this.log(`Error completing the game: ${error.message}`, 'error');
return false;
}
}
async getTaskList(accessToken, axios) {
const taskListUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/task/list";
try {
const response = await axios.post(taskListUrl, {
resourceId: 2056
}, {
headers: {
...this.headers,
"X-Growth-Token": accessToken
}
});
if (response.data.code !== "000000" || !response.data.success) {
throw new Error(`Cannot retrieve task list: ${response.data.message}`);
}
const taskList = response.data.data.data[0].taskList.data;
const resourceIds = taskList
.filter(task => task.completedCount === 0)
.map(task => task.resourceId);
return resourceIds;
} catch (error) {
this.log(`Cannot retrieve task list: ${error.message}`, 'error');
return null;
}
}
async completeTask(accessToken, resourceId, axios) {
const completeTaskUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/task/complete";
try {
const response = await axios.post(completeTaskUrl, {
resourceIdList: [resourceId],
referralCode: null
}, {
headers: {
...this.headers,
"X-Growth-Token": accessToken
}
});
if (response.data.code !== "000000" || !response.data.success) {
throw new Error(`Cannot complete the task: ${response.data.message}`);
}
if (response.data.data.type) {
this.log(`Successfully completed task ${response.data.data.type}!`, 'success');
}
return true;
} catch (error) {
this.log(`Cannot complete the task: ${error.message}`, 'error');
return false;
}
}
async completeTasks(accessToken, axios) {
const resourceIds = await this.getTaskList(accessToken, axios);
if (!resourceIds || resourceIds.length === 0) {
this.log("No uncompleted tasks found", 'info');
return;
}
for (const resourceId of resourceIds) {
if (resourceId !== 2058) {
const success = await this.completeTask(accessToken, resourceId, axios);
if (success) {
this.log(`Task completed: ${resourceId}`, 'success');
} else {
this.log(`Cannot complete task: ${resourceId}`, 'warning');
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
}
async playGameIfTicketsAvailable(queryString, accountIndex, firstName, proxy) {
let proxyIP = "Unknown";
try {
proxyIP = await this.checkProxyIP(proxy);
} catch (error) {
throw new Error(`Cannot check the proxy IP. Status code: ${response.status}`);
}
console.log(`========== Account ${accountIndex} | ${firstName.green} | ip: ${proxyIP} ==========`);
const axiosInstance = this.createAxiosInstance(proxy);
const result = await this.callBinanceAPI(queryString, axiosInstance);
if (!result) return;
const { userInfo, accessToken } = result;
const totalGrade = userInfo.metaInfo.totalGrade;
let totalAttempts = userInfo.metaInfo.totalAttempts;
let consumedAttempts = userInfo.metaInfo.consumedAttempts;
let availableTickets = totalAttempts-consumedAttempts;
this.log(`Total points: ${totalGrade}`);
this.log(`Available tickets: ${availableTickets}`);
await this.completeTasks(accessToken, axiosInstance)
while (availableTickets > 0) {
this.log(`Starting game with ${availableTickets} available tickets`, 'info');
if (await this.startGame(accessToken, axiosInstance)) {
if (await this.gameData()) {
await this.countdown(50);
if (await this.completeGame(accessToken, axiosInstance)) {
availableTickets--;
this.log(`Remaining tickets: ${availableTickets}`, 'info');
} else {
break;
}
} else {
this.log("Cannot receive game data", 'error');
break;
}
} else {
this.log("Cannot start the game", 'error');
break;
}
if (availableTickets > 0) {
await new Promise(resolve => setTimeout(resolve, 3000));
}
}
if (availableTickets === 0) {
this.log("All tickets used up", 'success');
}
}
async main() {
const moonbixT = "\n\x1b[1mMoonbix\x1b[0m";
const additionalText = "\nIf you use it, don't be afraid.\nIf you're afraid, don't use it.\nDo With Your Own Risk!\n";
console.log(moonbixT.green);
console.log(additionalText.yellow);
const dataFile = path.join(__dirname, 'data.txt');
const data = fs.readFileSync(dataFile, 'utf8')
.replace(/\r/g, '')
.split('\n')
.filter(Boolean);
while (true) {
for (let i = 0; i < data.length; i++) {
const queryString = data[i];
const userData = JSON.parse(decodeURIComponent(queryString.split('user=')[1].split('&')[0]));
const firstName = userData.first_name;
const proxy = this.proxies[i % this.proxies.length];
try {
await this.playGameIfTicketsAvailable(queryString, i + 1, firstName, proxy);
} catch (error) {
this.log(`Error processing account ${i + 1}: ${error.message}`, 'error');
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
const randomCountdown = Math.floor(Math.random() * (1800 - 300 + 1)) + 300; // Between 5m and 30m
await this.countdown(randomCountdown);
}
}
}
const client = new Binance();
client.main().catch(err => {
client.log(err.message, 'error');
process.exit(1);
});