Certificate Pinning Bypass
Certificate pinning is a security mechanism that restricts which certificates are trusted for a particular connection. Bypassing it is essential for intercepting HTTPS traffic during mobile app pentesting.
What is Certificate Pinning?
Types of Certificate Pinning
Certificate Pinning
Pins the entire certificate. If the certificate changes (e.g., renewal), the pin must be updated.
Public Key Pinning
Pins only the public key (SPKI). The same key can be used across certificate renewals.
Which of the two is in place changes what a successful bypass means. A certificate pin breaks at renewal, so intercepting one describes a brittle control rather than a missing one; a public-key pin survives renewal and is recorded as an SPKI hash, which makes the hash the evidence rather than the certificate. Neither is the same as absent pinning: if a user CA is trusted and traffic decrypts with no hook at all, the finding is missing pinning, not a bypass.
Where Pinning Is Actually Enforced
The same app can pin in three places on Android, and each fails to a different technique. A
network_security_config
pin is declarative: the platform reads it when it builds a socket's trust manager, so everything
on the platform HTTP stack inherits it and everything that replaces that stack does not. A pin in
application code — an OkHttp
CertificatePinner,
a custom X509TrustManager,
a hostname verifier installed by hand — runs after the platform has accepted a chain, and never
consults the config. A pin inside a native library, where Flutter's BoringSSL and some SDKs keep
theirs, sits below Java, and no
Java.use
call reaches it however many class names a universal script resolves.
iOS splits the same way: App Transport Security in Info.plist,
pinning in app code — an AFSecurityPolicy
mode, a TrustKit configuration, a URLSession
delegate inspecting the challenge — and the same class of bundled library. The layer decides what
to run and what a success means, so decide it before choosing a tool.
The Bypass Ladder
Each rung costs more than the one before it and answers a different question, so start at the top and record which rung worked.
| Rung | What it requires | What it does not prove |
|---|---|---|
| Existing trust | A user CA the app accepts, or a build whose config trusts one | Anything — decryption here means no pin was ever evaluated |
| Hook the verifier | An instrumented device and the class the app actually reaches | That the pin was defeated rather than never reached |
| Replace the stored pin | The pinned certificate or hash where the build keeps it, plus a re-signed APK | That other hosts pin the same way, or that integrity checks still pass |
| Patch the config in a repackaged build | Decompile, edit the trust anchors or ATS keys, rebuild, align, sign | Anything about a pin written in code: that check still runs |
| Patch the native library | The symbol or offset in this build, and enough TLS code to know what to change | Portability to another build, or that a check above the patch is not running |
Name the rung in the report, with the artefact patched and its hash, the chain before and after — leaf, issuer, SPKI hash — and whether the app's own pin was still evaluated. A config change that leaves an app-level pin running has not defeated that pin, however much traffic reaches the proxy.
Android Bypass Techniques
1. Frida Universal Bypass
The most reliable method for bypassing certificate pinning on Android:
// Universal Android SSL Pinning Bypass
Java.perform(function() {
// TrustManagerImpl bypass
var TrustManagerImpl = Java.use('com.android.org.conscrypt.TrustManagerImpl');
TrustManagerImpl.verifyChain.implementation = function(untrustedChain, trustAnchorChain, host, clientAuth, ocspData, tlsSctData) {
console.log('[+] Bypassing TrustManagerImpl.verifyChain for: ' + host);
return untrustedChain;
};
// OkHttp3 CertificatePinner bypass
try {
var CertificatePinner = Java.use('okhttp3.CertificatePinner');
CertificatePinner.check.overload('java.lang.String', 'java.util.List').implementation = function(hostname, peerCertificates) {
console.log('[+] Bypassing OkHttp3 CertificatePinner for: ' + hostname);
return;
};
} catch(e) {
console.log('[-] OkHttp3 not found');
}
// Retrofit/OkHttp bypass
try {
var OkHttpClient = Java.use('okhttp3.OkHttpClient$Builder');
OkHttpClient.certificatePinner.implementation = function(certificatePinner) {
console.log('[+] Bypassing OkHttpClient.certificatePinner');
return this;
};
} catch(e) {
console.log('[-] OkHttpClient not found');
}
// HttpsURLConnection hostname verification (platform client, not Apache's)
try {
var HttpsURLConnection = Java.use('javax.net.ssl.HttpsURLConnection');
// Suppress the app's own hostname verifier so the platform default is what runs
HttpsURLConnection.setDefaultHostnameVerifier.implementation = function(hostnameVerifier) {
console.log('[+] setDefaultHostnameVerifier suppressed');
return;
};
} catch(e) {}
});Run with Frida:
frida -U -f com.target.app -l android_ssl_bypass.js
Suppressing a custom
HostnameVerifier
does not weaken verification: it removes the app's override so the platform's own hostname verifier
runs instead, and that verifier rejects a mismatched host where an override returning true for any
host would not. A console line saying the setter was suppressed is therefore not a bypass. What
counts is that the connection completes against the pinned host and
that the certificate the client accepted is the one your proxy presented — read the leaf and issuer
out of the proxy history, not out of the console. If the app still dies at the pinning failure,
nothing was bypassed; if the hooked class was never reached on the path you exercised, you have a
log line and no evidence.
2. Objection Bypass
Quick bypass using objection:
# Start objection
objection -g com.target.app explore
# Inside objection shell:
android sslpinning disable
# Or spawn with bypass enabled
objection -g com.target.app explore --startup-command "android sslpinning disable"3. Network Security Config (Android 7+)
Modify the app to trust user certificates by editing the APK:
# Decompile APK
apktool d target.apk -o target_decompiled
# Create/edit res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
# Add to AndroidManifest.xml in <application> tag:
# android:networkSecurityConfig="@xml/network_security_config"
# Rebuild, align, then sign: a v2 signature covers the archive bytes,
# so zipalign has to run before apksigner, not after
apktool b target_decompiled -o target_unaligned.apk
zipalign -f 4 target_unaligned.apk target_patched.apk
apksigner sign --ks my.keystore --ks-key-alias alias_name --v1-signing-enabled false --v2-signing-enabled true target_patched.apk
# Verify, then install. v1/SHA-1 signatures are rejected from Android 11 (API 30)
apksigner verify --print-certs target_patched.apk
adb install -r target_patched.apkiOS Bypass Techniques
1. Frida iOS Bypass
// iOS Universal SSL Pinning Bypass
if (ObjC.available) {
// Bypass NSURLSession
var NSURLSession = ObjC.classes.NSURLSession;
Interceptor.attach(NSURLSession['- URLSession:didReceiveChallenge:completionHandler:'].implementation, {
onEnter: function(args) {
console.log('[+] Intercepting NSURLSession challenge');
var completionHandler = new ObjC.Block(args[4]);
var NSURLSessionAuthChallengeUseCredential = 0;
completionHandler.implementation = function(disposition, credential) {
console.log('[+] Accepting credential');
completionHandler(NSURLSessionAuthChallengeUseCredential, null);
};
}
});
// Bypass AFNetworking
try {
var AFSecurityPolicy = ObjC.classes.AFSecurityPolicy;
AFSecurityPolicy['- setSSLPinningMode:'].implementation = function(mode) {
console.log('[+] Bypassing AFNetworking pinning mode');
this.setSSLPinningMode_(0);
};
AFSecurityPolicy['- setAllowInvalidCertificates:'].implementation = function(allow) {
console.log('[+] Allowing invalid certificates');
this.setAllowInvalidCertificates_(1);
};
} catch(e) {
console.log('[-] AFNetworking not found');
}
// Bypass TrustKit
try {
var TrustKit = ObjC.classes.TrustKit;
TrustKit['+ setUpSharedInstanceWithConfiguration:'].implementation = function(config) {
console.log('[+] Bypassing TrustKit initialization');
return;
};
} catch(e) {
console.log('[-] TrustKit not found');
}
}2. Objection iOS Bypass
# Connect to iOS app
objection -g com.target.app explore
# Disable SSL pinning
ios sslpinning disable
# Hook specific pinning methods
ios sslpinning disable --quiet3. SSL Kill Switch 2
On a jailbroken device, a tweak such as SSL Kill Switch 2 disables certificate validation globally, so a proxy CA is accepted without a per-app hook.
# Install it from a package manager on the device that still serves packages
# Or install a .deb you already have
dpkg -i sslkillswitch2.deb
killall -9 SpringBoardBypassing Specific Implementations
| Library | Platform | Bypass Method |
|---|---|---|
| OkHttp3 | Android | Hook CertificatePinner.check() |
| Retrofit | Android | Hook OkHttp (uses OkHttp internally) |
| AFNetworking | iOS | Hook AFSecurityPolicy methods |
| TrustKit | iOS | Hook TSKPinVerifier |
| Flutter | Both | Patch ssl_x509.cc in libflutter.so |
| React Native | Both | Hook native HTTP client (OkHttp/NSURLSession) |
The table gives a starting hook per library, not a verdict. Name the implementation before
reporting the bypass — an OkHttp
CertificatePinner,
a TrustManager, a network security config and an App Transport Security setup are four different
controls, and a finding that does not say which one it defeated cannot be retested. A catch-all
script that hooks every trust manager also invalidates the result for a specific host, because it
stops being clear which check was defeated.
Proxy Configuration
Before Bypassing
Two results get mixed up at this stage. Traffic that appears only because the app retried over HTTP is a transport finding rather than a pinning result, and a clean proxy history for an app that failed to authenticate proves nothing about pinning at all. WebView requests follow the platform trust store and may not be pinned at all, so report them separately from the app's own client traffic.
Android CA Install
# Export Burp CA as DER
# Convert to PEM
openssl x509 -inform DER -in cacert.der -out cacert.pem
# Get hash
openssl x509 -inform PEM -subject_hash_old -in cacert.pem | head -1
# Rename and push
mv cacert.pem 9a5ba575.0
adb root
adb remount
adb push 9a5ba575.0 /system/etc/security/cacerts/
adb shell chmod 644 /system/etc/security/cacerts/9a5ba575.0iOS CA Install
# 1. Export Burp CA
# 2. Host on local server:
python3 -m http.server 8080
# 3. On iOS device:
# Navigate to http://YOUR_IP:8080/cert.der
# Install profile in Settings
# 4. Trust certificate:
# Settings > General > About >
# Certificate Trust Settings >
# Enable "Burp Certificate"Troubleshooting
A host that stayed pinned is a result and should be recorded as one: keep the failure output and the attempt that produced it, so the absence of interception is evidenced rather than assumed. A bypass that failed because the script was stale says nothing about the control either way.
Bypass not working?
- Check if the app uses a custom HTTP library
- Try multiple bypass scripts in combination
- Look for obfuscated pinning code
- Check if the app has root/jailbreak detection
App crashes after bypass?
- The bypass script might be too aggressive
- Try a more targeted approach for specific libraries
- Check Frida console for errors
- App might have integrity checks
Practice Lab
Pin a public key in your own app, watch the proxy connection fail, then bypass your own pin with a hook targeted at the class that raised the failure — done when the failure and the bypass are both demonstrated and you can say which kind of pin you implemented and at which of this page's three layers it lives.
Evidence to Capture
Target and build: The host being pinned, the app version and build, and the platform.
Pinning implementation: The class or configuration performing the check: an OkHttp CertificatePinner, a TrustManager, a network security config or an ATS setup.
Bypass artefact: The Frida or Objection command, the script hash, and the console output showing the hook installed.
Intercepted exchange: A proxy history entry with the host, path, request headers and response status.
Negative result: For a host that stayed pinned, the failure output and the attempt made.
Certificate chain: The leaf and issuing chain observed, with the SPKI hash where the bypass depended on swapping trust.
Likely False Positives
- Bypassed only under instrumentation: A universal hook installed on the test device.
- No pinning configured, no bypass needed: A user CA trusted and traffic decrypted with no hook.
- Host never contacted: An empty proxy history on an unauthenticated session.
- Fallback to cleartext: Traffic that appeared over HTTP after a retry.
- Catch-all hook disabled TLS verification: A catch-all trust-manager hook.
- WebView traffic attributed to the app client: WebView requests follow the platform store.
- Failed bypass read as pinning strength: A bypass that failed on a stale script.
Testing Checklist
Client
- ☐ Pinning implementation located and named
- ☐ Hosts covered by the pin listed, including CDN and API hosts
- ☐ Backup pin presence and rotation plan checked
- ☐ Pinning applied in the release configuration, not only in debug
Transport
- ☐ User CA trust and network security config state recorded
- ☐ Interception attempted per host rather than only at app launch
- ☐ TLS version and HSTS headers inspected
- ☐ Certificate chain recorded with SPKI hashes where the pin depends on it
Verification
- ☐ Proxy history retained as evidence for every intercepted host
- ☐ Negative results recorded with the attempt that produced them
- ☐ Bypass script version and tool version recorded
- ☐ A retest note added for any host that could not be intercepted
Scope
- ☐ System and third-party SDK traffic separated from app traffic
- ☐ WebView traffic reported separately
- ☐ Findings limited to hosts the app actually contacts
- ☐ Any host the client excluded recorded as a limitation
Remediation & Defense
Client pinning
- • Pin the public key rather than the leaf certificate, so renewal does not break the app
- • Ship at least one backup pin and document the rotation procedure
- • Keep pinning active in release builds and remove debug-only trust anchors
- • Exclude user-added CAs from the trust store where the platform allows it
Transport
- • Require TLS 1.2 or later and reject cleartext in the network security config or ATS
- • Enable HSTS on the hosts the app talks to, with preload where the domain allows
- • Keep certificate lifetimes short and monitor for unexpected issuers
Server
- • Serve a stable public key across CDN and origin, and monitor certificate changes
- • Alert when clients present an unexpected chain, so a bypass attempt becomes visible
- • Treat successful interception of a pinned host as an incident signal, not only a finding
Process
- • Record which hosts are pinned so a retest does not re-derive it
- • Add a pinning regression check to release QA
- • Document the threat model pinning addresses, so a bypass is scoped correctly