Skip to content

Instantly share code, notes, and snippets.

@alexwilson
Last active September 3, 2021 17:23
Show Gist options
  • Select an option

  • Save alexwilson/f4f084b87946f84a89b4 to your computer and use it in GitHub Desktop.

Select an option

Save alexwilson/f4f084b87946f84a89b4 to your computer and use it in GitHub Desktop.

Revisions

  1. alexwilson revised this gist Jan 17, 2015. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions cloudflare-challenge.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,12 @@
    /**
    * This is a project designed to get around sites using Cloudflare's "I'm under attack" mode.
    * Using the PhantomJS headless browser, it queries a site given to it as the second parameter, waits six seconds
    * and returns the cookies required to continue using this site. With this, it is possible to automate scrapers
    * or spiders that would otherwise be thwarted by Cloudflare's anti-bot protection.
    * Using the PhantomJS headless browser, it queries a site given to it as the second parameter,
    * waits six seconds and returns the cookies required to continue using this site. With this,
    * it is possible to automate scrapers or spiders that would otherwise be thwarted by Cloudflare's
    * anti-bot protection.
    *
    * To run this: phantomjs cloudflare-challenge.js http://www.example.org/
    */

    /**
    *
    * Copyright © 2015 by Alex Wilson <[email protected]>
    *
    * Permission to use, copy, modify, and/or distribute this software for
    @@ -51,7 +50,7 @@ antoligy.cloudflareChallenge = {
    this.system = require('system');
    this.page = this.webpage.create();
    this.url = this.system.args[1];
    this.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
    this.userAgent = 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0';
    this.timeout = 6000;
    },

  2. alexwilson revised this gist Jan 17, 2015. No changes.
  3. alexwilson revised this gist Jan 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cloudflare-challenge.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    /**
    * This is a project designed to get around sites using Cloudflare's "I'm under attack" mode.
    * Using the PhantomJS headless browser, it queries a site given to it as the second parameter, waits six seconds
    * and returns the cookies required to continue using this site. Using this, it is possible to automate scrapers
    * and returns the cookies required to continue using this site. With this, it is possible to automate scrapers
    * or spiders that would otherwise be thwarted by Cloudflare's anti-bot protection.
    *
    * To run this: phantomjs cloudflare-challenge.js http://www.example.org/
  4. alexwilson created this gist Jan 17, 2015.
    79 changes: 79 additions & 0 deletions cloudflare-challenge.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    /**
    * This is a project designed to get around sites using Cloudflare's "I'm under attack" mode.
    * Using the PhantomJS headless browser, it queries a site given to it as the second parameter, waits six seconds
    * and returns the cookies required to continue using this site. Using this, it is possible to automate scrapers
    * or spiders that would otherwise be thwarted by Cloudflare's anti-bot protection.
    *
    * To run this: phantomjs cloudflare-challenge.js http://www.example.org/
    */

    /**
    * Copyright © 2015 by Alex Wilson <[email protected]>
    *
    * Permission to use, copy, modify, and/or distribute this software for
    * any purpose with or without fee is hereby granted, provided that the
    * above copyright notice and this permission notice appear in all
    * copies.
    *
    * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
    * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
    * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
    * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    */


    /**
    * Namespaced object.
    * @type {Object}
    */
    var antoligy = antoligy || {};

    /**
    * Simple wrapper to retrieve Cloudflare's 'solved' cookie.
    * @type {Object}
    */
    antoligy.cloudflareChallenge = {

    webpage: false,
    system: false,
    page: false,
    url: false,
    userAgent: false,

    /**
    * Initiate object.
    */
    init: function() {
    this.webpage = require('webpage');
    this.system = require('system');
    this.page = this.webpage.create();
    this.url = this.system.args[1];
    this.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
    this.timeout = 6000;
    },

    /**
    * "Solve" Cloudflare's challenge using PhantomJS's engine.
    * @return {String} JSON containing our cookies.
    */
    solve: function() {
    var self = this;
    this.page.settings.userAgent = this.userAgent;
    this.page.open(this.url, function(status) {
    setTimeout(function() {
    console.log(JSON.stringify(phantom.cookies));
    phantom.exit()
    }, self.timeout);
    });
    }

    }

    /**
    * In order to carry on making requests, both user agent and IP address must what is returned here.
    */
    antoligy.cloudflareChallenge.init();
    antoligy.cloudflareChallenge.solve();