Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexeinazarov/53d1c03333a569c9658104db680955c1 to your computer and use it in GitHub Desktop.
Save alexeinazarov/53d1c03333a569c9658104db680955c1 to your computer and use it in GitHub Desktop.
Environment Installation Guide for Monitoring WhatsApp Activities

Comprehensive Environment Installation Guide for Monitoring WhatsApp Activities

This guide provides a detailed setup process for students to monitor various activities within WhatsApp, including audio, video, contacts, cookies, and other data interactions. The setup involves using dynamic instrumentation tools like Frida, filesystem monitoring tools like inotifywait, and network traffic monitoring tools like mitmproxy and Wireshark.

Prerequisites

  • A Linux host machine
  • Android Studio or Genymotion for Android emulation
  • Rooted Android emulator for advanced monitoring (optional)
  • Basic knowledge of Android development and Linux command-line tools

Tools and Software

  • Frida: For dynamic instrumentation
  • inotifywait: For filesystem monitoring
  • mitmproxy: For intercepting and analyzing HTTPS traffic
  • Wireshark: For capturing and analyzing network traffic
  • adb: Android Debug Bridge for emulator configuration

Part 1: Monitoring Audio, Video, and Contacts Activity

Step 1: Setting Up the Android Emulator

  1. Install Android Studio:

    • Download and install Android Studio from the official website.
    • Create a new Android Virtual Device (AVD) with the desired specifications.
  2. Root the Emulator (Optional for Advanced Monitoring):

    • Rooting the emulator can provide more control and access to system files.
    • Follow a guide such as How to Root Android Emulator for detailed steps.

Step 2: Installing and Configuring Frida

  1. Install Frida on the Linux Host:

    pip install frida-tools
  2. Download the Frida Server:

  3. Push the Frida Server to the Emulator:

    adb push frida-server /data/local/tmp/
    adb shell "chmod 755 /data/local/tmp/frida-server"
    adb shell "/data/local/tmp/frida-server &"
  4. Write Frida Scripts to Monitor Audio, Video, and Contacts:

    Java.perform(function() {
      // Hooking into audio methods
      var MediaRecorder = Java.use('android.media.MediaRecorder');
      MediaRecorder.start.implementation = function() {
        console.log('MediaRecorder started');
        this.start();
      };
    
      // Hooking into video methods
      var Camera = Java.use('android.hardware.Camera');
      Camera.startPreview.implementation = function() {
        console.log('Camera preview started');
        this.startPreview();
      };
    
      // Hooking into contacts access
      var ContentResolver = Java.use('android.content.ContentResolver');
      ContentResolver.query.overload('android.net.Uri', '[Ljava.lang.String;', 'android.os.Bundle', 'android.os.CancellationSignal').implementation = function(uri, projection, queryArgs, cancellationSignal) {
        console.log('Contacts accessed:', uri);
        return this.query(uri, projection, queryArgs, cancellationSignal);
      };
    });
  5. Run the Frida Script:

    frida -U -f com.whatsapp -l your_script.js --no-pause

Step 3: Monitoring Filesystem with inotifywait

  1. Install inotify-tools on Linux:

    sudo apt-get install inotify-tools
  2. Monitor WhatsApp's Data Directory:

    inotifywait -m -r -e access,modify,create,delete /data/data/com.whatsapp/
  3. Script for Real-Time Logging:

    #!/bin/bash
    
    # Directory to monitor
    DIR="/data/data/com.whatsapp/"
    
    # Log file to store inotify events
    LOGFILE="/var/log/whatsapp_data_monitor.log"
    
    # Run inotifywait and log events
    inotifywait -m -r -e access,modify,create,delete $DIR --format '%w%f %e' |
    while read FILE EVENT; do
        echo "$(date) - $EVENT - $FILE" >> "$LOGFILE"
    done

Part 2: Monitoring All Other Activities (Cookies, Data Transfers, etc.)

Step 1: Using Mitmproxy to Monitor Network Traffic

  1. Install mitmproxy on Linux:

    sudo apt-get install mitmproxy
  2. Start mitmproxy:

    mitmproxy -p 8080
  3. Configure the Emulator to Use mitmproxy:

    adb shell settings put global http_proxy <host_ip>:8080
  4. Install the mitmproxy Certificate on the Emulator:

    • Transfer the certificate:
      adb push ~/.mitmproxy/mitmproxy-ca-cert.pem /sdcard/Download/
    • Install the certificate from the emulator's settings.

Step 2: Capturing and Analyzing Traffic with Wireshark

  1. Install Wireshark on Linux:

    sudo apt-get install wireshark
  2. Start Wireshark and Select the Network Interface:

    • Capture traffic on the network interface used by the emulator (e.g., vboxnet0 for VirtualBox).
  3. Set Up Capture Filters:

    tcp.port == 8080
    

Step 3: Using Frida for Additional Monitoring

  1. Write Frida Scripts for Monitoring Cookies and Data Transfers:

    Java.perform(function() {
      // Hooking into cookie methods
      var CookieManager = Java.use('android.webkit.CookieManager');
      CookieManager.getInstance().setCookie.overload('java.lang.String', 'java.lang.String').implementation = function(url, value) {
        console.log('Cookie set - URL:', url, 'Value:', value);
        return this.setCookie(url, value);
      };
    
      // Hooking into database access methods
      var SQLiteDatabase = Java.use('android.database.sqlite.SQLiteDatabase');
      SQLiteDatabase.execSQL.overload('java.lang.String').implementation = function(sql) {
        console.log('SQL executed:', sql);
        return this.execSQL(sql);
      };
    });
  2. Run the Frida Script:

    frida -U -f com.whatsapp -l your_script.js --no-pause

Additional Methods and Options

  1. TrackerControl:

    • Installation: Download TrackerControl from the GitHub page.
    • Functionality: Monitor which tracking domains are contacted by WhatsApp and other apps.
  2. Real-Time Alerts:

    • Webhook Integration: Configure inotifywait or Frida scripts to trigger webhooks that notify a monitoring service when specific events are logged.
    • Monitoring Dashboard: Use tools like Grafana to visualize and set alerts for monitored events.

References

By following this comprehensive guide, students can set up an environment to monitor various activities within WhatsApp, including audio, video, contacts, cookies, and other data interactions. This setup provides hands-on experience with advanced cybersecurity tools and techniques, enhancing their understanding of mobile app data flows and privacy concerns.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment