Blog Details

9 Different Ways To Bypass SSL Pinning In Android

9 Different Ways To Bypass SSL Pinning In Android

What is SSL Pinning:

Why SSL Pinning should be implemented in Android Applications:

Basic Approach For bypassing SSL Pinning

1. SSL Pinning Bypass via IPtables Traffic Forwarding (Flutter & Xamarin application)

Steps To Bypass SSL pinning via IPtables Traffic Forwarding

  1. Turn on the invisible proxy option in the burp suite

Open burp suite => proxy => Options => edit => Request handling => turn on support invisible peroxy

2. Start adb as root by running the command adb root

3. Flush the existing IPtable rules using below command

adb shell “iptables -t nat -F”

4. Redirect HTTP & HTTPsTraffic using following command

adb shell “iptables -t nat -A OUTPUT -p tcp — dport 80 -j DNAT — to-destination 192.168.1.29:8080” (Destination/system IP)

adb shell “iptables -t nat -A OUTPUT -p tcp — dport 443 -j DNAT — to-destination 192.168.1.29:8080” (Destination/system IP)

5. Activate Masquerading for HTTP & HTTPs using following command

adb shell “iptables -t nat -A POSTROUTING -p tcp — dport 443 -j MASQUERADE”

adb shell “iptables -t nat -A POSTROUTING -p tcp — dport 80 -j MASQUERADE”

6. Start browsing the application and observe that the traffic will be captured in the burp suite.

2. SSL Pinning Bypass Via Replacing Hard-Coded Sha 256 Hash

So, we can simply replace the hard coded certificate hash value in the application with our burp suite certificate hash and reinstall the application.

Let’s see how to replace the hard coded certificate’s hash value

  1. Decompile the Application via the following command.

apktool d test.apk

look for the hardcoded hash, it might be at a different location for each app

2. Generate your burp suite certificate hash via the following command

openssl x509 -inform DER -in cacert.cer -out cacert.crt

openssl x509 -in cacert.crt -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

3. Replace our hash value with application hash via any editor.

4. Recompile the application and signed the application and install

apktool b test -0 test.apk

java -jar uber-apk-signer-1.2.1.jar — apk test.apk

Install the application

5. Start browsing the application and observe that the traffic will be captured in the burp suite.

3. SSL Pinning Bypass via Android Manifest modification

I was testing one of the android application and that application has SSL pinning, I have tried with n no of ways but nothing works, then I start analyzing the android manifest file and tried to remove this part “ android:networkSecurityConfig=”@xml/network_security_config” “ and reinstall the application and SSL pinning got bypassed.

Steps To Bypass SSL pinning via android Manifest modification

  1. Decompile the Application via the following command.

apktool d test.apk

2. Go to the Android Manifest file and remove highlighted part completely

3. Rebuild the application via the following command.

apktool b test -o test.apk

4. Sign the application with uber apk signer via the following command.

java -jar uber-apk-signer-1.2.1.jar — apk test.apk

5. Install the application

6. Start browsing the application and observe that the traffic will be captured in the burp suite.

4. SSL Pinning Bypass via Reflutter

Before starting, first Identify whether the application is built in Flutter or Xamarin

  1. Decompile the Android file:

apktool -d test.apk

2. Go To the “Assets” directory or use the grep command and search for flutter

cd test/assets

