TPLink 备份文件bin文件解析[续]

Most routers allow to save and restore configuration from files. This is cool because you can edit the configuration file and upload to the router again enabling some "hidden" configuration options.

For example on my D-Link DSL-2640B I managed to get higher download speed disabling DSL QoS (it was broken) by setting X_BROADCOM_COM_ATMEnbQos to FALSE!

So, I get a TP-Link wireless access point and, sadly, I found that they encrypted the configuration file, so I decided to reverse engineer it.

First of all I needed a dump of the filesystem to get the binaries, so I soldered a serial port on the router to get a serial console.

The bootloader didn‘t allow to interrupt the boot process but fortunately I knew that you can get a prompt by typing the secret word tpltpltpl

AP93 (ar7240) U-boot
DRAM:
sri
#### TAP VALUE 1 = 9, 2 = 9
32 MB
id read 0x100000ff
flash size 4194304, sector count = 64
Flash:  4 MB
Using default environment

In:    serial
Out:   serial
Err:   serial
Net:   ag7240_enet_initialize...
No valid address in Flash. Using fixed address
: cfg1 0xf cfg2 0x7014
eth0: 00:03:7f:09:0b:ad
eth0 up
No valid address in Flash. Using fixed address
: cfg1 0xf cfg2 0x7214
eth1: 00:03:7f:09:0b:ad
ATHRS26: resetting s26
ATHRS26: s26 reset done
eth1 up
eth0, eth1
Autobooting in 1 seconds
ar7240>

I‘ve compiled an OpenWrt (you know OpenWrt, right??) firmware with initramfs, and I loaded it from RAM without flashing the firmware:

ar7240> tftp 0x81000000 openwrt-ar71xx-generic-tl-wr841n-v8-initramfs-uImage.bin
ar7240> bootm

After that making the dump was easy, just "dd" the mtdblock device with the firmware and copy to the computer via scp.

# dd if=/dev/block/mtd2 of=/tmp/rootfs
# scp /tmp/rootfs [email protected]192.168.1.2:

I needed to compile an old version of squashfs tools to extract the files, and finally I extracted the whole filesystem.

$ unsquashfs rootfs

I looked at the web page which handled the configuration load/save and I noticed that there were many references to some sort of embedded functions which most likely are handled by the webserver itself. The webserver is a single blob which handled many system utilities, indeed there were many executables symlinked to the httpd binary. This is a common practice in embedded firmwares, like OpenWrt‘s Busybox and Android‘s toolbox

I started IDA to look at this binary, clearly httpConfUpload was the function to start hacking from.

Due to a reference to des_min_do and some string starting with DES_ I suspected that DES was used as cypher.

des_min_do was a galore of bitwise operators and nasty loops, clearly it was an inlined cryptographic function, and before calling it a pointer to a fixed null terminated string was pushed to the stack. It could be some salt or key passed to the encryption function so I‘ll note this string which was 478DA50BF9E3D2CF.

I tried to decrypt it with mdecrypt using that string as key but without success:

$ mdecrypt -b -a des -f key <config.bin

I looked again at the binary and I searching for the _des string I found md5_des which suggested me to use the md5 hash function:

$ mdecrypt -b -a des -f key -o mcrypt-md5 <config.bin

again with no luck, so I tried all the block modes available until I found the correct one:

$ mdecrypt -b -a des -m ecb -f key -o mcrypt-md5 <config.bin
????????????????lan_ip 192.168.1.254
lan_msk 255.255.255.0
lan_gateway 0.0.0.0

The file is decrypted! Note that the trailing 16 bytes are the md5 sum of the files without trailing zeroes:

the same can be done with openssl:

$ openssl enc -d -des-ecb -nopad -K 478DA50BF9E3D2CF -in config.bin

Have fun!

原文:http://teknoraver.net/software/hacks/tplink/

时间: 2024-10-20 18:45:18

TPLink 备份文件bin文件解析[续]的相关文章

TPLink 备份文件bin文件解析

TPLink 路由器备份文件bin文件 测试路由器 WR885,备份文件加密方式DES,密钥:478DA50BF9E3D2CF linux端: openssl enc -d -des-ecb -nopad -K 478DA50BF9E3D2CF -in config.bin python: python默认没有安装crypto需要自行安装,安装请点我 from Crypto.Cipher import DES from hashlib import md5 key = '\x47\x8D\xA5

