Debian Codegraph @

cloudscraper/interpreters/js2py.py

raw
1 from __future__ import absolute_import
2
3 import js2py
4 import logging
5 import base64
6
7 from . import JavaScriptInterpreter
8
9 from .encapsulated import template
10 from .jsunfuck import jsunfuck
11
12 # ------------------------------------------------------------------------------- #
13
14
15 class ChallengeInterpreter(JavaScriptInterpreter):
16
17 # ------------------------------------------------------------------------------- #
18
19 def __init__(self):
20 super(ChallengeInterpreter, self).__init__('js2py')
21
22 # ------------------------------------------------------------------------------- #
23
24 def eval(self, body, domain):
25
26 jsPayload = template(body, domain)
27
28 if js2py.eval_js('(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]') == '1':
29 logging.warning('WARNING - Please upgrade your js2py https://github.com/PiotrDabkowski/Js2Py, applying work around for the meantime.')
30 jsPayload = jsunfuck(jsPayload)
31
32 def atob(s):
33 return base64.b64decode('{}'.format(s)).decode('utf-8')
34
35 js2py.disable_pyimport()
36 context = js2py.EvalJs({'atob': atob})
37 result = context.eval(jsPayload)
38
39 return result
40
41
42 # ------------------------------------------------------------------------------- #
43
44 ChallengeInterpreter()