Android App Penetration Testing & Frida Hooks

Frida Hooking for Android: Bypass OkHttp3 SSL Pinning Like a Pro (Step-by-Step Guide)

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction to SSL Pinning and Its Role in Android Security

SSL Pinning is a security mechanism implemented by developers to prevent man-in-the-middle (MITM) attacks. While traditional SSL/TLS verifies the server’s certificate against a set of trusted root Certificate Authorities (CAs), pinning takes it a step further. It means the application expects a specific certificate or public key when communicating with its backend server. If the certificate presented by the server doesn’t match the pinned one, the connection is terminated, regardless of whether it’s signed by a trusted CA. This is a robust defense against attackers who might compromise a CA or issue their own trusted certificates.

For penetration testers and security researchers, SSL pinning presents a significant challenge. To analyze network traffic, tools like Burp Suite or OWASP ZAP rely on acting as a proxy, presenting their own (self-signed) certificates to the client. When an app employs SSL pinning, it will reject these proxy-generated certificates, preventing traffic interception and analysis. This article will guide you through bypassing SSL pinning specifically implemented using OkHttp3 on Android, leveraging the powerful dynamic instrumentation toolkit, Frida.

Understanding OkHttp3 and CertificatePinner

OkHttp3 is a popular HTTP client for Android and Java applications. It provides a robust and efficient way to make network requests. For SSL pinning, OkHttp3 offers the CertificatePinner class. Developers can configure CertificatePinner with specific hashes of server certificates or public keys. During an HTTPS handshake, OkHttp3 will consult its CertificatePinner instance. If the server’s certificate chain does not contain a certificate or public key that matches one of the pinned hashes, the connection fails with an SSLPeerUnverifiedException.

Our goal is to hook into the check method of the okhttp3.CertificatePinner class. By overriding this method, we can effectively tell the application to always trust the presented certificate, thereby bypassing the pinning logic without modifying the application’s bytecode.

Prerequisites for Bypassing SSL Pinning

Before we dive into the hooking process, ensure you have the following tools and setup ready:

  • Rooted Android Device or Emulator: Frida requires root privileges to inject into processes.
  • ADB (Android Debug Bridge): For interacting with your Android device (pushing files, running shell commands).
  • Frida: The Frida command-line tools installed on your host machine. Install via pip install frida-tools.
  • Frida Server: The corresponding Frida server binary pushed and running on your Android device.
  • Burp Suite (or similar proxy): To intercept and inspect HTTPS traffic. Ensure it’s configured to listen on an appropriate port and its CA certificate is installed on your Android device.
  • Target Android Application: An application that uses OkHttp3 and has SSL pinning enabled.

Step-by-Step Guide to OkHttp3 SSL Pinning Bypass with Frida

Step 1: Set up Frida Server on Your Android Device

First, download the correct Frida server binary for your device’s architecture (e.g., frida-server-*-android-arm64 for ARM64 devices) from the Frida releases page. Push it to your device and run it:

adb push /path/to/frida-server /data/local/tmp/frida-server
adb shell

Android Mobile Specs & Compare Directory

Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!

Compare Devices Specs →
Google AdSense Inline Placement - Content Footer banner