objection icon indicating copy to clipboard operation
objection copied to clipboard

Few enhancements to gadget injection into APK (patchapk)

Open Phyks opened this issue 3 years ago • 3 comments

Hi,

Here are a few proposals for enhancements of the patchapk function, in line with https://github.com/sensepost/objection/discussions/582:

-[x] Try to make the default value of flags and arguments clearer to the reader, through the --help interface. Everything enabled by default should now be explicitly stated as such.

  • [x] Inject libfrida-gadget.so by adding it in existing shared libraries if possible, and resort to Activity patching if this is not possible.
  • [x] Let user specify an alternative name of the Frida gadget library to help dodge (basic) anti-frida measures.
  • [x] Use a fuzzy matching of libraries folders inside an APK. If a user uses the base nomenclature from Frida (frida-gadget-xxx-arm64.so.xz => arm64) as provided architecture, it would now match a folder such as arm64-v8a inside the unpacked APK tree.
  • [x] Default to aapt2 for repacking. As far as I understand and experimented, aapt2 should work out of the box for most cases, while regular aapt would often fail on some resources. Is there a specific reason for keeping aapt as default?

Best,

Phyks avatar Nov 12 '22 11:11 Phyks

I should have reworked the various bits discussed. I'm waiting for your latest feedbacks on the remaining points to make a final pass on this MR to ensure everything is clean and mergeable.

Phyks avatar Jun 13 '24 10:06 Phyks

Given that many applications only load the so libraries later on or don't use them at all as you mention, I think it would be better to have this as a secondary mode of operation where you have to specify the library to inject to. Main reason being that it would negatively impact early-instrumentation as the library may only be loaded later on.

This adds to what Leonza mentioned about having a flag to disable it, rather I think it should be set to actively specify to use it. That way you also don't inject into multiple .so libraries.

Sorry for the delay. Think there are a few things to think about. One major thing to add would be to add the ability to skip patching native libraries using a flag.

It might even be worth either adding a command to list the shared object files it can inject into, and/or to use a prompt where the user can select which one to inject into (using prompt_toolkit). Just a suggestion

IPMegladon avatar Jul 10 '24 15:07 IPMegladon

Thanks for the review. However, I'm no longer using objection on a daily basis as I used to. I'm happy to make quick fixups to this MR if you think this is worth it, but let you decide what you want to do (close, pass it to someone else, etc.) if there is some significant dev time required (which I totally understand, I agree with all your points).

Phyks avatar Jul 17 '24 14:07 Phyks