破解ar9331路由器的boot密码

来源:互联网 发布:淘宝搞笑最牛评论 编辑:程序博客网 时间:2024/06/05 06:24

如何破解基于Atheros AR9931路由器中U-Boot的串口密码

大部分基于Atheros AR9331的路由器,U-Boot都是在Atheros SDK中U-Boot的基础上做些修改,然后用到产品中。我们可以从很多厂商的GPL release代码中找到Atheros SDK中的U-Boot代码。


互联网上已经有很多人在GPL release的代码基础上做一些U-Boot的修改和开发,比如下面这个项目(波兰文,请借助goolge翻译阅读):

http://www.tech-blog.pl/2013/03/29/zmodyfikowany-u-boot-dla-routerow-tp-link-z-atheros-ar9331-z-trybem-aktualizacji-oprogramowania-przez-www-i-konsola-sieciowa-netconsole/


我将利用上面这个项目中的U-Boot代码来分析如何破解AR9331 U-Boot中的串口密码,代码下载地址:

http://www.tech-blog.pl/pliki/u-boot_for_tp-link_AR9331_by_pepe2k.tar.gz

(也可以从我的baidu网盘下载:http://pan.baidu.com/share/link?shareid=268403347&uk=3392498151)


稍做修改后,然后编译这个项目,首先我们要看看最终的U-Boot是如何生成的,只有了解了它的生成过程,才会知道如何破解!

略掉很多细节,直接看关键的部分:


mips-openwrt-linux-uclibc-ld -Bstatic -T /home/build/ar9331/uboot/u-boot_sources_for_tp-link_AR9331_by_pepe2k/u-boot/board/ar7240/ap121/u-boot.lds -Ttext 0x80010000  -G 0 -static -n -nostdlib $UNDEF_SYM cpu/mips/start.o \
            --start-group lib_generic/libgeneric.a common/libcommon.a board/ar7240/ap121/libap121.a cpu/mips/libmips.a cpu/mips/ar7240/libar7240.a drivers/libdrivers.a lib_mips/libmips.a net/libnet.a rtc/librtc.a  --end-group -L /home/build/ar9331/uboot/u-boot_sources_for_tp-link_AR9331_by_pepe2k/toolchain/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3 -lgcc \
            -Map u-boot.map -o u-boot
mips-openwrt-linux-uclibc-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
mips-openwrt-linux-uclibc-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin

        mips-openwrt-linux-uclibc-ld -Bstatic -T /home/build/ar9331/uboot/u-boot_sources_for_tp-link_AR9331_by_pepe2k/u-boot/board/ar7240/ap121/u-boot-bootstrap.lds -Ttext 0x9F000000  -G 0 -static -n -nostdlib $UNDEF_SYM cpu/mips/start_bootstrap.o \
            --start-group lib_bootstrap/libbootstrap.a  board/ar7240/ap121/libap121.a  cpu/mips/libmips.a cpu/mips/ar7240/libar7240.a --end-group -L /home/build/ar9331/uboot/u-boot_sources_for_tp-link_AR9331_by_pepe2k/toolchain/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3 -lgcc \
            -Map bootstrap.map -o bootstrap
mips-openwrt-linux-uclibc-objcopy --gap-fill=0xff -O binary bootstrap bootstrap.bin
/home/build/ar9331/uboot/u-boot_sources_for_tp-link_AR9331_by_pepe2k/host_util/lzma e u-boot.bin u-boot.bin.lzma
./tools/mkimage -A mips -T firmware -C lzma \
        -a 0x80010000 \
        -e 0x80010000 \
        -n 'u-boot image' -d u-boot.bin.lzma u-boot.lzimg

Image Name:   u-boot image
Created:      Thu Jul  4 13:19:14 2013
Image Type:   MIPS Linux Firmware (lzma compressed)
Data Size:    43056 Bytes = 42.05 kB = 0.04 MB
Load Address: 0x80010000
Entry Point:  0x80010000
cat bootstrap.bin > tuboot.bin
cat u-boot.lzimg >> tuboot.bin


重点关注上面红色标注的部分,可以看出,最终的tuboot.bin由bootstrap.bin和u-boot.lzimg通过cat命令组合在一起构成。而u-boot.lzimg是u-boot.bin.lzma通过mkimage加一个header构成,而u-boot.bin.lzma是u-boot.bin通过lzma压缩而成。


如果你直接通过hex编辑工具打开u-boot.bin,U-Boot串口密码是可以直接看见的(为什么可以直接看见?此处略去技术细节的解释,有兴趣的朋友可以配合代码,去了解一些编译,链接的知识,以及objcopy等工具的使用)。


分析到这里,发现其实破解很简单,得到为未压缩的u-boot.bin,用hex编辑工具就可以查看到串口密码,这里我们用TP-LINK官方网站release的firmware文件做小白鼠(firmware的路由器型号是WR703N,也是基于AR9331),来演示整个过程。

小白鼠下载地址:

http://pan.baidu.com/share/link?shareid=24218525&uk=3392498151

(也可以从TP-LINK官方网站下载,为了防止以后死链出现,我在自己的baidu网盘里备份了一份。TP-LINK官方下载地址:http://service.tp-link.com.cn/detail_download_1016.html)


  

解压以后会得到:wr703nv1.bin,按照上面的分析思路,我们首先要获取到tuboot.bin,由于Bootloader一般都是放在整个firmware的最前面,根据一定的经验就可以判断出tuboot.bin的大小,参考下图:

通过dd命令截取tuboot.bin:

dd if=wr703nv1.bin of=tuboot.bin bs=48274 count=1


由于u-boot.lzimg是U-Boot工具mkimage生成的文件,参考u-boot/include/image.h:

=================================================

#define IH_MAGIC        0x27051956      /* Image Magic Number           */
#define IH_NMLEN                32      /* Image Name Length            */

/*
 * all data in network byte order (aka natural aka bigendian)
 */

typedef struct image_header {
        uint32_t        ih_magic;       /* Image Header Magic Number    */
        uint32_t        ih_hcrc;        /* Image Header CRC Checksum    */
        uint32_t        ih_time;        /* Image Creation Timestamp     */
        uint32_t        ih_size;        /* Image Data Size              */
        uint32_t        ih_load;        /* Data  Load  Address          */
        uint32_t        ih_ep;          /* Entry Point Address          */
        uint32_t        ih_dcrc;        /* Image Data CRC Checksum      */
        uint8_t         ih_os;          /* Operating System             */
        uint8_t         ih_arch;        /* CPU architecture             */
        uint8_t         ih_type;        /* Image Type                   */
        uint8_t         ih_comp;        /* Compression Type             */
        uint8_t         ih_name[IH_NMLEN];      /* Image Name           */
} image_header_t;
=================================================  

所以只要查找IH_MAGIC 0x27051956就可以知道u-boot.lzimg在整个tuboot.bin中的起始地址,见下图:

通过dd命令截取获得u-boot.lzimg:


dd if=tuboot.bin of=u-boot.lzimg bs=15440 skip=1

然后根据struct image_header的大小,截取获得u-boot.bin.lzma:

dd if=u-boot.lzimg of=u-boot.bin.lzma bs=64 skip=1


解压缩u-boot.bin.lzma:

lzma -d u-boot.bin.lzma

然后通过hex编辑器查看u-boot.bin:

TP-LINK默认的U-Boot串口密码是“tpl”。玩OpenWrt的人都熟知这个密码,所以我这里直接拿“tpl”做搜索的关键字。在实际破解中你肯定不会知道需要破解的密码,所以你可以根据上图中“tpl”前面的"seconds"做关键字。


本文主要提供一个破解思路,所以很多技术细节没有深入,描述也不是很准确。但你可以尝试着通过本文提供的方法,获取串口密码。有了串口密码,进入U-Boot串口命令行,我们可以通过U-Boot中的命令升级firmware(比如刷OpenWrt)。

0 0
原创粉丝点击