npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apk-mitm

v1.3.0

Published

A CLI application that automatically prepares Android APK files for HTTPS inspection

Downloads

1,398

Readme

apk-mitm

A CLI application that automatically prepares Android APK files for HTTPS inspection

Inspecting a mobile app's HTTPS traffic using a proxy is probably the easiest way to figure out how it works. However, with the Network Security Configuration introduced in Android 7 and app developers trying to prevent MITM attacks using certificate pinning, getting an app to work with an HTTPS proxy has become quite tedious.

apk-mitm automates the entire process. All you have to do is give it an APK file and apk-mitm will:

You can also use apk-mitm to patch apps using Android App Bundle and rooting your phone is not required.

⚠️ Limitations & alternatives

Modifying the regular behavior of an app to work around security features like certificate pinning requires either modifying the app's source code before running it or "hooking" the app while it is running to intercept function calls.

apk-mitm is currently taking the former approach of modifying the app's code by first "disassembling" the app using Apktool, making changes to several files, and then assembling it back together (again using Apktool).

This approach has the benefit that it doesn't require a rooted device but it also has several drawbacks. The biggest problem is that apps aren't really meant to be disassembled. Apktool tries to achieve that anyway but, especially with big and complex apps, it often runs into problems.

Another issue with this approach is that some certificate pinning methods, like checks performed within native binaries (as is the case for frameworks like Flutter), are either very hard or impossible to circumvent. For this reason, it can be beneficial to try out other approaches for more tricky apps.

Specifically, I'd like to highlight mitmproxy's android-unpinner project and the underlying frida-interception-and-unpinning scripts by HTTP Toolkit. Their approach applies patches at runtime using Frida, which is a lot more powerful but also means that it either can't be used or is more difficult to use without a rooted device.

Installation

If you have an up-to-date version of Node.js (14+) and Java (8+), you can install apk-mitm by running:

npm install -g apk-mitm

Usage

Once installed, you can run this command to patch an app:

apk-mitm <path-to-apk>

Patching an APK file called example.apk might look like this:

$ apk-mitm example.apk

  ✔ Decoding APK file
  ✔ Modifying app manifest
  ✔ Replacing network security config
  ✔ Disabling certificate pinning
  ✔ Encoding patched APK file
  ✔ Signing patched APK file

   Done!  Patched APK: ./example-patched.apk

You can now install the example-patched.apk file on your Android device and use a proxy like Charles or mitmproxy to look at the app's traffic.

Patching App Bundles

You can also patch apps using Android App Bundle with apk-mitm by providing it with a *.xapk file (for example from APKPure) or a *.apks file (which you can export yourself using SAI). If you're doing this on Linux, make sure that both zip and unzip are installed.

Making manual changes

Sometimes you'll need to make manual changes to an app in order to get it to work. In these cases the --wait option is what you need. Enabling it will make apk-mitm wait before re-enconding the app, allowing you to make changes to the files in the temporary directory.

If you want to experiment with different changes to an APK, then using --wait is probably not the most convenient option as it forces you to start from scratch every time you use it. In this case you might want to take a look at APKLab. It's an Android reverse engineering workbench built on top of VS Code that comes with apk-mitm support and should allow you to iterate much more quickly.

Allowing specific certificates

On some devices (like Android TVs) you might not be able to add a new certificate to the system's root certificates. In those cases you can still add your proxy's certificate directly to the app's Network Security Config since that will work on any device. You can accomplish this by running apk-mitm with the --certificate flag set to the path of the certificate (.pem or .der file) used by your proxy.

Caveats

  • If the app uses Google Maps and the map is broken after patching, then the app's API key is probably restricted to the developer's certificate. You'll have to create your own API key without restrictions and run apk-mitm with the --wait option to be able to replace the com.google.android.geo.API_KEY value in the app's AndroidManifest.xml file.

  • If apk-mitm crashes while decoding or encoding the issue is probably related to Apktool. Check their issues on GitHub to find possible workarounds. If you happen to find an Apktool version that's not affected by the issue, you can instruct apk-mitm to use it by specifying the path of its JAR file through the --apktool option.

Thanks

License

MIT © Niklas Higi