Discovery of 'the bug'

While monitoring the network traffic of WhatsApp after installing it on a (virtual) device, it turned out that the first phone number registration steps return interesting information. If you are not familiar with intercepting network traffic on Android, you can follow the Free Android Application Security training, especially the section '3 Android Penetration Testing Basics', since we will not explain all details in this post.

To summarize the bug: it is possible to retrieve details like the phone model by only entering a phone number in the WhatsApp registration flow.

If you stop after the first step, the owner of the phone number will not be notified, so it could be used for silent enumeration. This information (for example: "Samsung Galaxy A32") can be useful already for bad actors who want to target someone and try to 'get in their phone', or use the information in phishing attacks.

Meta did not classify this as a security issue and partly mitigated this already. It used to work on Android and iOS (numbers linked to it) a few months ago, but recently it does not work for iOS devices anymore. We suspect that this might be related to recent spyware attacks targeting iOS, but this is just speculation.

Below are the steps to reproduce this issue.

Prerequisites

To follow along with this post you need:

  • Android device or emulator with root access
  • Any version of WhatsApp installed on the device
  • Frida server installed on the device and the frida client installed on the host machine
  • Burp Suite to intercept network traffic

Analyzing mobile network traffic

One of the first things you will learn if you are exploring Mobile Application Security is how to intercept network traffic, to monitor API usage between the app and backend services, and tamper with those HTTP requests to find possible security issues. As a penetration tester this must sound familiar if you are testing web applications or APIs. The only difference between web / API testing and mobile apps is that there are often additional security measures implemented, like SSL pinning, or even additional encryption of the HTTP requests and responses to make it a little bit more difficult to read the responses or tamper with the requests.

In case of this WhatsApp API the HTTP request body is encrypted and the HTTP response is not encrypted, as shown in the API request below to the host v.whatsapp.net.

Burp Suite showing the WhatsApp registration API request to v.whatsapp.net with an encrypted ENC request body
The plaintext JSON response from v.whatsapp.net exposing user details

Assuming we cannot crack the encryption in the HTTP request body (the value of the ENC property), this already indicates that the bug is related to the information exposed in the response. Let's explain the issue and also go over the steps needed.

Steps to reproduce

1. Start an Android device or emulator with a proxy configured

For example, after creation via Android Studio:

emulator -avd Medium_Phone_API_36 -http-proxy 127.0.0.1:8080
Android emulator started with an HTTP proxy configured

2. Install WhatsApp on the device

We used WhatsApp version 2.25.18.77 from APK Mirror, but the bug is related to a backend API, so probably any version will do.

adb install -r com.whatsapp_[version].apk

3. Configure the device with the Burp Suite certificate to intercept network traffic

In this case we use Burp Suite Community Edition and installed the Burp root certificate on the Android (14+) emulated device. Follow the instructions in the course or this HTTP Toolkit guide for this.

After configuring the certificate on the device, you will still get errors related to the WhatsApp API:

The client failed to negotiate a TLS connection to v.whatsapp.net:443:
Received fatal alert: certificate_unknown

Visible in the event log at the left bottom in Burp Suite:

Burp Suite event log showing the TLS certificate_unknown error for v.whatsapp.net

This is related to SSL pinning: "SSL pinning is a technique that helps to prevent MITM attacks by hardcoding the SSL/TLS certificate's public key into the app or device. This means that when the app or device communicates with the server, it will compare the server's SSL/TLS certificate's public key with the one that is hardcoded into the app or device."

Luckily SSL pinning can be bypassed by modifying the app during runtime (and overriding commonly used Java classes for this) using the tool Frida, which is the next step.

4. Configure Frida to start the app with instrumentation to bypass SSL pinning

To bypass SSL pinning we need Frida. On your host machine you can install the Frida client via python:

pip3 install frida-tools
frida --version

This will install the latest version. Make sure to download the same version of frida-server to push to the Android device, for example frida-server-17.2.4-android-arm64.xz:

Frida releases page on GitHub with frida-server binaries for Android

Extract the binary from the archive and configure it on the device via adb:

adb push frida-server-17.2.4-android-arm64 /data/local/tmp
adb root
adb shell
chmod +x /data/local/tmp/frida-server-17.2.4-android-arm64
./frida-server-17.2.4-android-arm64

Now we can run Frida with the 'frida-multiple-unpinning' script, thanks to akabe1! Run the script from Frida CodeShare via:

frida -U --codeshare akabe1/frida-multiple-unpinning -f com.whatsapp

-f means spawn (start) the app (with package name com.whatsapp) and immediately attach the script.

Frida running the frida-multiple-unpinning codeshare script against com.whatsapp

The error related to the domain v.whatsapp.net should be gone, and requests should be visible in the HTTP history with readable responses:

Burp Suite HTTP history showing WhatsApp API requests with readable JSON responses after the SSL pinning bypass

5. Trigger 'the issue'

On the second screen, after pressing 'OK' and 'Agree and continue', you can link a phone number. Fill in your own phone number for example and click on 'Next':

WhatsApp registration screen asking for a phone number

Click on Next to get the following confirmation:

WhatsApp confirmation dialog asking to verify the entered phone number, with Edit and Yes options

If you press 'Yes' the owner will get a notification with a confirmation code:

WhatsApp verification code notification received on the target phone
This is what you should avoid if you want to be stealthy. Pressing 'Yes' sends the owner a verification code. Pressing 'Edit' instead returns to the previous screen and the user is never notified.

If you click 'Edit' you will go back to the previous screen and the user will not be notified. The interesting thing is that if you check the network traffic, after entering the phone number and before confirming the number, there is already a request:

POST /v2/exist
Host: v.whatsapp.net
Body: ENC=[encrypted string]

Response body: JSON with user details, and if lucky (Android?) details like "wa_old_device_name": "Samsung Galaxy A32" or "OnePlus OnePlus Nord2 5G" or "Google Pixel 8a" etc.

JSON response from the /v2/exist endpoint containing wa_old_device_name with the phone model

The request body is not useful, so easy enumeration via the API is not possible:

The encrypted ENC request body of the /v2/exist call

Interestingly, this used to work in almost all cases (if the phone number is linked to WhatsApp), and this seems to have changed recently.

Earlier wa_old_device_name for an iOS-linked phone number:

Earlier response for an iOS-linked number still exposing wa_old_device_name

Recently:

Recent response for an iOS-linked number no longer exposing the device name
Recent API response without the wa_old_device_name field

Conclusion

Although we did not discover a serious security flaw in WhatsApp, it is still interesting to monitor the network traffic and look for (sensitive) information. If it was easier to enumerate and always returned the same output, it could have been interesting to enumerate all phone numbers (per country) and collect statistics about which phones are most popular, for example.

Want to learn more?

Join our free AppSec courses for Android and iOS and prove your skills by doing the exams to become a Certified Android Penetration Tester (CAPT) or Certified iOS Penetration Tester (CIPT).

Or if you want to dive deeper to cover the whole stack:

  • Android Userland Fuzzing & Exploitation, with a 72-hour hands-on exam to become a Certified Android Exploit Developer
  • Android Kernel Fuzzing & Exploitation, with free hands-on tryout labs