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

macOS Docker Documentation #141

Closed umerbutt03 closed 1 year ago

umerbutt03 commented 1 year ago

Please provide proper documention for macOS docker process.

ClaudiuGeorgiu commented 1 year ago

https://github.com/ClaudiuGeorgiu/Obfuscapk#docker-image

Which steps are missing/not clear in the readme of the project? Docker instructions are the same for each os, just install docker by using the official guide, pull or build locally the docker image and then follow the readme to view a description of the available parameters.

umerbutt03 commented 1 year ago

docker run --rm -it obfuscapk -o ConstStringEncryption -o ClassRename -o DebugRemoval -o Nop -o Goto -o RandomManifest -o Rebuild -o NewAlignment -o NewSignature -o LibEncryption -w /Users/umer/Desktop/obfuscate_dir/ -d /Users/umer/Desktop/APP_NAME.apk -i -p --keystore-file /Users/umer/Desktop/APP_NAME_docs/APP_NAME_keystore_credentials/APP_NAME_keystore --keystore-password KEYSTORE_PASSWORD --key-alias key0 --key-password KEYSTORE_PASSWORD --use-aapt2 /Users/umer/Desktop/app-release.apk

When I run above command, it gives me below error.

03/10/2022 10:21:57> [CRITICAL][obfuscapk.main][perform_obfuscation()] Unable to find application file "/Users/umer/Desktop/app-release.apk" 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 main() File "/Obfuscapk/obfuscapk/cli.py", line 171, in main perform_obfuscation( File "/Obfuscapk/obfuscapk/main.py", line 100, in perform_obfuscation raise FileNotFoundError( FileNotFoundError: Unable to find application file "/Users/umer/Desktop/app-release.apk"

ClaudiuGeorgiu commented 1 year ago

Please see https://github.com/ClaudiuGeorgiu/Obfuscapk/issues/127#issuecomment-1027705016. Also, I suggest starting only with -o Rebuild -o NewAlignment -o NewSignature obfuscators and without specifying the keystore, just to check that basic commands work (if that works, then you can add all the other parameters, this way it will be easier to debug in case of errors).

umerbutt03 commented 1 year ago

docker run -v "/Users/umer/Desktop/":"/workdir" obfuscapk -w /workdir/obfuscation_dir/ -o ConstStringEncryption -o ClassRename -o DebugRemoval -o Nop -o Goto -o RandomManifest -o Rebuild -o NewAlignment -o NewSignature -o LibEncryption -d /workdir/APPNAME.apk -i -p --keystore-file /workdir/APPNAME_docs/APPNAME_keystore_credentials/APPNAME_keystore --keystore-password KEYSTORE_PASSWORD --key-alias key0 --key-password KEYSTORE_PASSWORD --use-aapt2 /workdir/app-release.apk

@ClaudiuGeorgiu now it's giving me below error, after running above command.

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 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/rebuild/rebuild.py", line 20, in obfuscate obfuscation_info.build_obfuscated_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 555, in build_obfuscated_apk apktool.build( File "/Obfuscapk/obfuscapk/tool.py", line 166, in build 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 '['/usr/local/bin/apktool', '--frame-path', '/tmp', 'b', '--force-all', '/workdir/obfuscation_dir/app-release', '--use-aapt2', '-o', '/workdir/APPNAME.apk']' returned non-zero exit status 1.

ClaudiuGeorgiu commented 1 year ago

I suggest starting only with -o Rebuild -o NewAlignment -o NewSignature obfuscators and without specifying the keystore, just to check that basic commands work.

If this works, the issue is with one of the obfuscators, otherwise it's an Apktool issue (or the app is using some anti-repackaging technique).

umerbutt03 commented 1 year ago

docker run -v "/Users/umer/Desktop/":"/workdir" obfuscapk -w /workdir/obfuscation_dir/ -o Rebuild -o NewAlignment -o NewSignature -d /workdir/APPNAME.apk -p /workdir/app-release.apk

@ClaudiuGeorgiu now it's giving me below error, after running above command.

Running obfuscators (Rebuild): 0%| |[00:00<?, ?obfuscator/s]03/10/2022 13:07:51> [ERROR][obfuscapk.tool.Apktool][build()] Error during build command: I: Using Apktool 2.6.0 I: Smaling smali folder into classes.dex... I: Building resources... W: /workdir/obfuscation_dir/app-release/res/values/styles.xml:2396: error: Resource entry ThemeOverlay.ZendeskComponents.ConnectionBannerStyle already has bag item connectionBannerSuccessLabelColor. W: /workdir/obfuscation_dir/app-release/res/values/styles.xml:2395: Originally defined here. W: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_17134922656831643165471453308355144108.tmp, p, --forced-package-id, 127, --min-sdk-version, 22, --target-sdk-version, 32, --version-code, 50, --version-name, 1.0.49, --no-version-vectors, -F, /tmp/APKTOOL4047931180551342106.tmp, -e, /tmp/APKTOOL7962325335266040391.tmp, -0, arsc, -I, /tmp/1.apk, -S, /workdir/obfuscation_dir/app-release/res, -M, /workdir/obfuscation_dir/app-release/AndroidManifest.xml]

03/10/2022 13:07:51> [ERROR][obfuscapk.obfuscation][build_obfuscated_apk()] Error during apk building: Command '['/usr/local/bin/apktool', '--frame-path', '/tmp', 'b', '--force-all', '/workdir/obfuscation_dir/app-release', '-o', '/workdir/APPNAME.apk']' returned non-zero exit status 1. 03/10/2022 13:07:51> [ERROR][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Error during execution of "Rebuild" obfuscator: Command '['/usr/local/bin/apktool', '--frame-path', '/tmp', 'b', '--force-all', '/workdir/obfuscation_dir/app-release', '-o', '/workdir/APPNAME.apk']' returned non-zero exit status 1. 03/10/2022 13:07:51> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['/usr/local/bin/apktool', '--frame-path', '/tmp', 'b', '--force-all', '/workdir/obfuscation_dir/app-release', '-o', '/workdir/APPNAME.apk']' returned non-zero exit status 1. 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/rebuild/rebuild.py", line 20, in obfuscate obfuscation_info.build_obfuscated_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 555, in build_obfuscated_apk apktool.build( File "/Obfuscapk/obfuscapk/tool.py", line 166, in build 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 '['/usr/local/bin/apktool', '--frame-path', '/tmp', 'b', '--force-all', '/workdir/obfuscation_dir/app-release', '-o', '/workdir/APPNAME.apk']' returned non-zero exit status 1. Running obfuscators (Rebuild): 0%| |[01:21<?, ?obfuscator/s] 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 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/rebuild/rebuild.py", line 20, in obfuscate obfuscation_info.build_obfuscated_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 555, in build_obfuscated_apk apktool.build( File "/Obfuscapk/obfuscapk/tool.py", line 166, in build 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 '['/usr/local/bin/apktool', '--frame-path', '/tmp', 'b', '--force-all', '/workdir/obfuscation_dir/app-release', '-o', '/workdir/APPNAME.apk']' returned non-zero exit status 1.

umerbutt03 commented 1 year ago

@ClaudiuGeorgiu I want to tell more thing, I developed application on Flutter Framework. It's alreay obfuscated many code, but it didn't obfuscate the com folder.

ClaudiuGeorgiu commented 1 year ago

This seems to be an Apktool issue, since it's not able to rebuild the application even when no obfuscator is used. You could try using the latest version of Apktool (v2.6.1). However, Obfuscapk was not tested with Flutter applications, so I'm not sure that it will work (even if Apktool was able to rebuild the app).