Skip to content

Instantly share code, notes, and snippets.

@BitesizedLion
Created October 8, 2024 11:44
Show Gist options
  • Save BitesizedLion/1e55e500c769d00072274dfe0dd8219c to your computer and use it in GitHub Desktop.
Save BitesizedLion/1e55e500c769d00072274dfe0dd8219c to your computer and use it in GitHub Desktop.
solve db schenker captchas
// Function to solve the puzzle asynchronously
async function solvePuzzle(t) {
// Calculate the target number using parameters from the puzzle
const e = calculateTarget(t[13], t[14]);
// Variable to hold the solution
let o;
// Loop to find a valid solution
for (let attempts = 0; attempts <= Number.MAX_SAFE_INTEGER; attempts++) {
const a = convertToInt8Array(attempts); // Convert attempt number to Int8Array
const hashValue = await hashValueWithPuzzle(a, t); // Hash the combined data
// Check if the hash is less than the target
if (hashValue < e) {
o = a; // Store the valid solution
break; // Exit loop if solution is found
}
}
// Return the solution encoded as Base64
return o ? btoa(String.fromCharCode(...new Uint8Array(o))) : ''; // If no solution, return empty string
}
// Function to calculate the target number based on puzzle parameters
function calculateTarget(t, n) {
const r = BigInt(8 * (t - 3)); // Calculate exponent
const base = BigInt(2); // Base is 2
let power = base;
// Raise base to the exponent
for (let i = 1; i < r; i++) {
power *= base; // Calculate power
}
return BigInt(n) * power; // Return the target
}
// Function to hash a value with puzzle data using SHA-256
async function hashValueWithPuzzle(t, n) {
const combinedData = combineData(t, n); // Combine the data
const hash1 = await crypto.subtle.digest('SHA-256', combinedData); // First SHA-256 hash
const hash2 = await crypto.subtle.digest('SHA-256', hash1); // Second SHA-256 hash
// Convert the final hash to a BigInt for comparison
return convertHashToBigInt(new Uint8Array(hash2));
}
// Function to combine value and puzzle data into a byte array
function combineData(value, puzzle) {
const combinedArray = new Int8Array(40); // Create an Int8Array of 40 bytes
for (let i = 0; i < 32; i++) {
combinedArray[i] = puzzle[i]; // Copy first 32 bytes from puzzle
}
for (let j = 32; j < 40; j++) {
combinedArray[j] = value[j - 32]; // Copy 8 bytes from value
}
return combinedArray; // Return the combined data
}
// Function to convert a number to an Int8Array
function convertToInt8Array(value) {
const n = new Int8Array(8);
for (let i = 0; i < n.length; i++) {
const e = value & 255; // Get the last 8 bits
n[i] = e; // Store in Int8Array
value = (value - e) / 256; // Shift right
}
return n; // Return the Int8Array
}
// Function to convert a hash to a BigInt for comparison
function convertHashToBigInt(hash) {
let bigIntValue = BigInt(0);
for (let i = hash.length - 1; i >= 0; i--) {
bigIntValue = (bigIntValue * BigInt(256)) + BigInt(hash[i]); // Convert byte array to BigInt
}
return bigIntValue; // Return BigInt value
}
async function solveCaptchaMain(messages) {
Promise.all(
messages.map(async ({ jwt, puzzle }) => ({
jwt: jwt,
solution: await solvePuzzle(puzzle)
}))
).then(results => {
console.log(results);
filter1 = results.filter(Pt=>messages.some(en=>en.jwt === Pt.jwt));
console.log(btoa(JSON.stringify(filter1)))
});
}
P = "ZXlKaGJHY2lPaUpJVXpJMU5pSjkuZXlKd2RYcDZiR1VpT2lKQlFVRkJRVUZCUmpSS2RUaHZXREl2WW1sRlMwRkJRVUZCUVVGQlFVRkJRVUZCUVVGQlFVRkJRVUZDZWs0MFptWkhSbmxHU0hSNWFVUnpTVVZVZGpsME5ubFpjMWxSWjJKM2MyVnRlVEIxU2xwNmNIbHVRVDA5SWl3aWFXRjBJam94TnpJNE16Z3lNVFl5TENKbGVIQWlPakUzTWpnek9ESXlNako5LkRxaTNJTGhyTHNBSnJjY3hpNzFVTDhKVWM0VkVpOGRjRGhpY3l2OHNpWWcsZXlKaGJHY2lPaUpJVXpJMU5pSjkuZXlKd2RYcDZiR1VpT2lKQlFVRkJRVUZEY25OdFRWbFNVRVJKU0hsRlMwRkJRVUZCUVVGQlFVRkJRVUZCUVVGQlFVRkJRVUZDZWs0MFptWkhSbmxHU0hSNWFVUnpTVVZVZGpsME5ubFpjMWxSWjJKM2MyVnRlVEIxU2xwNmNIbHVRVDA5SWl3aWFXRjBJam94TnpJNE16Z3lNVFl5TENKbGVIQWlPakUzTWpnek9ESXlNako5LkpWaEtoS2IzZ2F4X0tRdi1vODBMWjA4eEFfYWQ3VDN4RUFmMHprSVA4SDgsZXlKaGJHY2lPaUpJVXpJMU5pSjkuZXlKd2RYcDZiR1VpT2lKQlFVRkJRVUZFUWtka1NuSnRTMnhqUlZORlMwRkJRVUZCUVVGQlFVRkJRVUZCUVVGQlFVRkJRVUZDZWs0MFptWkhSbmxHU0hSNWFVUnpTVVZVZGpsME5ubFpjMWxSWjJKM2MyVnRlVEIxU2xwNmNIbHVRVDA5SWl3aWFXRjBJam94TnpJNE16Z3lNVFl5TENKbGVIQWlPakUzTWpnek9ESXlNako5LlJCS1hhM3hhSF9MU2VLMExuX1FqaV9ULURfaWtqVmJRQlJfLU10Z0pVWGs="
Xe = atob(P).split(",").map(f=>{
const w = JSON.parse(atob(f.split(".")[1]));
return {
jwt: f,
puzzle: Int8Array.from(atob(w.puzzle), xe=>xe.charCodeAt(0))
}
}
)
solveCaptchaMain(Xe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment