I need to understand what the following obfuscated application does:
interpreter.py:
string = "lambda x : obfuscated_code_to_interpret_variable_x"
interpreter = eval(string)
instructions = read_instructions(argv[1])
interpreter(instructions)
instructions.txt:
04GFUHSDSLGHLDFIHGLDSHLFHGLSDGHFLFSHGLIFSHLGFLGFIIGFL...
You run the application typing the command python3 interpreter.py instructions.txt
instructions.txt
contains machine code (of some hypothetical machine). interpreter.py
contains an interpreter that runs the machine code.
I want to modify the interpreter by adding print(variable)
statements inside the string
,
to see what the code does.
The problem is that somewhere in the instructions.txt
file, a file interpreter.py
is read as a string, hashed, and checked that the hash equals to a predefined value. Thus, any modification to the interpreter
variable will invalidate the hash.
I also have no idea what the numbers inside the instructions.txt
file mean, because only the obfuscated interpreter understands the meaning of those numbers. So I can't remove the hash check from the instructions.txt
file, because I don't know where it is.
Any ideas, how to deobfuscate such application?
def x(y): return z(y+1)
def z(x): return x if x ^ 234 < 10 else 0
... and so on, like 200 functions, with if/else statements, maths expressions, such as(x || y && z ^ 2)
, all of that to construct one big function F, which is then evaluated with an argument x, sostring = "lambda x : F(x)"
F(x)
. I would addprint
statements to print the variables of the inner functions of the implementation ofF(x)
, if I see that some variable is a constant, then I can delete the code computing that variable to simplify the function, and keep iterating. This technique has worked for me before. But now addingprint
statements changes the value ofstring
, and thus the hash(string).