如何绕过固件头中的 CRC 校验和

逆向工程 固件 嵌入式 CRC
2021-06-29 01:02:39

我有这个 Ubiquiti 固件,我成功提取固件并重建它,我修改 Squashfs 文件系统并使用来自固件模块套件的 build-firmware.sh 脚本重建它,但我遇到的问题是 CRC 与原始值不同,那么我怎样才能绕过CRC校验和这个“CRC32多项式表,大端”是什么

原始固件的此输出

Scan Time:     2016-03-16 11:23:35
Target File:   /home/security/Desktop/XW.v5.6.3-beta3.28377.150922.1830_2.bin
MD5 Checksum:  c7227eeeb31a1c5a8fbcbfc7f70587f0
Signatures:    351
DECIMAL       HEXADECIMAL     DESCRIPTION
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0             0x0             Ubiquiti firmware header, header size: 264 bytes, ~CRC32: 0xB49B5747, version: "XW.ar934x.v5.6.3-beta3.28377.150922.1830"
260           0x104           Ubiquiti partition header, header size: 56 bytes, name: "PARTu-boot", base address: 0x00000000, data size: 0 bytes
127444        0x1F1D4         Certificate in DER format (x509 v3), header length: 4, sequence length: 64
151956        0x25194         U-Boot version string, "U-Boot 1.1.4-s958 (Jun 10 2015 - 10:56:20)"
152244        0x252B4         CRC32 polynomial table, big endian
222808        0x36658         CRC32 polynomial table, big endian
225032        0x36F08         Ubiquiti end header, header size: 12 bytes, cumulative ~CRC32: 0x454E442E
228848        0x37DF0         Ubiquiti partition header, header size: 56 bytes, name: "PARTkernel", base address: 0x00000001, data size: -2147475456 bytes
228912        0x37E30         uImage header, header size: 64 bytes, header CRC: 0x4A2F55E8, created: 2015-09-22 15:31:31, image size: 952264 bytes, Data Address: 0x80002000, Entry Point: 0x80002000, data CRC: 0x533245A9, OS: Linux, CPU: MIPS, image type: OS Kernel Image, compression type: lzma, image name: "MIPS Ubiquiti Linux-2.6.32.67"
228976        0x37E70         LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: 2783164 bytes
1181240       0x120638        Ubiquiti partition header, header size: 56 bytes, name: "PARTrootfs", base address: 0x00000002, data size: 0 bytes
1181304       0x120678        Squashfs filesystem, little endian, version 4.0, compression:lzma, size: 5877613 bytes, 1185 inodes, blocksize: 131072 bytes, created: 2015-09-22 15:31:33
7210680       0x6E06B8        gzip compressed data, from Unix, last modified: 2015-09-22 15:30:15

修改固件的输出在这里http://pastebin.com/uWxG59pu
*我也可以制作假 CRC 以使其看起来像原始值

2个回答

您无法绕过它,您必须重新计算所有必需的校验和。

Ubiquiti XW 固件由以下部分组成:

UBNT <version-string> CRC32(header part) <4byte padding>
PART u-boot <content> CRC32(u-boot part) <4byte padding>
PART kernel <content> CRC32(kernel part) <4byte padding>
PART rootfs <content><squashfs md5 checksum> CRC32(rootfs part) <4byte padding>
EXEC script <content> CRC32(script part) <4byte padding>
END. CRC32(all parts above> <4byte padding>

如果更换的rootfs部分的内容,您桅杆重新计算CRC32该部分在重新计算CRCEND.部分

顺便说一句, firmware-mod-kit为 Ubiquiti 创建了非常破碎的图像,在压缩文件系统后忽略所有内容,并且不重新计算最终END.校验和。

如果您修改固件并重新构建它,则应更改 CRC 值。因此,新的 CRC 值可能是正确的。

您不必对 CRC32 多项式表做任何事情,因为这意味着仅binwalk在引导加载程序找到了 CRC32 表。该表用于快速计算 CRC32 值。