/
WhatsAppKeyExtract.sh
executable file
·64 lines (49 loc) · 2.55 KB
/
WhatsAppKeyExtract.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
##########################################################################
## WhatsApp Key/DB Extractor v2.2 #
## This script will extract the WhatsApp Key file and DB on Android 4.0+ #
## You DO NOT need root for this to work, but you DO need Java installed #
## Base Script by: TripCode #
## Thanks to: Nikolay Elenkov for abe.jar and David Fraser #
## Updated By: Abinash Bishoyi (Added support for 4.4.X/L devices) #
## Version: v2.2 (15th Aug 2014) #
##########################################################################
# Using a subshell because the (old?) instructions used `source` as `. ./WhatsAppKeyExtract.sh`.
(
# Exit on error
set -e
# Check that (some) dependencies are available on the path.
[[ -z $(which adb) ]] && { echo "adb is required" 1>&2; exit 1; }
[[ -z $(which python) ]] && { echo "python is required" 1>&2; exit 1; }
# Create a temporary directory based on the script name and a random pattern.
TEMPORARY=$(mktemp -d "$(basename "${BASH_SOURCE}").XXXXXXXX")
# Remove the temporary directory upon script exit (for any reason).
trap 'rm -rf "$TEMPORARY"' EXIT
outputDirectory="$PWD/extracted/"
whatsappFile="whatsapp.ab"
whatsappNamespace="com.whatsapp"
LegacyFile="$PWD/LegacyWhatsApp.apk"
NewFile="$PWD/WhatsApp.apk"
(
[[ -f "WhatsApp.apk" ]] || curl -o WhatsApp.apk http://www.whatsapp.com/android/current/WhatsApp.apk
echo "Installing legacy WhatsApp 2.11.431"
adb install -r -d "$LegacyFile"
# Perform commands in the temporary directory.
cd "$TEMPORARY"
# Get backup file.
[[ -f "$whatsappFile" ]] || adb backup -f "$whatsappFile" -noapk "$whatsappNamespace"
# Uncompress, unpack backup file.
dd if="$whatsappFile" bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar x
# Create an output directory for unencrypted databases.
mkdir -p "$outputDirectory"
# Extract key, unencrypted message and contacts databases.
cp "apps/$whatsappNamespace/f/key" "$outputDirectory/whatsapp.key"
cp "apps/$whatsappNamespace/db/msgstore.db" "$outputDirectory"
cp "apps/$whatsappNamespace/db/wa.db" "$outputDirectory"
# Push the decryption key to the device.
adb push "apps/$whatsappNamespace/f/key" "/sdcard/WhatsApp/Databases/.nomedia"
echo Updating WhatsApp
adb install -r -d "$NewFile"
echo Consider a Paypal donation to abinashbishoyi@gmail.com
)
)