Steps to capture traffic via reflutter

  1. Install the reflutter from here (https://github.com/Impact-I/reFlutter)
  2. Run the below command

reflutter test.apk

3. Select the intercept option and enter the IP address of your system

4. Sign the APK using uber apk signer or any signer.

java -jar uber-apk-signer-1.2.1.jar — apk release.RE.apk

5. Turn on the invisible proxy option in the burp suite

Open burp suite => proxy => Options => edit => Request handling => turn on support invisible peroxy

6. Set the port to 8083 in burp

7. Install the application, Do not set a proxy.

8. Start browsing the application and observe that the traffic will be captured in the burp suite.

5. Bypassing SSL Pinning via MITM

  1. Install mitmproxy via the following command in MacBook

brew install mitmproxy

2. Download the MITM certificate in the android phone

3. Connect the device and Macbook via USB and Enter the below command or set the proxy in android device

mitmproxy

4. Enter the below command in the android device browser

Mitm.it (Download the Android certificate)

5. Install the MITM certificate on the android phone

In android phone navigate to Setting => Install from device storage=> CA Certificate => install

6. Enter the below command to start the mitmproxy in the Browser.

mitmweb (mitm get open in the browser automatically)

7. Setup MITMProxy for forwarding traffic from the MITM to the burp suite.

8. Enter the below command

mitmweb

9. Go to the option and click on “Edit Options” and click on “set this configuration

10. Search for mode and add the following line there

upstream:http://127.0.0.1:8888

11. Search for ssl_insecure and enable it

12. Set proxy in burp suite.

Set the IP address and port no in the burp suite which you have set for the upstream in mode option.

13. Start browsing the application from android phone and observe that the traffic will be captured in the burp suite.

6. SSL Pinning Bypass via Replacing Hard-Coded Certificate:

So, we’ll replace the hard coded certificate in the android application with our burp suite certificate and reinstall the app, and we’ll be able to bypass the pinning.

Let’s see how to replace the hard coded certificate

  1. Unzip the APK file with the following command.

apktool d test.apk

2. Go to the binary

cd /test

3. Search for hardcoded certificate via following command

find . | grep .cer

4. Replace All the hardcoded certificates with your burp suite certificate

cp ~/Path_of_Your_burp_certificate ./Full_Path_Of_Hardcoded_Certificate

5. Recompile the application and signed the application and install

apktool b test -0 test.apk

java -jar uber-apk-signer-1.2.1.jar — apk test.apk

Install the application

6. Start browsing the application and observe that the traffic will be captured in the burp suite.

7. Hotspot method (Flutter & Xamarin Application)

Before starting, first Identify the application is built in Flutter or Xamarin

  1. Decompile the apk and search for flutter

    Requirements:

    • One mobile device(Android/iOS) to share the internet via Bluetooth tethering.
    • android device
    • MacBook

    Steps to capture traffic via Hotspot Method

    1. Share the internet connection via Bluetooth tethering

    Turn on mobile data = > turn on mobile Bluetooth => connect to the MacBook => turn on Bluetooth tethering from setting in mobile device

    (Try to browse some data in MacBook to confirm that Bluetooth tethering is done properly)

    2. Share internet connection from MacBook to android phone

    In MacBook navigate to System preferences => sharing => internet sharing => share your connection from => bluetooth PAN => To computer using => wifi

3. In Android navigate to Wifi => connect to the Macbook’s wifi

(Try to browse some data in android phone to confirm that this is done properly)

4. Forward the traffic to the burp suite

Create the Pf.rules file with the following data

rdr pass on bridge100 inet proto tcp from any to any -> 127.0.0.1 port 8080

Run the below two command

sudo pfctl -f pf.rules

sudo sysctl -w net.inet.ip.forwarding=1

5. Turn on the invisible proxy option in the burp suite

Open burp suite => proxy => Options => edit => Request handling => turn on support invisible peroxy

6. Start browsing the application from an android device and observe that the traffic will be captured in the burp suite.

8. SSL Pinning Bypass via Objection:

Push the frida server according your frida version and device architecture on data/local/tmp location via given commandGive the permission via following commandRun the below command to start the frida server

2. Install objection in MacBook

sudo pip3 install objection

3. Enter the below command to connect the application to the objection and explore the application.

objection — g package_name explore

4. Run the below command to bypass SSL pinning

android sslpinning disable

5. Start browsing the application from android phone and observe that the traffic will be captured in the burp suite.

9. SSL Pinning bypass via Frida

frida -U -f package_name -l ssl.js — no-pause

U => To use a connected USB device as a target

F => To indicates the package name

L => To load the script

ssl.js =>

(Download the script from codeshare or you can build your own script according to application)

— no-pause => To force the Frida to “not to pause” app execution after injecting the script.

2. Start browsing the application from an android device and observe that the traffic will be captured in the burp suite.

Conclusion

Author Bio:

One Last Thing…….