Created
April 5, 2023 03:15
-
-
Save mustofa-id/4b17d5040cf74c77f6bfad53e24e6054 to your computer and use it in GitHub Desktop.
Find valid Telegram Group invite link. This is a challenge from my friend.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Find valid Telegram Group invite link. | |
* This is a challenge from my friend. | |
*/ | |
const config = { | |
url: 'https://t.me/+zUufcmk***E3nGQ1', // asterisks are hidden chars | |
name: 'Mine', // name of group | |
process_count: 100, // how many process should run at a time | |
}; | |
const valid_chars = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`; | |
const candidates = []; | |
const possible_urls = []; | |
const pattern = /\*+/g.exec(config.url)[0]; | |
if (!pattern) { | |
console.error('failed to get pattern', pattern); | |
process.exit(1); | |
} | |
console.log('preparing candidates ...'); | |
function generate_candidates(prefix, level) { | |
if (level === pattern.length) { | |
candidates.push(prefix); | |
return; | |
} | |
for (const c of valid_chars) { | |
generate_candidates(prefix + c, level + 1); | |
} | |
} | |
generate_candidates('', 0); | |
console.log('begin ...'); | |
for ( | |
let i = 0; | |
i < candidates.length - config.process_count - 1; | |
i += config.process_count | |
) { | |
await Promise.all( | |
Array.from({ length: config.process_count }) // | |
.map((_, j) => try_candidate(i + j)) | |
); | |
process.stdout.write(`test left: ${candidates.length}\r`); | |
if (possible_urls.length) { | |
console.log('found:', possible_urls); | |
break; | |
} | |
} | |
async function try_candidate(index) { | |
const candidate = candidates[index]; | |
if (!candidate) return; | |
try { | |
const new_url = config.url.replace(pattern, candidate); | |
const response = await fetch(new_url); | |
candidates.splice(index, 1); | |
if (!response.ok) return; | |
const text = await response.text(); | |
if (text.toLocaleLowerCase().includes(config.name.toLocaleLowerCase())) { | |
// simple check group name in response | |
possible_urls.push(new_url); | |
} | |
} catch (error) { | |
console.error(`error at ${candidate}:`, error.message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basically this is a Brute Force.