Intercepting Android HTTP
Intercepting Android HTTP
Intercepting Android HTTP
HTTP
Help improve these docs on GitHub
HTTP Toolkit can automatically intercept, inspect & rewrite traffic from any
Android device.
For a quick demo and an outline of how this works, check out the HTTP Toolkit for
Android page, or read on for a detailed guide.
For many cases, including most browser traffic, emulators, and rooted devices, this
works with zero manual setup required.
To intercept secure HTTPS traffic from other apps on non-rooted devices, you'll
need to either:
If you're trying to intercept HTTPS from a 3rd party app or an existing build that
can't be easily changed, you'll usually want to use an emulator or rooted device
instead.
Keep reading to get started right away, or jump to the full details for your case
in 'Intercepting HTTPS traffic from your own app' or 'Intercepting HTTPS traffic
from 3rd party apps'.
Once this is complete, you're good to go. All apps' HTTP traffic will be intercepted
and shown on your computer, and HTTPS traffic from apps that trust user-installed
CAs will appear too. Hit the "Test Interception" button to open a test page that will
confirm that HTTP Toolkit can successfully collect & rewrite traffic from your
device.
If you do have running apps that don't trust the CA, you'll see events in HTTP
Toolkit like "Certificate rejected for <domain>" and "HTTPS setup failed for
<domain>". If you see events like these related to apps you'd like to intercept, you'll
need to either configure those apps to trust user-installed CA certificates, or use a
rooted device or emulator with ADB-based setup to install a system CA certificate.
Each of these cases are covered in more detail below.
If not, you need to explicitly opt in to trusting the CA certificate. You'll know this is
happening because you'll see messages in HTTP Toolkit like "Certificate rejected for
connection to..." and "Aborted connection to..." and "HTTPS setup failed for...".
Each of these typically means the application rejected our HTTPS interception
before sending its requests.
To fix this you need to trust user-installed certificates in your app, like so:
This configures your application to trust both built-in & user-added CA certificates
for all HTTPS connections, for debug & release builds.
You can include this in your config at all times, and it will work with and without
HTTP Toolkit. The only risk is that your end users will be able to intercept their own
HTTPS traffic from your app, and potentially any users who are tricked into trusting
an attacker's CA could have their traffic intercepted. For most applications that isn't a
major concern.
If you'd like to enable this only for your debug builds, replace base-
config with debug-overrides in the XML above.
See Android's network security config documentation for more details.
If you already have a custom network security config:
Add <certificates src="user" overridePins="true" /> within the <trust-
anchors> element of either your <base-config> element (to trust user-added
certificates for all builds) or <debug-overrides> (to trust user-added certificates in
debug builds only).
See Android's network security config documentation for more details.
o Official emulators, using the standard Google API or AOSP builds (but
not 'Google Play' builds)
o Genymotion emulators
o Any other ADB device where adb shell su or adb root are available
In some of these cases you won't have the Google Play Store available, which can be
inconvenient for reverse engineering. To fix that, you can use Open GAPPS to install
Google tools manually, or you can download individual APKs directly, from sites
such like ApkPure or APKMirror.
To install a system certificate, first connect a supported device using ADB, and the
"Android device connected via ADB" interception option will appear on the
'Intercept' page in your HTTP Toolkit application. Click that, and the certificate will
be added as a system certificate on the device, the HTTP Toolkit Android app will be
installed if not already present (this may take 10 seconds or so), and then interception
will start up automatically.
When system interception is installed successfully, it's shown in the app:
The system CA cert is installed using a temporary filesystem in place of the device's
real certificate store, and will disappear next time the device reboots. For the full
low-level details, see 'The Technical Details' below.
Troubleshooting rooted Android device setup
If the system CA certificate is not installed successfully, check that it's possible to
run commands as root with ADB via one of the supported mechanisms:
If you're sure the device is rooted, but HTTP Toolkit is still not automatically
installing the system certificate, please file an issue.
If this is deactivated, it either means that HTTP Toolkit cannot communicate with
ADB on your computer, or that no devices are currently connected successfully.
You can test this yourself by running adb devices in a terminal. If there's a
connected device, this should show output like:
$ adb devices
List of devices attached
<your device name> device
If the device is missing, or any other status such as "offline" or "unauthorized" is
shown, then your device is not properly connected. You may need to accept a
permissions prompt to allow debugging on the device, or to disconnect and reconnect
your device.
It is possible that devices could be connected but not accessible to HTTP Toolkit if
your ADB server runs on a non-default port, so it isn't automatically detected by
HTTP Toolkit. HTTP Toolkit attempts to connect to port 5037 by default. If your
ADB server is running on a different port, you can launch HTTP Toolkit with
the ANDROID_ADB_SERVER_PORT environment variable set to the correct port to allow
it to be detected correctly.
This is common and unavoidable when using HTTP Toolkit on non-rooted devices
or locked-down emulators such as the 'Google Play' official emulator builds. On
those devices, Android makes it impossible to change the system certificate
configuration. In this case many applications will not allow interception by default,
and you will need to modify the target application's configuration to capture it's
traffic. See the instructions above for more details.
When ADB interception is used on rooted devices or emulators (except the 'Google
Play' version of the official emulators), HTTP Toolkit should be able to inject system
certificates for your automatically, so that you don't see this message.
It's possible this could fail however if root access isn't allowed via ADB. Ensure that
one of the following steps works on your device and prints 'root':
If one of the above commands prints 'root' but you're still having problems, you may
find more information in HTTP Toolkit's logs. These can be found in the menu under
"Help" -> "View HTTP Toolkit logs". These logs only store the most recent run of
HTTP Toolkit, so you will want to start the app, re-run ADB interception setup from
scratch, and then check the logs, to ensure the output is correctly logged there.
If you're still not sure what's failing, or you think you've run into a bug here,
please file an issue so this can be investigated & fixed.
o 80
o 443
o 8000
o 8001
o 8080
o 8888
o 9000
TCP packets to other ports, all UDP packets, and ICMP ping packets are sent on as
normal, unchanged.
In addition to this port matching, on Android 10+ the VPN sets a default HTTP
proxy configuration. Most apps will observe this automatically for all HTTP(S)
traffic, allowing HTTP Toolkit to capture this traffic even when sent to ports not in
the above list.
The initial configuration used by the app to communicate with the HTTP Toolkit
desktop app is received either as a QR code or via the ADB connection. This
configuration includes every local network IP address of the computer. The Android
app then connects to that desktop app to retrieve the full HTTPS CA certificate, and
to verify connectivity on at least one of the given IPs.
In each case, the initial configuration includes a certificate fingerprint, to verify that
the HTTP Toolkit instance we connect to is the correct one, and that our HTTPS
MITM is not itself MITM'd.
When connecting, HTTP Toolkit checks that this CA certificate is trusted on the
device, and prompts to install it as a user-installed certificate if not, using the
standard Android APIs to do so.
Then app also prompts for permission to register as a VPN, to allow it to intercept
traffic, as described above. Once complete, the VPN activates, intercepting all traffic,
and a notification is shown whilst this is active.
When the VPN is stopped, the CA remains installed (as a 'user-installed CA')
indefinitely. This is not a significant security risk, as your CA certificate is unique to
you, and the key is stored only on the computer with HTTP Toolkit installed (and
never shared), so it can only used by your own HTTP Toolkit interception. That said,
the certificate can be removed or disabled manually from 'Trusted Credentials' in
your device settings, if required.
The VPN also remains registered, but inactive. The VPN can also be removed
manually from the device settings, if necessary, and cannot activate silently. This is
enforced by Android's own VPN system, which kills the VPN service within seconds
if it is ever running without an attached persistent notification, and also shows a
separate key icon and warning in your notification area whilst any VPN is active on
the device.
ADB interception
ADB interception is managed by the HTTP Toolkit server, running on your
computer as part of the desktop app.
This is used to inject HTTPS system certificates, to automatically install the app if
not present, and to configure the Android app without using any QR codes.
Internally, this uses an existing ADB server or attempts to start its own. Port 5037 is
checked for an existing ADB server by default, which can be overridden with the
standard ANDROID_ADB_SERVER_PORT environment variable. If not available, ADB
will be started using the instance suggested by ANDROID_HOME if set, or by looking
for adb in your PATH otherwise.
Once connected, the ADB interception option will be available in HTTP Toolkit
when at least one device is connected. If multiple devices are connected, you can
pick between them from inside the app after clicking the interception option.
Due to the sensitivity of system certificates and the use of the approach above, this
system CA is installed only temporarily. The next time the device is rebooted, the
extra certificate will unmount and disappear entirely.
On devices where root isn't available, this CA injection process is skipped, and ADB
interception acts as just a convenient alternative to QR code setup for ADB-
connected devices.