lhr0909 / PythonObfuscator

[DEPRECATED] An Obfuscator for simple Python 2 Scripts
MIT License
35 stars 16 forks source link

Can't obfuscate already obfuscated code #1

Closed redjohn closed 10 years ago

redjohn commented 11 years ago

It doesn't look like the obfuscator works correctly with code that it has already obfuscated. Giving it the code print 'something' results in

exec('''import re\nexec((lambda p,y:(lambda o,b,f:re.sub(o,b,f))(r"([0-9a-f]+)",lambda m:p(m,y),"1 \\'0\\'"))(lambda a,b:b[int("0x"+a.group(1),16)],"something|print".split("|")))''')

which runs as expected:

>>> exec('''import re\nexec((lambda p,y:(lambda o,b,f:re.sub(o,b,f))(r"([0-9a-f]+)",lambda m:p(m,y),"1 \\'0\\'"))(lambda a,b:b[int("0x"+a.group(1),16)],"something|print".split("|")))''')
something
>>>

If I run that back through the obfuscator, I get

exec('''import re\nexec((lambda p,y:(lambda o,b,f:re.sub(o,b,f))(r"([0-9a-f]+)",lambda m:p(m,y),"17(\\'\\'\\'e 3\\15((4 9,8:(4 7,b,f:3.14(7,b,f))(13\\"([0-12-f]+)\\",4 5:9(5,8),\\"1 \\\\\\'0\\\\\\'\\"))(4 a,b:b[11(\\"10\\"+a.2(1),16)],\\"d|c\\".6(\\"|\\")))\\'\\'\\')"))(lambda a,b:b[int("0x"+a.group(1),16)],"0|1|group|re|lambda|m|split|o|y|p|a|b|print|something|import|f|0x|int|9a|r|sub|nexec|16|exec".split("|")))''')

which doesn't do anything when executed:

>>> exec('''import re\nexec((lambda p,y:(lambda o,b,f:re.sub(o,b,f))(r"([0-9a-f]+)",lambda m:p(m,y),"17(\\'\\'\\'e 3\\15((4 9,8:(4 7,b,f:3.14(7,b,f))(13\\"([0-12-f]+)\\",4 5:9(5,8),\\"1 \\\\\\'0\\\\\\'\\"))(4 a,b:b[11(\\"10\\"+a.2(1),16)],\\"d|c\\".6(\\"|\\")))\\'\\'\\')"))(lambda a,b:b[int("0x"+a.group(1),16)],"0|1|group|re|lambda|m|split|o|y|p|a|b|print|something|import|f|0x|int|9a|r|sub|nexec|16|exec".split("|")))''')
>>> 
lhr0909 commented 11 years ago

Interesting, haven't tried this yet. I am going to switch up the way to obfuscation so it takes the back slashes into the word list (including \n, and \t). Hopefully will solve this issue.

lhr0909 commented 10 years ago

Should work in v0.3