sensepost / objection

📱 objection - runtime mobile exploration
GNU General Public License v3.0
7.54k stars 855 forks source link

[bug] Win10 apktool version parsing #345

Closed forgotPassword closed 4 years ago

forgotPassword commented 4 years ago

Hi, in latest version objection fails to detect apktool version:

print(o)
2.4.1
Press any key to continue . . .

The 'Press any key to continue' breaks parsing functionality..

rmills commented 4 years ago

I can second this issue, running the latest 2.4.1, Windows 10

No architecture specified. Determining it using adb... Detected target device architecture as: armeabi-v7a Using latest Github gadget version: 12.8.19 Patcher will be using Gadget version: 12.8.19 Detected apktool version as: 2.4.1 Press any key to continue . . . apktool version should be at least 2.4.1 Please see the following URL for more information: https://github.com/sensepost/objection/wiki/Apktool-Upgrades apktool is not ready for use

rmills commented 4 years ago

A dirty fix for now is adding the following to line 235 in objection\utils\patchers\android.py

o = str(o).splitlines()[0]

This is obviously not the correction solution, I don't know what is causing the "press any key to continue". Running apktool --version from the command line does not show this. So I would be blaming something in the block starting on line 225 but did not chase any farther.

o = delegator.run(list2cmdline([
            self.required_commands['apktool']['location'],
            '-version',
        ]), timeout=self.command_run_timeout).out.strip()
leonjza commented 4 years ago

Happy to take a PR that checks if the output has Press any key to continue and then split like suggested.

leonjza commented 4 years ago

(not a Windows user) I am guessing this is an artefact of command processing library we are using. The following patch seems to pass the version detection correctly on Windows. I hacked by environment in a VM pretty badly to get to this step, so if anyone can test that this actually fixes the problem then we can push to master.

diff --git a/objection/utils/patchers/android.py b/objection/utils/patchers/android.py
index df0703c..d7810dc 100644
--- a/objection/utils/patchers/android.py
+++ b/objection/utils/patchers/android.py
@@ -227,6 +227,10 @@ class AndroidPatcher(BasePlatformPatcher):
             '-version',
         ]), timeout=self.command_run_timeout).out.strip()

+        # windows / delegator weirdness...
+        if 'Press any key to continue . . .' in o:
+            o = o.split('\n')[0]
+
         if len(o) == 0:
             click.secho('Unable to determine apktool version. Is it installed')
             return False
rmills commented 4 years ago

Patch worked for me.

Not:e I had to upgrade frida to 12.8.20 as at least 12.8.19 was throwing "Unable to determine URL for Android gadget download.", might need to update dependency as well.

leonjza commented 4 years ago

A new Frida release was just made. The assets take a while to upload from the build sever.

rmills commented 4 years ago

Ah gotcha, I can't think of any scenario the patch does not work. Probably safe to push to the master.