This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcap_module.js
144 lines (109 loc) · 4.12 KB
/
hcap_module.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
const p = require('phin');
const unidecode = require('unidecode');
const cocoSsd = require('@tensorflow-models/coco-ssd');
const tf = require('@tensorflow/tfjs-node');
const magikCoco = async (imgURL) => {
try {
const buffer = await p({
'url': imgURL,
})
const blob = buffer.body
const model = await cocoSsd.load();
const predictions = await model.detect(tf.node.decodeImage(blob));
return predictions;
} catch {
return null;
}
}
const getPredictions = async (reqImg, images, keyword) => {
let answers = [];
let threads = [];
for (const task of reqImg) {
threads.push(magikCoco(task));
}
try {
await Promise.all(threads).then((results, i) => {
results.forEach( async (res, index) => {
let [data] = res;
if (data !== undefined && data.score > 0.5 && data.class.toLowerCase() == keyword) {
answers.push(index);
}
});
});
} catch (err) {
console.log(err);
}
return answers;
};
const imgGetURL = async (page, images) => {
let tab = [];
for (let image of images) {
let img_background = await page.evaluate(image => image.style['background-image'], image);
let matches = img_background.match(/^url\("(.*)"\)$/);
if (matches.length > 0) {
let url = matches[matches.length - 1];
if (url) {
tab.push(url);
}
}
}
return tab;
}
const resolve = async (page) => {
const iframeAll = page.frames();
let iframeCheckbox, iframeChallenge;
iframeAll.forEach((iframe) => {
if (iframe.url().startsWith('https://newassets.hcaptcha.com/captcha/') ) {
if (iframe.url().includes('hcaptcha.html#frame=checkbox')) {
iframeCheckbox = iframe;
}
if (iframe.url().includes('hcaptcha.html#frame=challenge')) {
iframeChallenge = iframe;
}
}
});
await iframeCheckbox.hover('#checkbox');
await iframeCheckbox.click('#checkbox');
await page.waitForTimeout(5000);
const start = async () => {
if (await iframeChallenge.$('.prompt-text') === null)
return console.log('[+] Captcha Solved !');
const promptElement = await iframeChallenge.$('.prompt-text');
const promptText = await iframeChallenge.evaluate(promptElement => promptElement.textContent, promptElement);
const promptParsed = promptText.split(' ');
const promptWord = promptParsed.slice(-1).toString();
let promptWordClean = unidecode(promptWord);
switch (promptWordClean) {
case 'dzeaplane':
promptWordClean = 'seaplane';
break;
case 'trusk':
promptWordClean = 'truck';
break;
case 'sar':
promptWordClean = 'car';
break;
}
//console.log(promptWordClean)
let imgElements = await iframeChallenge.$$('.task-grid .task-image .image');
let imgURL = await imgGetURL(iframeChallenge, imgElements);
let imgValid = await getPredictions(imgURL, imgElements, promptWordClean);
async function* ForAsync() {
var i = 0;
while (i < imgValid.length) {
yield i++;
}
}
for await (let i of ForAsync()) {
await imgElements[imgValid[i]].hover();
await imgElements[imgValid[i]].click();
}
await page.waitForTimeout(1000);
await iframeChallenge.hover(".button-submit");
await iframeChallenge.click(".button-submit");
await page.waitForTimeout(2000);
start();
}
start();
}
exports.resolve = resolve;