Created
May 16, 2016 18:02
-
-
Save NikitaKarnauhov/5d9129f13e7b0e257cfbe93215751c7a to your computer and use it in GitHub Desktop.
Shell script to decode and encode TP-LINK router config files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# tlrecode.sh | |
# Decode and encode TP-LINK router config files. | |
# | |
# Creative Commons CC0 License: | |
# http://creativecommons.org/publicdomain/zero/1.0/ | |
# | |
# To the extent possible under law, the person who associated CC0 with this | |
# work has waived all copyright and related or neighboring rights to this work. | |
in="" | |
out="" | |
mode="" | |
# See http://teknoraver.net/software/hacks/tplink/ | |
key="478DA50BF9E3D2CF" | |
tmp_template="tlrecode.XXXXXXXXXX" | |
tmp="" | |
tmp2="" | |
usage() { | |
cat <<EOF | |
tlrecode.sh | |
Decode and encode TP-LINK router config files. | |
Usage: tlrecode.sh (-e|-d) [-i] INPUT [-o] OUTPUT | |
-i, --input Input file name. | |
-o, --output Output file name. | |
-d, --decode Decoding mode (default). | |
-e, --encode Encoding mode. | |
-h, --help Print this message. | |
EOF | |
} | |
error() { | |
echo "Error: $1" >&2 | |
exit 1 | |
} | |
decode() { | |
openssl enc -d -des-ecb -K "${key}" -nopad -in "${in}" -out "${tmp}" && | |
tail -c +17 "${tmp}" > "${tmp2}" && | |
tr -d "\000" < "${tmp2}" > "${out}" | |
} | |
encode() { | |
openssl md5 -binary "${in}" > "${tmp}" && | |
cat "${tmp}" "${in}" > "${tmp2}" && | |
truncate -s %8 "${tmp2}" && | |
openssl enc -e -des-ecb -K "${key}" -nopad -in "${tmp2}" -out "${out}" | |
} | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-i|--input) | |
[ -z "${in}" ] || error "input file '${in}' is already set." | |
[ $# -gt 1 ] || error "option '$1' needs an argument." | |
in="$2" | |
shift 2 | |
;; | |
-o|--output) | |
[ -z "${out}" ] || error "output file '${out}' is already set." | |
[ $# -gt 1 ] || error "option '$1' needs an argument." | |
out="$2" | |
shift 2 | |
;; | |
-d|--decode) | |
[ -z "${mode}" ] || error "mode '${mode}' is already set." | |
mode="decode" | |
shift 1 | |
;; | |
-e|--encode) | |
[ -z "${mode}" ] || error "mode '${mode}' is already set." | |
mode="encode" | |
shift 1 | |
;; | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
*) | |
if [ -z "${in}" ]; then | |
in="$1" | |
elif [ -z "${out}" ]; then | |
out="$1" | |
else | |
error "unexpected argument '$1'" | |
fi | |
shift 1 | |
;; | |
esac | |
done | |
[ -z "${in}" ] && error "no input file given." | |
[ -f "${in}" ] || error "input file '${in}' does not exist." | |
[ -z "${out}" ] && error "no output file given." | |
[ -z "${mode}" ] && mode="decode" | |
tmp="$(mktemp ${tmp_template})" | |
tmp2="$(mktemp ${tmp_template})" | |
if [ "${mode}" == "decode" ]; then | |
decode | |
else | |
encode | |
fi | |
result=$? | |
rm "${tmp}" "${tmp2}" | |
exit ${result} |
With the TD=W8970B you have to add a Null byte to the config, md5 it finally truncate before the encryption. I'll post a fork.
Hello, with the newst version firmware not working.
problem in OSX:
tlrecode.sh: line 53: truncate: command not found
any help?
problem in OSX:
tlrecode.sh: line 53: truncate: command not found
any help?
brew install truncate
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how use it ?
./tlrecode.sh nameFile