Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NodeJS code for automating Puppeteer to register an account on Reddit avoiding Captcha challenge
- // Install node 10.x repository to the system
- // curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
- // download & install nodejs 10.x along with npm
- // $ sudo apt install nodejs
- // Install puppeteer
- // $ mkdir your-project
- // $ cd your-project
- // $ npm install puppeteer
- // $ npm install request-promise-native
- // $ npm install promise-poller
- // create a file index.js in your folder, then paste the following code
- // More information on https://homputersecurity.com/2020/08/31/comment-contourner-les-challenges-captcha-avec-le-service-2captcha/
- const puppeteer = require('puppeteer');
- const chromeOptions = {
- headless:false,
- defaultViewport: null,
- slowMo:10
- };
- const siteDetails = {
- sitekey: '6LeTnxkTAAAAAN9QEuDZRpn90WwKk_R1TRW_g-JC',
- pageurl: 'https://old.reddit.com/login'
- };
- const request = require('request-promise-native');
- const poll = require('promise-poller').default;
- const apiKey = '$user-apikey';
- const Username = '$intented-username';
- const Password = '$intended-password';
- const Email = '$intended-email';
- (async function main() {
- try {
- const browser = await puppeteer.launch(chromeOptions);
- const page = await browser.newPage();
- page.on('error', async function(err) {
- console.log('PageOnError: caught!');
- });
- await new Promise(async function(resolve, reject) {
- try {
- await page.goto('https://old.reddit.com/login');
- const requestId = await initiateCaptchaRequest(apiKey);
- await page.type('#user_reg', Username);
- await page.type('#passwd_reg', Password);
- await page.type('#passwd2_reg', Password);
- await page.type('#email_reg', Email);
- await page.click('#rem_reg');
- await page.click('#newsletter_subscribe');
- const response = await pollForRequestResults(apiKey, requestId);
- console.log(`Entering recaptcha response ${response}`);
- await page.evaluate(`document.getElementById("g-recaptcha-response").innerHTML="${response}";`);
- page.click('#register-form button[type=submit]');
- } catch (err) {
- reject(err);
- }
- });
- } catch (err) {
- console.log(err);
- }
- })();
- async function initiateCaptchaRequest(apiKey) {
- const formData = {
- method: 'userrecaptcha',
- googlekey: siteDetails.sitekey,
- key: apiKey,
- pageurl: siteDetails.pageurl,
- json: 1
- };
- const response = await request.post('http://2captcha.com/in.php', {form: formData});
- return JSON.parse(response).request;
- }
- async function pollForRequestResults(key, id, retries = 100, interval = 1500, delay = 15000) {
- await timeout(delay);
- return poll({
- taskFn: requestCaptchaResults(key, id),
- interval,
- retries
- });
- }
- function requestCaptchaResults(apiKey, requestId) {
- const url = `http://2captcha.com/res.php?key=${apiKey}&action=get&id=${requestId}&json=1`;
- return async function() {
- return new Promise(async function(resolve, reject){
- console.log(`Polling for response...`);
- const rawResponse = await request.get(url);
- const resp = JSON.parse(rawResponse);
- console.log(resp);
- if (resp.status === 0) return reject(resp.request);
- console.log('Response received');
- resolve(resp.request);
- });
- }
- }
- const timeout = millis => new Promise(resolve => setTimeout(resolve, millis))
- ;
Add Comment
Please, Sign In to add comment