detect DDos-Guard through title content. resolves #546 (#559)

This commit is contained in:
Athorcis 2022-10-22 15:34:29 +02:00 committed by GitHub
parent c99101f74b
commit 197258e921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,9 @@ const CHALLENGE_SELECTORS: string[] = [
'#link-ddg', // DDoS-GUARD '#link-ddg', // DDoS-GUARD
'td.info #js_info' // Custom CloudFlare for EbookParadijs, Film-Paleis, MuziekFabriek and Puur-Hollands 'td.info #js_info' // Custom CloudFlare for EbookParadijs, Film-Paleis, MuziekFabriek and Puur-Hollands
]; ];
const CHALLENGE_TITLES: string[] = [
'DDOS-GUARD'
];
const CAPTCHA_SELECTORS: string[] = [ const CAPTCHA_SELECTORS: string[] = [
// todo: deprecate 'input[name="cf_captcha_kind"]' // todo: deprecate 'input[name="cf_captcha_kind"]'
'#cf-challenge-hcaptcha-wrapper', '#cf-norobot-container', 'input[name="cf_captcha_kind"]' '#cf-challenge-hcaptcha-wrapper', '#cf-norobot-container', 'input[name="cf_captcha_kind"]'
@ -49,7 +52,7 @@ export default async function resolveChallenge(url: string, page: Page, response
// find Cloudflare selectors // find Cloudflare selectors
let selectorFound = false; let selectorFound = false;
let selector: string = await findAnySelector(page, CHALLENGE_SELECTORS) let selector: string = await findChallenge(page)
if (selector) { if (selector) {
selectorFound = true; selectorFound = true;
log.debug(`Javascript challenge element '${selector}' detected.`) log.debug(`Javascript challenge element '${selector}' detected.`)
@ -58,7 +61,7 @@ export default async function resolveChallenge(url: string, page: Page, response
while (true) { while (true) {
try { try {
selector = await findAnySelector(page, CHALLENGE_SELECTORS) selector = await findChallenge(page)
if (!selector) { if (!selector) {
// solved! // solved!
log.debug('Challenge element not found') log.debug('Challenge element not found')
@ -124,6 +127,20 @@ export default async function resolveChallenge(url: string, page: Page, response
return response; return response;
} }
async function findChallenge(page: Page): Promise<string|null> {
const selector = await findAnySelector(page, CHALLENGE_SELECTORS);
if (selector == null) {
const title = await page.title();
if (CHALLENGE_TITLES.includes(title)) {
return `:title[${title}]`;
}
}
return selector;
}
async function findAnySelector(page: Page, selectors: string[]) { async function findAnySelector(page: Page, selectors: string[]) {
for (const selector of selectors) { for (const selector of selectors) {
const cfChallengeElem = await page.$(selector) const cfChallengeElem = await page.$(selector)