xdarklight / mktplinkfw3

Firmware format analysis for TP-Link firmwares with the version 3 header (0x03000000)
GNU General Public License v2.0
47 stars 12 forks source link

Cannot extracts the signature input from official TP-Link images with your shell script #5

Open bamstwn opened 6 years ago

bamstwn commented 6 years ago

I try to extracts the signature input from official TP-Link images with your shell script but it says "unable to load Public Key", what's wrong? I use TD-W8980v1 image when try.

xdarklight commented 6 years ago

can you please share the exact steps you are using to reproduce this (including the version of the TD-W8980 v1 image)?

bamstwn commented 6 years ago
  1. I copied public key to a file named tp-link_pubkey.bin.ms_publickeyblob
    BgIAAACkAABSU0ExAAQAAAEAAQD54+t3X+bMvuKUfm03w6prR+S+BRjefof9XuPFVew1mftBLi4IPmBc8fb5XJXSusmDXHa/SmSaH4dvNWE5xUuvzc9p2sWxczWEvGqAi4rNk82WtKn4JUgJoalOBOwLavO2ilq4MIcBNi4bYJ6s0vU243zlgFW7p29IsA64d3LY6Q==
  2. run this code with terminal ./extract-sign.sh TD-W8980v1.bin
    
    #!/bin/sh
    IMG="${1}"

for i in ${IMG} ; do echo "--- $i ---"

if [ -f "$i" ]; then

get signature as hex string from image file (one hex

# value per line) and reverse all lines
sig=$(xxd -s +208 -l 128 -c 1 -plain "$i" | tac)

# convert hex string to binary and let openssl extract
# the signed content
echo -n $sig | xxd -revert -plain | openssl rsautl \
          -hexdump -verify -pubin \
          -inkey tp-link_pubkey.bin.ms_publickeyblob \
          -keyform MS\ PUBLICKEYBLOB

fi done

3. result

--- TD-W8980v1.bin --- unable to load Public Key

xdarklight commented 6 years ago

the documentation states that the given public key is base64 encoded:

[...] contains the base64 encoded public key of the pair [...]

so please base64-decode the public key and save the decoded (binary) result as tp-link_pubkey.bin.ms_publickeyblob

bamstwn commented 6 years ago

OK, run base64-decode with base64 -d < pub.b64 > tp-link_pubkey.bin.ms_publickeyblob. Decode (binary) results like this:

image

Run this code again ./extract-sign.sh TD-W8980v1.bin Result:

--- TD-W8980v1.bin ---
RSA operation error
3074271432:error:0407006A:rsa routines:RSA_padding_check_PKCS1_type_1:block type is not 01:rsa_pk1.c:100:
3074271432:error:04067072:rsa routines:RSA_EAY_PUBLIC_DECRYPT:padding check failed:rsa_eay.c:721:
leksmax commented 5 years ago

i have same error with tplink 850v2 cannot extract signature