2020-08-03 02:36:38 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import js2py
|
|
|
|
import logging
|
|
|
|
import base64
|
|
|
|
|
|
|
|
from . import JavaScriptInterpreter
|
|
|
|
|
2021-06-23 19:54:28 +00:00
|
|
|
from .encapsulated import template
|
2020-08-03 02:36:38 +00:00
|
|
|
from .jsunfuck import jsunfuck
|
|
|
|
|
2021-06-23 19:54:28 +00:00
|
|
|
# ------------------------------------------------------------------------------- #
|
|
|
|
|
2020-08-03 02:36:38 +00:00
|
|
|
|
|
|
|
class ChallengeInterpreter(JavaScriptInterpreter):
|
|
|
|
|
2021-06-23 19:54:28 +00:00
|
|
|
# ------------------------------------------------------------------------------- #
|
|
|
|
|
2020-08-03 02:36:38 +00:00
|
|
|
def __init__(self):
|
|
|
|
super(ChallengeInterpreter, self).__init__('js2py')
|
|
|
|
|
2021-06-23 19:54:28 +00:00
|
|
|
# ------------------------------------------------------------------------------- #
|
|
|
|
|
|
|
|
def eval(self, body, domain):
|
|
|
|
|
|
|
|
jsPayload = template(body, domain)
|
|
|
|
|
2020-08-03 02:36:38 +00:00
|
|
|
if js2py.eval_js('(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]') == '1':
|
|
|
|
logging.warning('WARNING - Please upgrade your js2py https://github.com/PiotrDabkowski/Js2Py, applying work around for the meantime.')
|
2021-06-23 19:54:28 +00:00
|
|
|
jsPayload = jsunfuck(jsPayload)
|
2020-08-03 02:36:38 +00:00
|
|
|
|
|
|
|
def atob(s):
|
|
|
|
return base64.b64decode('{}'.format(s)).decode('utf-8')
|
|
|
|
|
|
|
|
js2py.disable_pyimport()
|
|
|
|
context = js2py.EvalJs({'atob': atob})
|
2021-06-23 19:54:28 +00:00
|
|
|
result = context.eval(jsPayload)
|
2020-08-03 02:36:38 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2021-06-23 19:54:28 +00:00
|
|
|
# ------------------------------------------------------------------------------- #
|
|
|
|
|
2020-08-03 02:36:38 +00:00
|
|
|
ChallengeInterpreter()
|