Skip to content

Unexpected token ILLEGAL js2py #335

Description

@BarotbekTurxonov

I have long obfuscated code in obfuscated_code.js

var _0xc46e=["","split","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/","slice","indexOf","","",".","pow","reduce","reverse","0"];function _0xe51c(d,e,f){var g=_0xc46e[2]_0xc46e[1];var h=g_0xc46e[3];var i=g_0xc46e[3];var j=d_0xc46e[1]_0xc46e[10][_0xc46e[9]](function(a,b,c){if(h_0xc46e[4]!==-1)return a+=h_0xc46e[4]*(Math_0xc46e[8])},0);var k=_0xc46e[0];while(j>0){k=i[j%f]+k;j=(j-(j%f))/f}return k||_0xc46e[11]}eval(function(h,u,n,t,e,r){r="";for(var i=0,len=h.length;i<len;i++){var s="";while(h[i]!==n[e]){s+=h[i];i++}for(var j=0;j<n.length;j++)s=s.replace(new RegExp(n[j],"g"),j);r+=String.fromCharCode(_0xe51c(s,e,10)-t)}return decodeURIComponent(r)}("AAAAAffaAAAAffAaAAffAAaAAAfAAaAAAfAAaAAfffffaAAAfAffaAffffAAAaAAAAfAAaAfffffAaAffffAfAaAfffffAfaAfffAfffaAffffffAaAAAfAAAaAAAfAAaAAAAAfaAffffffAaAAAAfffaAfffAfAfaAAffAAaAfAfAAAaAAAfAffaAffffAAAaAAAAfffaAAAfAAaAAAAffaAAffAAaAffffAfaAAffAAaAfffAffaAffffAAaAffffAAaAffffAAaAAAAffaAAAAffaAAffAAaAffAAAAaAAffAAaAfffAffaAffAfAfaAfffAAfaAffAffAaAffAfffaAfffAAAaAffAAffaAffAAffaAffAfffaAffffAAaAAAAffaAfffAAAfaAAAfAaAAAAAffaAAAAffAaAAffAAaAAAfA

here is my code to deobfuscate it,

import re
import js2py

def deobfuscate_js(obfuscated_code):
code = obfuscated_code.replace('\\', '\')

match = re.search(r'eval\(function\((.*?)\){(.*)}(.*?)\)', code, re.DOTALL)
if not match:
    return "Couldn't parse the obfuscated code."

args = match.group(1).split(',')
function_body = match.group(2)
arg_values = match.group(3).strip('()').split(',')

# Reconstruct the function
func = f"function deobfuscator({','.join(args)}){{{function_body}}}"

try:
    py_func = js2py.eval_js(func)
    result = py_func(*arg_values)
except js2py.internals.simplex.JsException as e:
    return f"Error executing JavaScript: {e}"

return result

with open('obfuscated_code.js', 'r') as file:
obfuscated_code = file.read()

deobfuscated_code = deobfuscate_js(obfuscated_code)
print(deobfuscated_code)

but I couldn't fixed this error
Error executing JavaScript: SyntaxError: Line 1: Unexpected token ILLEGAL

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions