blob: a17ecc47ca34cc25e67ed9f2c338c67e118ffc4c (
plain)
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
|
#!/bin/bash
# Why is the download so complicated and uses a custom downloader?
#
# The download link only works with a hash that also seems to depend on
# the user agent. The hash can be derived from the "X-Usrid" HTTP header,
# which is only set in the HTTP response when requesting the undocumented
# URL https://mengelke.de/Projekte/FritzBox-Tools;fb_tools.md5.
#
# For example, the hash for the user agent "_" can be calculated as follows:
# curl -A "_" -IsS "http://mengelke.de/Projekte/FritzBox-Tools;fb_tools.md5"
# | grep -ioP "usrid: \K\S+" | base64 -d | xxd -ps | sed 's/^0*//'
#
# To make matters worse, the returned "X-Usrid" HTTP header changes
# regularly, so a new request must be made for each download to get the
# current value of this header.
#
# The necessary procedure was derived by reverse engineering.
DOWNLOAD_URL="$1"
FILE_NAME="$2"
generateUserAgent()
{
local operatingSystems; operatingSystems=("Windows NT 10.0"
"Macintosh; Intel Mac OS X 10_15_7"
"X11; Ubuntu; Linux x86_64" "Android 10"
"iPhone; CPU iPhone OS 14_3 like Mac OS X")
local os; os="${operatingSystems[$RANDOM % ${#operatingSystems[@]}]}"
local browsers; browsers=("Chrome" "Firefox" "Safari" "Edge")
local browser; browser="${browsers[$RANDOM % ${#browsers[@]}]}"
local major; major=$((RANDOM % 150 + 50))
local minor; minor=$((RANDOM % 200))
local patch; patch=$((RANDOM % 1000))
local version; version="$major.$minor.$patch"
local userAgent
case "$browser" in
"Chrome")
userAgent="Mozilla/5.0 ($os) AppleWebKit/537.36 (KHTML, like Gecko) $browser/$version Safari/537.36"
;;
"Firefox")
userAgent="Mozilla/5.0 ($os; rv:$version) Gecko/$version Firefox/$version"
;;
"Safari")
userAgent="Mozilla/5.0 ($os) AppleWebKit/537.36 (KHTML, like Gecko) Version/$version Safari/537.36"
;;
"Edge")
userAgent="Mozilla/5.0 ($os) AppleWebKit/537.36 (KHTML, like Gecko) Edge/$version Safari/537.36"
;;
esac
echo "$userAgent"
}
userAgent=$(generateUserAgent)
userID="$(curl -A "$userAgent" -IsS "${DOWNLOAD_URL%.txz}.md5" | grep -ioP "usrid: \K\S+")"
hash=$(base64 -d <<< "$userID" | xxd -ps)
shopt -s extglob
curl -A "$userAgent" -o "$FILE_NAME" "$DOWNLOAD_URL?${hash##+(0)}"
|