-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPP-Decrypt.sh
67 lines (54 loc) · 1.74 KB
/
GPP-Decrypt.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
65
66
67
#!/bin/bash
# Known AES key for GPP encryption
AES_KEY='4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b'
# Function to decrypt GPP password
decrypt() {
local cpass="$1"
local decoded padding
# Add necessary padding
padding=$(printf '%*s' $((4 - ${#cpass} % 4)) "")
padding=${padding// /=}
cpass="${cpass}${padding}"
# Decode from base64 and decrypt
decoded=$(echo "$cpass" | base64 -d | openssl aes-256-cbc -d -A -iv 00000000000000000000000000000000 -K $AES_KEY 2>/dev/null)
echo "$decoded"
}
# Function to process XML file and extract cpassword
process_file() {
local file="$1"
if [[ ! -f "$file" ]]; then
echo "Sorry, file not found!"
exit 1
fi
# Use xmllint to parse XML and extract needed information
local username=$(xmllint --xpath "string(//User/@name)" "$file" 2>/dev/null)
local cpassword=$(xmllint --xpath "string(//Properties/@cpassword)" "$file" 2>/dev/null)
if [[ -n "$username" ]]; then
echo "Username: $username"
else
echo "Username not found!"
fi
if [[ -n "$cpassword" ]]; then
local decrypted=$(decrypt "$cpassword")
echo "Password: $decrypted"
else
echo "Password not found!"
fi
}
# Main function
main() {
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 -f [groups.xml] OR -c [cpassword]"
exit 1
fi
while getopts ":f:c:" opt; do
case $opt in
f) process_file "$OPTARG" ;;
c) echo "Password: $(decrypt "$OPTARG")" ;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
:) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;;
esac
done
}
# Execute main function with all passed arguments
main "$@"