npm run 命令解析与node_modules .bin下的文件解析

npm run 命令解析 在vue和react项目中,我们常常用到npm run dev命令来起本地服务,那么npm run dev到底做了什么? package.json文件中的字段script的每一个属性都是一个自定义的脚本命令,npm run 其实执行了package.json中的script脚本 下面的例子,我们以vue-cli3脚手架搭建的项目为例说明,所以当我们输入命令npm run serve命令,底层相当执行vue-cli-service serve --port 8055命令

基于Android2.3.5系统:Android.mk文件解析

*************************************************************************************************************************** 作者:EasyWave                                                                                                               时间:2

paper 37 : WINCE的BIB文件解析

WINCE的BIB文件解析 BIB的全称为Binary Image Builder,在Wince编译过程中的最后MakeImage阶段会用到BIB文件,BIB文件的作用是指示构建系统如何构建二进制映像.所有的BIB文件会被合并成CE.bib文件,然后打包工具Romimage.exe会根据BIB文件中的描述来决定哪些文件最终被包含到WINCE image中,BIB文件还决定了WINCE设备内存的分配,比如定义了WINCE image占用哪块内存,显存(Framebuffer)占用哪块内存等. BI

bin文件和elf文件

ELF文件格式是一个开放标准,各种UNIX系统的可执行文件都采用ELF格式,它有三种不同的类型: 可重定位的目标文件(Relocatable,或者Object File) 可执行文件(Executable) 共享库(Shared Object,或者Shared Library) ELF格式提供了两种不同的视角,链接器把ELF文件看成是Section的集合,而加载器把ELF文件看成是Segment的集合. 有一篇文章介绍elf文件的格式以及加载过程介绍的很详细,可以看一下,地址:http://ww

Intel HEX文件解析

近期有一个需求就是为Arduino开发板做一个基于蓝牙的无线烧录程序.眼下的Arduino程序都是通过USB线连接到电脑的主机上,实际的传输过程是基于USB协议的,这个过程还是比較麻烦的.由于每次的编译完以后都须要通过一个USB线来完毕传输烧录的工作,这个还是非常麻烦的. 原理解读 在Arduino中.利用USB来完毕传输烧录大概是这么一个过程. 每一个Arduino源程序.即sketch文件,经过一系列的编译处理以后.终于会形成一个Intel HEX格式的文件.这个HEX文件事实上就一个被封装

AndroidNative层文件解析漏洞挖掘指南

| 导语 本文以手Q的一次文件解析类漏洞挖掘为例,叙述了Android Native层文件解析类型漏洞挖掘的过程 手Q这个应用从功能来说十分的庞大,如果使用类似MFFA的框架去挖掘文件解析类漏洞,效率低,而且文件入口在哪儿.如何利用脚本进行自动化都是非常大的问题.本文在一次手Q的文件解析类漏洞挖掘的过程中,提出了一种可能的解决问题的方案,妄称指南不吝赐教. 目录: 1.问题分析 2.流程图 3.so筛选 4.测试程序编写 5.test case生成 6.测试得出crash 7.未来的工作 0x0

用DAEMON TOOLS打开rational ross 的bin文件并安装过程梳理

最近要开始准备毕业设计了,学习熟悉了一些UML用例图.类图之类的,开始准备用自家PC电脑画图的时候发现Rational Ross没安装. 本以为简单,却碰上bin文件.琢磨好久,终于把Ross安上了.下面讲讲期间遇到的问题及解决方法. 注:Rational Ross 以下简称Ross 1.下载Ross 网上一堆Ross安装包,有2003版本和2007版本两种,听说win7不兼容2003版本(不知道是真是假),总之我下了个2007版的Ross 打开链接:http://pan.baidu.com/s

Atitit。Tree文件解析器的原理流程与设计实现&#160;&#160;java&#160;&#160;c#&#160;php&#160;js

Atitit.Tree文件解析器的原理流程与设计实现  java  c# php js 1. 解析原理与流程1 1.1. 判断目录  ,表示服  dirFlagChar = "└├─";1 1.2. 剑豪制表符出现的位置与文件夹级别对应表1 1.3. 主要判读流程2 2. Tree结果2 3. Code----3 4. 结果5 1. 解析原理与流程 1.1. 判断目录  ,表示服  dirFlagChar = "└├─"; 其中-类似于剑豪的制表符是表示目录的..够