httptoolkit-server icon indicating copy to clipboard operation
httptoolkit-server copied to clipboard

Cannot get list of apps using frida method on Android

Open victor141516 opened this issue 1 year ago • 7 comments

A couple days ago this was working fine with the same computer and the same Android device, but today it's stuck in "Scanning for apps to intercept..."

I'm debugging the issue, but it's taking more time than I expected and maybe Tim can solve this issue faster.

Specificly this line is not resolving: https://github.com/httptoolkit/httptoolkit-server/blob/main/src/interceptors/frida/frida-android-integration.ts#L193

And deeper, in frida-js line 191 does resolve but line 192 doesn't.

It just doesn't resolve at all, but there is a timeout here so the request from the ui is completed but doesn't contain anything ({})

I don't have much experience with D-Bus or Frida so I'm having issues debugging deeper.

Thank you! and congrats for the product and the codebase, very straightforward to follow

victor141516 avatar Sep 27 '24 16:09 victor141516

Hmm, that's interesting. My best guess is that the frida server has just got stuck somewhere. That shouldn't happen, but it can do in some cases. What happens if you restart the device? You could also adb shell in and kill frida-server to ensure it gets restarted, if that's easier.

In future I'd like to try to detect this - as long as there's no intercepted apps currently running, there's no downside to restarting Frida if it becomes unresponsive,

pimterry avatar Sep 30 '24 11:09 pimterry

I restarted both the computer and the phone, but no luck. Later today I'll try to adb shell and debug from there.

Thanks for the tips!

victor141516 avatar Sep 30 '24 13:09 victor141516

Hmm, ok, that's very weird then.

The next thing I'd test for comparison is installing & querying Frida manually using the CLI (guide: https://httptoolkit.com/blog/frida-certificate-pinning/#install-and-start-frida-on-the-device). The server uses Frida 16.3.3.

If that works, it would be interesting to try restarting the device, launching a normal Frida server (which should result in HTTP Toolkit not launching its own) and then trying to use that.

Digging into the differences here bit by bit, somewhere we should eventually either find out that Frida doesn't work on the device at all (so there's a Frida/device issue to investigate, or maybe we need to update or something) or there's some specific part of HTTP Toolkit that's breaking something here, and we can then dig into that particular failure directly.

pimterry avatar Sep 30 '24 14:09 pimterry

Great! I was able to fix it :D

When I was trying to do frida-ps -U I was getting this error: Failed to enumerate processes: unable to perform ptrace pokedata

Then I saw in an issue in the fridaa repo that installing MagiskFrida may fix it, and indeed something changes. Now frida-ps -U prints cannot read properties of undefined (reading 'getRunningAppProcesses') 🎉

Also in this issue someone said that running pm uninstall com.google.android.art fixes it and man it does

So happy end! Thanks for the support!

Edit: I think this is the root cause: https://github.com/frida/frida/issues/2958

victor141516 avatar Sep 30 '24 17:09 victor141516

I see, glad that's working for you now, thanks for the details @victor141516! I don't think HTTP Toolkit should reasonably uninstall system packages like com.google.android.art for you automatically, so this'll have to be a manual fix for any other people affected too, but I'll keep an eye on https://github.com/frida/frida/issues/2958 and update to a working Frida as soon as that's been resolved.

pimterry avatar Oct 01 '24 12:10 pimterry

don't think HTTP Toolkit should reasonably uninstall system packages like com.google.android.art for you automatically

Yeah that's for sure! However having some logic to detect this situation (as you suggested) could be a good improvement. Would you mind if I spend some time on it? I can send a PR in a few days

victor141516 avatar Oct 01 '24 17:10 victor141516

Sure! Yeah, if it's possible to detect it and return an error from the server to the UI, that could definitely help. Returning a brief explanation with a link to this issue is probably the best solution, then it's easy to update with more info here later.

pimterry avatar Oct 02 '24 13:10 pimterry

Frida have now released a fix for this, and I've just published a new HTTP Toolkit update with that included. Next time you run HTTP Toolkit, it'll update in the background, and the following time this should work correctly!

You will see the "Frida Installation required" step again when you pick a device if it had Frida before, and when you click that it'll automatically update the device's Frida version to the new working release before listing the apps (just takes a few seconds). Once that's done it should work correctly even on devices with the new com.google.android.art version.

Thanks for reporting this issue! Good to be able to get that fixed. I'll close this as resolved now, but please get in touch if you're still having any issues after updating.

pimterry avatar Jan 13 '25 15:01 pimterry

Frida have now released a fix for this, and I've just published a new HTTP Toolkit update with that included. Next time you run HTTP Toolkit, it'll update in the background, and the following time this should work correctly!

You will see the "Frida Installation required" step again when you pick a device if it had Frida before, and when you click that it'll automatically update the device's Frida version to the new working release before listing the apps (just takes a few seconds). Once that's done it should work correctly even on devices with the new com.google.android.art version.

Thanks for reporting this issue! Good to be able to get that fixed. I'll close this as resolved now, but please get in touch if you're still having any issues after updating.

i don't think that fully fixed it, i'm still having this issue on lineageos 22.2 (android 15) where the com.google.android.art package doesn't even exist. also the frida cli works fine, e.g. uvx --from frida-tools frida-ps -Ua so it seems like this is an http toolkit issue

HyperKiko avatar May 13 '25 17:05 HyperKiko

@HyperKiko, from your description, it sounds like you're running your own Frida server (HTTP Toolkit's Frida installation is run on a separate non-standard port, so the command you suggest wouldn't work). The HTTP Toolkit fix here only applies when using HTTP Toolkit to install & launch Frida server for you. Which Frida server version are you using?

Alternatively, it might be that you're somehow running two Frida servers on the device at the same time, which could also plausibly cause issues I imagine.

pimterry avatar May 14 '25 11:05 pimterry

@HyperKiko, from your description, it sounds like you're running your own Frida server (HTTP Toolkit's Frida installation is run on a separate non-standard port, so the command you suggest wouldn't work). The HTTP Toolkit fix here only applies when using HTTP Toolkit to install & launch Frida server for you. Which Frida server version are you using?

Alternatively, it might be that you're somehow running two Frida servers on the device at the same time, which could also plausibly cause issues I imagine.

i've tried restarting and using the built in frida server in http toolkit and get the same issue

HyperKiko avatar May 14 '25 11:05 HyperKiko

No idea I'm afraid. The only thing I know that can cause this is the bug in Frida < 16.6, and I haven't heard any other reports of this since then. If you're still seeing this then there's something else unusual happening with your device I suspect.

If you'd like to dig into it in depth, the code we use to talk to Frida is here: https://github.com/httptoolkit/frida-js/. It's quite simple, just a thin wrapper around Frida's API to send an enumerateApplications message and unwrap the response. That's called from HTTP Toolkit here. I'm not aware of any scenario where Frida would successfully return apps elsewhere, but wouldn't do so with this setup.

pimterry avatar May 16 '25 12:05 pimterry

i'll try to clone the repo locally and debug the issue

HyperKiko avatar May 16 '25 12:05 HyperKiko