sta-c0000 / tpconf_bin_xml

Command line utility to convert TP-Link router backup config files
160 stars 40 forks source link

Support for Archer C20i #21

Closed tosiara closed 2 years ago

tosiara commented 2 years ago

I'm able to decrypt Archer C20i config, but could not import

Error code: 4501
You put a wrong file.

I do not edit anything, just decrypt and encrypt back.

There were similar issues reported and even patch provided. maybe someone knows how to patch for Archer C20i?

tosiara commented 2 years ago

I started troubleshooting this issue, verified libcmm.so is using standard process for encryption: compress -> md5 -> des And then suddenly I figured out that I'm able to repack another one backup. So I have two bin files, both them decrypt fine, but I could only import one of them after re-encryption without any modification. Difference between two files:

$ python tpconf_bin_xml.py conf_bad.bin conf_bad.xml
WARNING: wrong endianness, automatically switching. (see -h)
OK: appears your device uses little-endian.
OK: BIN file decrypted, MD5 hash verified, uncompressing…
Done.

$ python tpconf_bin_xml.py conf_good.bin conf_good.xml
WARNING: wrong endianness, automatically switching. (see -h)
OK: appears your device uses little-endian.
OK: BIN file decrypted, MD5 hash verified, uncompressing…
Done.

$ python tpconf_bin_xml.py -l conf_bad.xml conf_bad_repack.bin
OK: XML file - compressing, hashing and encrypting…
Done.

$ python tpconf_bin_xml.py -l conf_good.xml conf_good_repack.bin
OK: XML file - compressing, hashing and encrypting…
Done.

$ ls -l *bad*
-rw-rw-r-- 1 user user  5528 gruod.  7 18:16 conf_bad.bin
-rw-rw-r-- 1 user user  5504 gruod.  7 18:18 conf_bad_repack.bin
-rw-rw-r-- 1 user user 33265 gruod.  7 18:16 conf_bad.xml
$ ls -l *good*
-rw-rw-r-- 1 user user  5544 gruod.  7 18:16 conf_good.bin
-rw-rw-r-- 1 user user  5520 gruod.  7 18:18 conf_good_repack.bin
-rw-rw-r-- 1 user user 33297 gruod.  7 18:18 conf_good.xml

$ md5sum *bad*
90fa8201ec51cb4ee52fe2be2f0906cc  conf_bad.bin
2354f37dd9b1767b342b733378f0fae5  conf_bad_repack.bin
4c1a3390d8dbf0c311c512e0d7122a90  conf_bad.xml
$ md5sum *good*
dce9b290c82908d0e9cfb6e2f4b7bda8  conf_good.bin
6c25a14e9b55e3ae614e18888cfd0ea3  conf_good_repack.bin
350cddddf29432e05c6eb08446488762  conf_good.xml

$ diff -u -w conf_bad.xml conf_good.xml
--- conf_bad.xml    2021-12-07 18:16:54.967343361 +0200
+++ conf_good.xml   2021-12-07 18:18:12.659355474 +0200
@@ -13,6 +13,7 @@
       <X_TP_isFD val=1 />
       <X_TP_LogCfg>
         <ServerIP val=192.168.0.100 />
+        <LocalSeverity val=7 />
       </X_TP_LogCfg>
     </DeviceInfo>
     <X_TP_EthSwitch>

Imports fine: conf_bad.bin, conf_good.bin, conf_good_repack.bin Import fails: conf_bad_repack.bin

Any ideas what to check? Maybe wrong padding?

tosiara commented 2 years ago

So, I made a serial console and this is the error logged when importing conf_bad_repack.bin:

[ rsl_sys_restoreCfg ] 932:  Config file MD5 check fail
[ rdp_restoreCfg ] 299:  perror:4501
sta-c0000 commented 2 years ago

Without seeing a conf.bin I can't really know...

So I checked the Archer C20i v1 firmware's cen_compressBuff and it's identical to the old Archer C20 v1, so it skiphits. I couldn't find newer C20i versions, unlike C20 which has v4 and v5 which do not skiphits.

Please post your HardwareVersion val= line from the XML file.

tosiara commented 2 years ago

<HardwareVersion val="Archer C20i v1 00000000" />

I'm gonna try to reset the router and reproduce with a clean config and then provide you a sample conf.bin

sta-c0000 commented 2 years ago

Thanks. You could first just try editing the code and change the following:

                if b'Archer C2 v1' in src or b'Archer C20 v1' in src:

to:

                if b'Archer C2 v1' in src or b'Archer C20i v1' in src:
tosiara commented 2 years ago

yes, that worked

tosiara commented 2 years ago

Verified the latest master also worked correctly