Skip to content

Commit

Permalink
blafoo
Browse files Browse the repository at this point in the history
  • Loading branch information
fionera committed Nov 15, 2023
1 parent d116849 commit fdaf3ef
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 55 deletions.
22 changes: 11 additions & 11 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
<div class="container">
<div class="description">
<h3 class="heading">Request on Hold</h3>
<div class="captcha">
</div>
<noscript>
<p>
You need to allow Javascript to verify your Browser.
</p>
</noscript>
<span id="cookie-warning" style="display: none">You need to enable Cookies to verify your Browser.</span>

<div class="captcha-container">
<div class="captcha"></div>
<div class="circle-loader">
<div class="checkmark draw"></div>
<div class="cross draw"></div>
</div>
<div class="captcha"></div>
</div>
<noscript>
<p>
You need to allow Javascript to verify your Browser.
</p>
</noscript>
<p id="cookie-warning" style="display: none">You need to enable Cookies to verify your Browser.</p>
<p>If you suspect that you are being blocked by mistake, make sure that you have the
latest browser version installed and all active browser plugins are disabled.</p>
<span id="loop-warning" style="display: none">If you see this and the verification repeats, please try a different browser.</span>
<p>If you see this and the verification repeats, please try a different browser.</p>
</div>
<div class="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1136.8 1219.13">
Expand All @@ -42,6 +41,7 @@ <h3 class="heading">Request on Hold</h3>
</g>
</svg>
</div>
<div class="error-container"></div>
<div class="break"></div>
<div class="error-container footer"></div>
</div>
</body>
45 changes: 29 additions & 16 deletions web/src/challange/challanger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {challengeFingerprinting, challengeNone, challengePOW, challengeUnknown} from "./challanges";
import {getChallengeSolver} from "./challanges";
import * as loader from "./loader.js";

/**
* Decide and solve browser challenges.
Expand All @@ -20,21 +21,33 @@ async function getChallenge() {
* @return {Promise<void>}
*/
export async function doChallenge() {
const challenge = await getChallenge();
const {t} = challenge;

const challengeFunc = (() => {
switch (t) {
case 0:
return challengeNone;
case 1:
return challengePOW;
case 2:
return challengeFingerprinting;
default:
return challengeUnknown;
loader.start();

let result;
try {
loader.setChallengeInfo("Fetching challenge...")

const challenge = await getChallenge();
const {t} = challenge;

const [name, solver] = getChallengeSolver(t);

loader.setChallengeInfo(name)
result = await solver(challenge);
if (!!result) {
result = `Validation result: ${result}`;
}
})()
} catch (e) {
result = e.toString();
}

loader.stop(!!result);
if (result) {
loader.showError(result);
return;
}

return await challengeFunc(challenge)
setTimeout(() => {
window.location.reload();
}, 3000);
}
25 changes: 14 additions & 11 deletions web/src/challange/challanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function nativeHash(data, method) {
* @param {object} challenge
* @return {Promise<void>}
*/
export async function challengePOW(challenge) {
async function challengePOW(challenge) {
let hash;
let i;
// eslint-disable-next-line no-constant-condition
Expand All @@ -45,7 +45,7 @@ export async function challengePOW(challenge) {
*
* @return {Promise<string>}
*/
export async function challengeFingerprinting() {
async function challengeFingerprinting() {
const usualUa = isUsualBrowserBasedOnUa();
if (!usualUa) return "ua";

Expand All @@ -63,18 +63,21 @@ export async function challengeFingerprinting() {
*
* @return {Promise<void>}
*/
export async function challengeNone() {
async function challengeNone() {
return new Promise((resolve) => {
setTimeout(resolve, 3000);
});
}

/**
* Unknown challenge from server.
* Reload page.
*
* @return {Promise<void>}
*/
export async function challengeUnknown() {
window.location.reload();
export function getChallengeSolver(challengeType) {
switch (challengeType) {
case 0:
return ["Please wait...", challengeNone];
case 1:
return ["Solving POW challenge...", challengePOW];
case 2:
return ["Validating browser fingerprint...", challengeFingerprinting];
default:
throw new Error(`Unknown challenge type: ${challengeType}`);
}
}
7 changes: 6 additions & 1 deletion web/src/challange/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ export function start() {

export function showError(error) {
const errors = /** @type {HTMLDivElement} */ (document.querySelector(".error-container"));
errors.insertAdjacentHTML("beforeend", `<p>Error: ${error}</p>`)
errors.insertAdjacentHTML("beforeend", `<code>${error}</code>`)
}

export function setChallengeInfo(text) {
const captcha = /** @type {HTMLDivElement} */ (document.querySelector(".captcha"));
captcha.innerText = text;
}

/**
Expand Down
15 changes: 1 addition & 14 deletions web/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "./style.scss";
import {doChallenge} from "./challange/challanger";
import * as loader from "./challange/loader.js";


(() => {
Expand All @@ -10,18 +9,6 @@ import * as loader from "./challange/loader.js";
if (noCookie) noCookie.style.display = "block";
}

loader.start();
try {
const result = await doChallenge()
loader.stop(!!result);
} catch (e) {
loader.showError(e)
loader.stop(true);
return;
}

setTimeout(() => {
window.location.reload();
}, 1000);
await doChallenge();
});
})();
29 changes: 27 additions & 2 deletions web/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

.container {
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
align-items: center;
align-content: center;
position: absolute;
width: 100%;
height: 100%;
Expand All @@ -22,6 +23,25 @@
font-weight: bold;
}
}
> .break {
flex-basis: 100%;
height: 0;
}
}

.footer {
bottom: 1em;
position: absolute;
}

code {
padding: 16px;
overflow: auto;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
max-width: 80vw;
display: block;
}

.logo {
Expand All @@ -44,11 +64,16 @@
margin: .5em 0 .5em 0;
}

.captcha {
margin-left: auto;
font-size: 120%;
}

$circleSize: 3em;

.circle-loader {
visibility: hidden;
margin-left: auto;
margin-left: 1em;
border: 1px solid rgba(0, 0, 0, 0.2);
border-left-color: #000;
animation: loader-spin 1.2s infinite linear;
Expand Down

0 comments on commit fdaf3ef

Please sign in to comment.