Skip to content

huamanyuan-1/capture_android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

中文版本

Android App Automation Testing and Network Traffic Capture Tool

A Python-based Android app automation testing tool that can automatically perform app operations and capture corresponding network traffic.

Project Overview

This project aims to automate testing of Android applications while simultaneously capturing their network traffic data. By combining uiautomator2, adb, and mitmdump tools, the project can automatically perform app operations (such as opening apps, searching content, etc.) and record the app's network communication data for subsequent analysis.

Key Features

  • Android app automation operations (based on uiautomator2)
  • Network traffic capture (using adb tcpdump)
  • HTTPS traffic decryption (using mitmdump and SSLKEYLOGFILE)
  • Multi-process management and control
  • Supports automation testing for apps like YouTube and Reddit

Project Structure

  • main.py - Main entry file for starting tests for different apps
  • beans/ - App-specific automation operation implementations
    • youtube.py - Automation operations for YouTube app
    • reddit.py - Automation operations for Reddit app
  • utils/ - Utility classes
    • process.py - Process management and traffic capture functionality
    • random_string.py - Random string generation utility

How It Works

  1. Start mitmdump proxy server and set up SSL key log file
  2. Start tcpdump on Android device for traffic capture
  3. Connect to device via uiautomator2 and perform app operations
  4. Terminate all related processes after operations are completed
  5. Generate paired data containing app operations and corresponding network traffic

Traffic Capture Configuration

  • Ensure Developer Options and USB Debugging are enabled on the Android device
  • Create pcap directory on Android device: adb shell mkdir -p /data/local/tmp/pcap/
  • Ensure tcpdump tool is installed on the device and has execution permissions

Process Management Configuration

  • mitmdump in process.py uses upstream proxy mode (--mode upstream:http://127.0.0.1:7897), ensure a proxy service is available on local port 7897
  • SSL key log files will be saved in C:/Users/nstl/Downloads/extract/key/ directory, ensure this path exists and is writable
  • Traffic capture files (.pcap) will be saved in /data/local/tmp/pcap/ directory on the Android device

Usage

  1. Install mitmproxy man-in-the-middle environment and install the man-in-the-middle certificate on the test device. For details, refer to: https://docs.mitmproxy.org/stable/
  2. Install uiautomator2. For details, refer to: https://github.com/openatx/uiautomator2
  3. Write scripts for the apps you need to collect data from, you can refer to beans/youtube.py
  4. Run main.py.

About

采集android应用流量,使用mitmproxy和uiautomator2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages