ClaudiuGeorgiu / Obfuscapk

An automatic obfuscation tool for Android apps that works in a black-box fashion, supports advanced obfuscation features and has a modular architecture easily extensible with new techniques
MIT License
1.09k stars 285 forks source link

Obfuscation always returning non-zero exit status 255. #145

Closed bluecatpixel closed 9 months ago

bluecatpixel commented 1 year ago

Hi.

I'm trying to obfuscate an. apk that is signed and process always returns non-zero exit status 255.

I suspect that I'm doing it the wrong way.

sudo docker run --rm -it -u $(id -u):$(id -g) -v "${PWD}":"/workdir" obfuscapk -o RandomManifest -o Rebuild -o NewAlignment -o NewSignature original.apk -p --keystore-file XXXX.key --keystore-password PASS --key-alias PASS --key-password PASS

The result is always this:

Traceback (most recent call last): File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/new_alignment/new_alignment.py", line 20, in obfuscate obfuscation_info.align_obfuscated_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 620, in align_obfuscated_apk zipalign.align(self.obfuscated_apk_path) File "/Obfuscapk/obfuscapk/tool.py", line 247, in align output = subprocess.check_output( File "/usr/local/lib/python3.10/subprocess.py", line 420, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/local/lib/python3.10/subprocess.py", line 524, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/android-sdk-linux/build-tools/32.0.0/zipalign', '-p', '-v', '-f', '4', 'obfuscation_working_dir/original_obfuscated.copy.apk', 'obfuscation_working_dir/original_obfuscated.apk']' returned non-zero exit status 255. Traceback (most recent call last): File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/Obfuscapk/obfuscapk/cli.py", line 189, in <module> main() File "/Obfuscapk/obfuscapk/cli.py", line 171, in main perform_obfuscation( File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/new_alignment/new_alignment.py", line 20, in obfuscate obfuscation_info.align_obfuscated_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 620, in align_obfuscated_apk zipalign.align(self.obfuscated_apk_path) File "/Obfuscapk/obfuscapk/tool.py", line 247, in align output = subprocess.check_output( File "/usr/local/lib/python3.10/subprocess.py", line 420, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/local/lib/python3.10/subprocess.py", line 524, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/android-sdk-linux/build-tools/32.0.0/zipalign', '-p', '-v', '-f', '4', 'obfuscation_working_dir/original_obfuscated.copy.apk', 'obfuscation_working_dir/original_obfuscated.apk']' returned non-zero exit status 255.

What I'm doing wrong?

Thanks in advance Jose

ClaudiuGeorgiu commented 1 year ago

Hi, this is an interesting error that I haven't seen before. The command you wrote looks good to me, do you get the same error with every apk file? Can you share an apk file that returns this error?

bluecatpixel commented 1 year ago

Hi. Thanks for your quick response.

After all it's not about the apk or signature because I tried with several apks, I even created one simple debug apk just for test and still always the same. I'm running the docker in a macbook M1 I guess it must be related. Now I'm trying to do it on a windows machine (old) but I'm getting problems with the docker. I'll let you know the results.

bluecatpixel commented 1 year ago

Hi.

As I suspected the problem was related with my macbook M1. I wasn't able to fixed it so I prepared an old computer with ubuntu and this time it was ok.

Now although it works without errors the results are not the expected.

I tried to rename the classes, methods and fields and when I analyse the apk or I do the reverse engineer I still see the classes, methods and fields names.

What I'm doing wrong? Thanks in advance.

This is the execution: joserfsantos@joserfsantos-HP-ProBook-640-G1:~/Downloads$ sudo docker run --rm -it -u $(id -u):$(id -g) -v "${PWD}":"/workdir" obfuscapk -o RandomManifest -o Rebuild -o NewAlignment -o NewSignature -o ClassRename -o FieldRename -o Goto -o LibEncryption -o MethodRename ./app.apk -p --keystore-file XXXX --keystore-password XXXX --key-alias XXXX --key-password XXXX Class name to smali file mapping: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████|[00:00<00:00, 30206.73file/s] Renaming class declarations: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:04<00:00, 3659.20file/s] Renaming class usages in smali files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████|[00:11<00:00, 1337.80file/s] Renaming class usages in xml files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████|[00:03<00:00, 40.49file/s] Renaming field declarations: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:00<00:00, 1431.74file/s] Renaming field declarations: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:04<00:00, 1992.11file/s] Renaming field declarations: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:02<00:00, 2110.29file/s] Processing multidex: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:07<00:00, 2.46s/dex] Renaming field references: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:06<00:00, 2159.88file/s] Inserting "goto" instructions in smali files: 100%|████████████████████████████████████████████████████████████████████████████████████████|[00:06<00:00, 2297.38file/s] Renaming method declarations: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:06<00:00, 2454.56file/s] Renaming method invocations: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████|[00:08<00:00, 1748.93file/s] Running obfuscators (MethodRename): 100%|██████████████████████████████████████████████████████████████████████████████████████████████|[01:52<00:00, 12.46s/obfuscator]

ClaudiuGeorgiu commented 1 year ago

What I'm doing wrong?

You are using some obfuscators after rebuilding the app, see FAQ. Put -o Rebuild -o NewAlignment -o NewSignature after all the other obfuscators.

bluecatpixel commented 1 year ago

LOL...makes sense

thanks for the quick response