Method 1: apk-mitm

apk-mitm is a CLI application that prepares Android APK files for HTTPS inspection that automates the entire process. In the How it Works section you will find more details, but as a summary 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.

Requirements

  1. Apktool

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

Install Node JS

brew install nodejs

Install/update apk-mitm

npm install -g apk-mitm

Patch APK

apk-mitm example.apk

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

Install APK (from adb)

adb <-s DEVICE_ID> install example-patched.apk

How it Works

Decode the APK file

Using Apktool

Modify the app's AndroidManifest.xml

To make it debuggable

To allow user-added certificates. The Network Security Configuration feature lets apps customize their network security settings in a safe, declarative configuration file without modifying app code. These settings can be configured for specific domains and for a specific app. So you can customize which Certificate Authorities (CA) are trusted for an app's secure connections. For example, trusting particular self-signed certificates or restricting the set of public CAs that the app trusts.

Once your target APK is properly disassembled, look for AndroidManifest.xml at the root folder and add the following attribute to the application element:

<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config" ... >
        ...
    </application>
</manifest>

That attribute points to the file res/xml/network_security_config.xml inside your project. If it doesn't, create it now and change its contents to be like this:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>  
      <base-config>  
            <trust-anchors>  
                <!-- Trust preinstalled CAs -->  
                <certificates src="system" />  
                <!-- Additionally trust user added CAs -->  
                <certificates src="user" />  
           </trust-anchors>  
      </base-config>  
 </network-security-config>

This rule tells the Android system to accept any system or user certificates, overriding default behavior. See this page for other overriding options.

To disable certificate pinning logic

Encode the patched APK file

Using Apktool

Sign the patched APK file

Using uber-apk-signer

Last updated