Android Mobile Forensics, Recovery, & Debugging

Mastering ADB Shell: A Step-by-Step Guide to Full Android Forensic Imaging

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction to Android Forensic Imaging with ADB Shell

In the realm of digital forensics, acquiring a full, bit-for-bit image of a mobile device’s storage is paramount. Android devices, with their diverse hardware and software configurations, present unique challenges. While specialized hardware tools exist, the Android Debug Bridge (ADB) shell, a versatile command-line utility, often serves as a powerful, free, and accessible alternative for initial data acquisition, especially when dealing with rooted devices or custom recoveries. This guide will delve into using ADB shell for forensic imaging, focusing on extracting raw partition data.

Understanding Android Storage Architecture

Before diving into commands, it’s crucial to understand how Android devices store data. Modern Android phones typically use eMMC (embedded Multi-Media Controller) or UFS (Universal Flash Storage) chips. These storage devices are partitioned much like a traditional hard drive. Key partitions include:

  • /boot: Contains the kernel and ramdisk necessary to boot the device.
  • /system: The Android operating system itself (framework, libraries, binaries).
  • /vendor: Device-specific hardware abstraction layer (HAL) implementations.
  • /data (userdata): User applications, settings, databases, and user-generated content. This is often the most critical partition for forensics.
  • /cache: Temporary storage for system components.
  • /recovery: An alternative bootable partition for system recovery or updates.

These partitions are mapped to block devices, typically found under /dev/block. You’ll often see them referred to as mmcblk0pX (for eMMC) or sdaX (for UFS) followed by a partition number, or linked by name under /dev/block/platform/*/by-name/.

Prerequisites for ADB Forensic Imaging

To successfully image an Android device using ADB, you’ll need the following:

  • ADB (Android Debug Bridge) Setup: Ensure you have the platform-tools package installed and ADB is configured in your system’s PATH.
  • USB Debugging Enabled: On the target Android device, navigate to Developer Options and enable USB Debugging. You may need to enable Developer Options by tapping the build number seven times in ‘About Phone’.
  • Device Authorization: When connecting the device for the first time with USB Debugging enabled, a prompt will appear on the device asking to authorize the computer’s RSA key. Always select ‘Always allow from this computer’ and tap ‘OK’.
  • Rooted Device (Highly Recommended): For full raw partition imaging, root access is almost always required to read sensitive block devices. Without root, your access will be severely limited, primarily to user-accessible files.
  • Sufficient Host Storage: The destination drive on your forensic workstation must have enough free space to store the entire image, which can range from gigabytes to hundreds of gigabytes.

Method 1: ADB Backup (Limited Scope)

The adb backup command allows you to create a backup of an Android device’s application data and some system data. While useful for general backups, it’s not a full forensic image.

adb backup -all -f <backup_filename>.ab

This command attempts to back up all installed applications and their data. However, many apps explicitly opt out of backups, and it does not capture raw partition data or deleted files. Thus, for true forensic acquisition, this method is inadequate.

Method 2: Raw Partition Imaging with ADB Shell and dd (Root Required)

This is the primary method for obtaining a forensically sound image of specific partitions. It requires root access.

Step 1: Connect and Verify Device

Connect your Android device to your computer via USB. Open a terminal or command prompt and verify ADB recognizes the device:

adb devices

You should see your device listed with a serial number and ‘device’ status.

Step 2: Access ADB Shell with Root Privileges

Enter the ADB shell and request superuser privileges:

adb shellsu

If successful, your prompt will change from $ to #, indicating root access.

Step 3: Identify Partitions

List the block devices and their corresponding partitions. This command helps you find the specific block device (e.g., mmcblk0) and its partitions by name.

ls -l /dev/block/platform/*/by-name/

Look for partitions like userdata, system, boot, etc., and note their symlinked block device paths (e.g., /dev/block/mmcblk0pXX or /dev/block/sdaXX).

For example, you might see output like:

lrwxrwxrwx 1 root root 21 1970-01-01 00:00 cache -> /dev/block/mmcblk0p28lrwxrwxrwx 1 root root 21 1970-01-01 00:00 userdata -> /dev/block/mmcblk0p35

In this example, userdata is /dev/block/mmcblk0p35.

Step 4: Image Partitions Using dd and adb exec-out

The most efficient way to image partitions is by directly streaming the output of dd from the device to your host machine using adb exec-out. This avoids writing large image files to the device’s internal storage, which can be slow and risks overwriting crucial data.

To image the userdata partition (replace mmcblk0p35 with your device’s actual partition):

adb exec-out "su -c 'dd if=/dev/block/mmcblk0p35 bs=4096'" > userdata.img
  • adb exec-out: Executes a command on the device and streams its standard output directly to the host’s standard output.
  • su -c '...': Executes the dd command with superuser privileges.
  • dd if=/dev/block/mmcblk0p35: dd (data duplicator) reads from the input file (if) which is our target partition.
  • bs=4096: Sets the block size to 4KB. A larger block size can speed up transfers.
  • > userdata.img: Redirects the streamed output to a local file named userdata.img on your forensic workstation.

Repeat this command for all relevant partitions you wish to acquire (e.g., system, boot, cache). Always start with the userdata partition as it contains the most volatile and user-specific data.

You can also create a full device image if you identify the root block device (e.g., mmcblk0 or sda).

adb exec-out "su -c 'dd if=/dev/block/mmcblk0 bs=4096'" > full_device.img

Be aware that a full device image can be very large and time-consuming.

Challenges and Forensic Considerations

  • Root Requirement: The biggest hurdle is often the lack of root access. Many modern devices have locked bootloaders, making rooting difficult or impossible without wiping data.
  • Encryption (FDE/FBE): Full Disk Encryption (FDE) or File-Based Encryption (FBE) means that even if you acquire a raw image, the data within the userdata partition will be encrypted. You’ll need the user’s unlock credentials (password, PIN) to decrypt it for analysis.
  • `dm-verity`: This security feature verifies the integrity of the /system partition. Modifying system files on a `dm-verity` enabled device will trigger a verification failure.
  • Chain of Custody: While ADB imaging is powerful, it’s a ‘soft’ acquisition method. For strict forensic integrity, a hardware write-blocker for the Android device itself is ideal, but often impractical. Document every step precisely.
  • Device State: The device should ideally be in a forensically sound state (e.g., airplane mode, minimal network activity) to prevent data alteration during acquisition.

Post-Imaging Steps

Once you have acquired your image files:

  1. Verify Hashes: Calculate the MD5 or SHA256 hash of each acquired image file immediately after acquisition. This ensures data integrity.
  2. md5sum userdata.img
  3. Analysis: Use forensic tools like Autopsy, FTK Imager, or EnCase to analyze the acquired images. These tools can parse file systems, recover deleted files, and extract artifacts.

Conclusion

Mastering ADB shell for forensic imaging provides a crucial capability for digital investigators, especially when specialized hardware is unavailable or impractical. While it demands careful execution and an understanding of Android’s internal workings, the ability to directly access and image raw partitions using commands like dd via adb exec-out offers unparalleled flexibility and depth in data acquisition. Always prioritize best practices, document your process thoroughly, and be mindful of the legal and ethical implications of forensic data handling.

Android Mobile Specs & Compare Directory

Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!

Compare Devices Specs →
Google AdSense Inline Placement - Content Footer banner