How to use the cloudscraper.interpreters.JavaScriptInterpreter function in cloudscraper

To help you get started, we’ve selected a few cloudscraper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github VeNoMouS / cloudscraper / cloudscraper / interpreters / js2py.py View on Github external
from __future__ import absolute_import

import js2py
import logging
import base64

from . import JavaScriptInterpreter

from .encapsulated import template
from .jsunfuck import jsunfuck

# ------------------------------------------------------------------------------- #


class ChallengeInterpreter(JavaScriptInterpreter):

    # ------------------------------------------------------------------------------- #

    def __init__(self):
        super(ChallengeInterpreter, self).__init__('js2py')

    # ------------------------------------------------------------------------------- #

    def eval(self, body, domain):

        jsPayload = template(body, domain)

        if js2py.eval_js('(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]') == '1':
            logging.warning('WARNING - Please upgrade your js2py https://github.com/PiotrDabkowski/Js2Py, applying work around for the meantime.')
            jsPayload = jsunfuck(jsPayload)
github VeNoMouS / cloudscraper / cloudscraper / interpreters / nodejs.py View on Github external
import base64
import subprocess
import sys

from . import JavaScriptInterpreter
from .encapsulated import template

# ------------------------------------------------------------------------------- #


class ChallengeInterpreter(JavaScriptInterpreter):

    # ------------------------------------------------------------------------------- #

    def __init__(self):
        super(ChallengeInterpreter, self).__init__('nodejs')

    # ------------------------------------------------------------------------------- #

    def eval(self, body, domain):
        try:
            js = 'var atob = function(str) {return Buffer.from(str, "base64").toString("binary");};' \
                 'var challenge = atob("%s");' \
                 'var context = {atob: atob};' \
                 'var options = {filename: "iuam-challenge.js", timeout: 4000};' \
                 'var answer = require("vm").runInNewContext(challenge, context, options);' \
                 'process.stdout.write(String(answer));' \
github VeNoMouS / cloudscraper / cloudscraper / interpreters / v8.py View on Github external
import sys

try:
    import v8eval
except ImportError:
    sys.tracebacklimit = 0
    raise RuntimeError('Please install the python module v8eval either via pip or download it from https://github.com/sony/v8eval')

from . import JavaScriptInterpreter
from .encapsulated import template

# ------------------------------------------------------------------------------- #


class ChallengeInterpreter(JavaScriptInterpreter):

    def __init__(self):
        super(ChallengeInterpreter, self).__init__('v8')

    # ------------------------------------------------------------------------------- #

    def eval(self, body, domain):
        try:
            return v8eval.V8().eval(template(body, domain))
        except (TypeError, v8eval.V8Error):
            RuntimeError('We encountered an error running the V8 Engine.')


# ------------------------------------------------------------------------------- #

ChallengeInterpreter()
github VeNoMouS / cloudscraper / cloudscraper / interpreters / native.py View on Github external
from __future__ import absolute_import

import re
import operator as op

from . import JavaScriptInterpreter

# ------------------------------------------------------------------------------- #


class ChallengeInterpreter(JavaScriptInterpreter):

    def __init__(self):
        super(ChallengeInterpreter, self).__init__('native')

    def eval(self, body, domain):
        # ------------------------------------------------------------------------------- #

        operators = {
            '+': op.add,
            '-': op.sub,
            '*': op.mul,
            '/': op.truediv
        }

        # ------------------------------------------------------------------------------- #
github VeNoMouS / cloudscraper / cloudscraper / interpreters / chakracore.py View on Github external
from __future__ import absolute_import

import os
import sys
import ctypes.util

from ctypes import c_void_p, c_size_t, byref, create_string_buffer, CDLL

from . import JavaScriptInterpreter
from .encapsulated import template

# ------------------------------------------------------------------------------- #


class ChallengeInterpreter(JavaScriptInterpreter):

    # ------------------------------------------------------------------------------- #

    def __init__(self):
        super(ChallengeInterpreter, self).__init__('chakracore')

    # ------------------------------------------------------------------------------- #

    def eval(self, body, domain):
        chakraCoreLibrary = None

        # check current working directory.
        for _libraryFile in ['libChakraCore.so', 'libChakraCore.dylib', 'ChakraCore.dll']:
            if os.path.isfile(os.path.join(os.getcwd(), _libraryFile)):
                chakraCoreLibrary = os.path.join(os.getcwd(), _libraryFile)
                continue