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 = , =
MB
id read 0x100000ff
flash size , sector count =
Flash: 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: ::7f::0b:ad
eth0 up
No valid address in Flash. Using fixed address
: cfg1 0xf cfg2 0x7214
eth1: ::7f::0b:ad
ATHRS26: resetting s26
ATHRS26: s26 reset done
eth1 up
eth0, eth1
Autobooting in 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 matteo@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/

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

  1. TPLink 备份文件bin文件解析

    TPLink 路由器备份文件bin文件 测试路由器 WR885,备份文件加密方式DES,密钥:478DA50BF9E3D2CF linux端: openssl enc -d -des-ecb -nop ...

  2. paper 37 : WINCE的BIB文件解析

    WINCE的BIB文件解析 BIB的全称为Binary Image Builder,在Wince编译过程中的最后MakeImage阶段会用到BIB文件,BIB文件的作用是指示构建系统如何构建二进制映像 ...

  3. bin文件和elf文件

    ELF文件格式是一个开放标准,各种UNIX系统的可执行文件都采用ELF格式,它有三种不同的类型: 可重定位的目标文件(Relocatable,或者Object File) 可执行文件(Executab ...

  4. Module、__init__.py 文件解析

    一.什么是Module? 一个python Module就是一个模块,本质就是一个.py文件,其中包含了python对象的定义和python语句. 在模块内部,模块名存储在全局变量__name__中, ...

  5. S03_CH12_基于UDP的QSPI Flash bin文件网络烧写

    S03_CH12_基于UDP的QSPI Flash bin文件网络烧写 12.1概述 为了满足不同的需求,本例程在"基于TCP的QSPI Flash bin文件网络烧写"上进行修改 ...

  6. S03_CH11_基于TCP的QSPI Flash bin文件网络烧写

    S03_CH11_基于TCP的QSPI Flash bin文件网络烧写 11.1概述 针对ZYNQ中使用QSPI BOOT的应用,将BOOT.bin文件烧写至QSPI Flash基本都是通过USB C ...

  7. Json文件解析(下)

    Json文件解析(下) 代码地址:https://github.com/nlohmann/json   从STL容器转换 任何序列容器(std::array,std::vector,std::dequ ...

  8. Linux下关于用户账户的几个文件解析

    Linux下关于用户账户的几个文件解析 Linux是一个多用户系统,但是对于一个多用户共存的系统中,当然不能够出现用户相互越权等一系列的安全问题,所以如何正确的管理账户成为了Linux系统中至关重要的 ...

  9. CocosStudio文件解析工具CsdAnalysis

    起因 因为工作需要,所以需要使用CocosStudio来制作界面动画什么的.做完了发现需要找里边对象的时候会有很长一串代码,感觉不是很爽.之前写OC代码的时候可以吧程序中的对象指针跟编辑器中的对象相对 ...

随机推荐

  1. 增强Web可用性,你需要避免的七大设计错误

    Web设计给了你展示自我创新才能的平台,同时也要求你特别关注其中的诸多琐碎细节.优秀的Web设计师需要从设计前辈那里获得设计灵感,寻求他们给的建议,并反复推敲,以及付出诸多努力.职业博客作者Rajni ...

  2. VBA提高速度的技巧

    此贴原转自EH论坛,我自己有所修改 [编者按]速度是程序设计永恒的热门话题,虽然速度技巧在各种语言之间可以相互借鉴,但差别有时也会很大,比如VC中由于字符串的存储方式决定了判断空串使用len函数更快, ...

  3. 词法分析器--DFA(c++实现)

    语言名为TINY 实例程序: begin var x,y:interger; x:=; read(x); then x:=x-y; x:=x+y; write(x); end TINY语言扫描程序的D ...

  4. Qt之事件系统

    简述 在Qt中,事件就是对象,派生自QEvent抽象类,用来表示在应用程序中发生的事件,或是应用程序需要处理的外部活动产生的事件. Events可以被任何QObject派生的子类实例对象接收和处理,但 ...

  5. (20)odoo中的action

    ---------更新时间18:06 2016-09-18 星期日15:05 2016-03-14 星期一18:07 2016-02-19 星期五---------* 窗口动作   <?xml ...

  6. hdu-----(1179)Ollivanders: Makers of Fine Wands since 382 BC.(二分匹配)

    Ollivanders: Makers of Fine Wands since 382 BC. Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  7. java设计之简单的JAVA计算器

    做这个东西主要是为了练习一下以前学习过的java Swing,所以那些复杂的算法就没有加载到里面去........ 先展示一下效果....,额,当然不是这个样子....   ---> 代码: p ...

  8. jQuery+zTree加载树形结构菜单

    jQuery+zTree加载树形结构菜单 由于项目中需要设计树形菜单功能,经过一番捣腾之后,终于给弄出来了,所以便记下来,也算是学习zTree的一个总结吧. zTree的介绍: 1.zTree 是利用 ...

  9. 10 vi简介(重点)

    1.为什么学习vi? vi很多系统都预装,如果我们的系统没有图像界面,可以使用vi vi是轻量级且执行快速的编辑器 2.vi的几种模式 命令模式.插入模式.底行模式 1) 命令行模式(command ...

  10. ios基础篇(一)——UIView控件基本属性与常见用法

    1.frame 控件的位置和尺寸(以父控件的左上角为坐标原点(0,0)) 2.center 控件的中点(以父控件的左上角为坐标原点) 3.bounds 控件的位置和尺寸(以自己的左上角为坐标原点(0, ...