Files
KeyDive/README.md
T

140 lines
7.8 KiB
Markdown
Raw Permalink Normal View History

2025-06-09 18:12:49 +02:00
# KeyDive: Widevine L3 Key Extractor for Android
2024-03-30 20:03:15 +01:00
2025-06-09 18:12:49 +02:00
KeyDive is a Python tool designed to extract Widevine L3 DRM keys from Android devices seamlessly, supporting multiple Android versions for DRM research, education, and analysis.
2024-03-30 20:03:15 +01:00
2024-07-12 12:12:31 +02:00
> [!IMPORTANT]
2025-06-09 18:12:49 +02:00
> For dynamic key extraction on devices with Android SDK > 33 (OEM API 18+), a minimum `frida-server 16.6.0` is required. Otherwise, pre-extracted functions from Ghidra are necessary.
2024-03-30 20:03:15 +01:00
## Features
2025-06-09 18:12:49 +02:00
- 🚀 Easy installation with [pip](https://pip.pypa.io/)
- 🔄 Automated Widevine L3 key extraction supporting SDK > 21
- 📱 Supports a wide range of Android devices and versions
- 💾 Export extracted keys and device credentials in multiple formats including pywidevine `.wvd`
- 🌐 Offline extraction mode available
- 🖥️ Flexible command-line interface with multiple customization options
- 🛠️ Supports injecting custom Widevine functions extracted from Ghidra XML files
- ❤️ Fully open-source and actively maintained
2024-03-30 20:03:15 +01:00
## Prerequisites
2025-06-09 18:12:49 +02:00
- **ADB (Android Debug Bridge):** Make sure to install [ADB](https://github.com/hyugogirubato/KeyDive/blob/main/docs/PACKAGE.md#adb-android-debug-bridge) and include it in your system's PATH environment variable for easy command-line access.
- **frida-server:** Install `frida-server` on your target Android device. This requires root access on the device. For installation instructions and downloads, visit the [official Frida documentation](https://frida.re/docs/installation/).
- **Python 3.8+**
2024-03-30 20:03:15 +01:00
## Installation
Follow these steps to set up KeyDive:
1. Ensure all prerequisites are met (see above).
2025-01-19 17:54:05 +01:00
2. Install KeyDive directly from PyPI:
2025-06-09 18:12:49 +02:00
````shell
2024-07-06 20:01:47 +02:00
pip install keydive
2025-06-09 18:12:49 +02:00
````
2024-03-30 20:03:15 +01:00
## Usage
2025-01-19 17:54:05 +01:00
1. Run the KeyDive script:
2025-06-09 18:12:49 +02:00
````bash
keydive -kw -a player
````
2025-01-19 17:54:05 +01:00
2. The script will install and launch the [Kaltura](https://github.com/kaltura/kaltura-device-info-android) DRM test app (if not already installed).
3. Follow these steps within the app:
- **Provision Widevine** (if the device isn't provisioned).
- **Refresh** to intercept the keybox or private key.
- **Test DRM Playback** to extract the challenge.
4. KeyDive automatically captures the Widevine keys, saving them as:
- `client_id.bin` (device identification data).
- `private_key.pem` (RSA private key).
2024-04-01 13:10:21 +02:00
2025-06-09 18:12:49 +02:00
This will automatically install and launch the recommended DRM test app (Kaltura), provision Widevine if necessary, and perform the extraction steps.
> [!TIP]
> This sequence ensures that the DRM-protected content is active and ready for key extraction by the time the KeyDive script is initiated, optimizing the extraction process.
2024-03-30 20:03:15 +01:00
### Command-Line Options
2025-06-09 18:12:49 +02:00
````shell
Usage: keydive [-h] [-s <serial>] [-d <delay>] [-v] [-l <dir>] [-V] [-o <dir>] [-w] [-k] [-a <type>] [--no-detect] [--no-disabler] [--no-stop] [--unencrypt] [--symbols <symbols>] [--challenge <challenge>] [--rsa-key <rsa-key>] [--aes-key <aes-key>]
2024-03-30 20:03:15 +01:00
2025-06-09 18:12:49 +02:00
Extract Widevine CDM components from an Android device.
2024-03-30 20:03:15 +01:00
2025-06-09 18:12:49 +02:00
Optional Arguments:
2024-04-01 15:53:18 +02:00
-h, --help show this help message and exit
2024-07-06 20:01:47 +02:00
2025-06-09 18:12:49 +02:00
Global Options:
-s, --serial <serial>
ADB serial number of the target Android device.
-d, --delay <delay> Delay in seconds between process status checks. (default: 1.0)
-v, --verbose Enable detailed logging for debugging.
-l, --log <dir> Directory to save log files.
-V, --version Show tool version and exit.
Cdm Extraction:
-o, --output <dir> Directory to store extracted CDM files. (default: ./device)
-w, --wvd Export data in pywidevine-compatible WVD format.
-k, --keybox Export Widevine keybox if available on the device.
-a, --auto <type> Automatically launch a DRM playback test. ("web" or "player")
Advanced Options:
--no-detect Disable automatic detection of OEM private key function.
--no-disabler Disable liboemcrypto-disabler module (patches memory protection).
--no-stop Do not stop once minimum CDM data is intercepted.
--unencrypt Force the license challenge to keep client ID data unencrypted.
--symbols <symbols> Path to Ghidra-generated XML symbol file for function mapping.
--challenge <challenge>
Protobuf challenge file(s) captured via MITM proxy.
--rsa-key <rsa-key> RSA private key(s) in PEM or DER format for client ID decryption.
--aes-key <aes-key> AES key(s) in hex, base64, or file form for decrypting keybox data.
````
> [!NOTE]
> The advanced options are primarily intended for debugging and development purposes. Regular users do not need to use them.
2024-03-30 20:03:15 +01:00
2024-07-12 12:12:31 +02:00
## Advanced Usage
2024-03-31 15:27:10 +02:00
2024-07-12 12:12:31 +02:00
### Extracting Functions
2024-03-31 15:27:10 +02:00
2025-06-09 18:12:49 +02:00
Custom functions extracted from Widevine libraries with Ghidra can be provided to KeyDive to improve compatibility on some devices. See the [Functions Extraction Guide](https://github.com/hyugogirubato/KeyDive/blob/main/docs/advanced/FUNCTIONS.md).
2024-03-30 20:03:15 +01:00
2024-07-12 12:12:31 +02:00
### Offline Extraction
2025-06-09 18:12:49 +02:00
KeyDive supports offline extraction workflows suitable for restricted environments. See the [Offline Mode Guide](https://github.com/hyugogirubato/KeyDive/blob/main/docs/advanced/OFFLINE.md).
2024-07-12 12:12:31 +02:00
2025-06-09 18:12:49 +02:00
### Using Unencrypted Challenge Data
2024-07-12 12:12:31 +02:00
2025-06-09 18:12:49 +02:00
> [!CAUTION]
> The `--unencrypt` option forces the license challenge to keep client ID data unencrypted. This option can cause repetitive crashes or instability in the Widevine library on certain devices.
2024-07-12 12:19:06 +02:00
2025-06-09 18:12:49 +02:00
When client ID extraction fails, provide an unencrypted challenge via `--challenge`. See the [Challenge Extraction Guide](https://github.com/hyugogirubato/KeyDive/blob/main/docs/advanced/CHALLENGE.md).
2024-03-30 20:03:15 +01:00
2024-07-12 12:12:31 +02:00
### Temporary Disabling L1 for L3 Extraction
2024-03-30 20:03:15 +01:00
2024-07-12 12:19:06 +02:00
> [!WARNING]
2024-07-12 12:12:31 +02:00
> Usage of the module is now deprecated because the deactivation of the library was natively added.
2025-06-09 18:12:49 +02:00
Some manufacturers (e.g., Xiaomi) allow the use of L1 keyboxes even after unlocking the bootloader. In such cases, it's necessary to install a Magisk module called [liboemcrypto-disabler](https://github.com/hyugogirubato/KeyDive/blob/main/docs/PACKAGE.md#liboemcrypto-disabler) to temporarily disable L1, thereby facilitating L3 key extraction.
2024-03-30 20:03:15 +01:00
## Disclaimer
KeyDive is intended for educational and research purposes only. The use of this tool in unauthorized testing of protected content is strictly prohibited. Please ensure you have permission before proceeding with DRM key extraction.
2024-07-12 12:12:31 +02:00
## Contributors
<a href="https://github.com/hyugogirubato"><img src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/65763543?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="hyugogirubato"/></a>
<a href="https://github.com/FoxRefire"><img src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/155989196?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="FoxRefire"/></a>
<a href="https://github.com/azimabid00"><img src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/110490898?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="azimabid00"/></a>
2024-07-15 19:59:49 +02:00
<a href="https://github.com/JohnDoe1964"><img src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/167800584?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="JohnDoe1964"/></a>
2024-07-23 22:14:31 +02:00
<a href="https://github.com/Nineteen93"><img src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/107993263?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Nineteen93"/></a>
2024-07-27 15:44:42 +02:00
<a href="https://github.com/sn-o-w"><img src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/2406819?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="sn-o-w"/></a>
2025-06-09 18:12:49 +02:00
<a href="https://github.com/sn-o-w"><img src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/206893953?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="samu87d8dh2"/></a>
2024-07-15 19:59:49 +02:00
2024-07-12 12:12:31 +02:00
## Licensing
This software is licensed under the terms of [MIT License](https://github.com/hyugogirubato/KeyDive/blob/main/LICENSE).
You can find a copy of the license in the LICENSE file in the root folder.
2025-01-19 18:15:14 +01:00
---
2024-07-12 12:12:31 +02:00
2025-06-09 18:12:49 +02:00
© hyugogirubato 2025