Ahoj, existuje najaka moznost, jak rozbalit a pote zase zabalit firmware s linuxem?
Jde mi o firmware pro Ubiquity zarizeni, ktery je dostupny na http://dl.ubnt.com/firmwares/XW-fw/v5.6.5/XW.v5.6.5.29033.160515.2108.bin
O co mi jde? Potrebuji firmware rozbalit, upravit a znova zabalit.
Kdysi bylo od UBNT SDK, ale to uz je stare.
Squashfs to neni:
# unsquashfs -i XW.v5.6.5.29033.160515.2108.bin
Can't find a SQUASHFS superblock on XW.v5.6.5.29033.160515.2108.bin
nekde na foru psali, ze jde o UBI.
Podle nejakeho fora jsem zkusil firmware-mod-kit (https://code.google.com/archive/p/firmware-mod-kit/wikis/Documentation.wiki), take to nejde rozbalit:
# unsquashfs -i XW.v5.6.5.29033.160515.2108.bin
Can't find a SQUASHFS superblock on XW.v5.6.5.29033.160515.2108.bin
root@martin:~/ubnt/fmk# ./extract-firmware.sh XW.v5.6.5.29033.160515.2108.bin
...
Scan Time: 2016-05-18 11:51:57
Signatures: 193
Target File: /home/martin/ubnt/fmk/XW.v5.6.5.29033.160515.2108.bin
MD5 Checksum: f5f41db6f5738195ddbb17291a43bce2
DECIMAL HEX DESCRIPTION
-------------------------------------------------------------------------------------------------------
Extracting 0 bytes of header image at offset 0
ERROR: No supported file system found! Aborting...
Pokud se podivam pres strings, na zacatku vidim u-boot:
# strings XW.v5.6.5.29033.160515.2108.bin | less
UBNTXW.ar934x.v5.6.5.29033.160515.2108
PARTu-boot
...
flashsize
flashoffset
ethaddr =
%c%02X
ip_addr =
baudrate = %d bps
bdinfo
bdinfo - print Board Info structure
Usage:
## Board info at 0x%08lX ...
go - start application at address 'addr'
addr [arg ...]
- start application at address 'addr'
passing 'arg' as arguments
reset
reset - Perform RESET of the CPU
Error: Bad gzipped data
Error: gunzip out of data in header
Error: inflateInit2() returned %d
Error: inflate() returned %d
Image Name: %.*s
...
could not get current partition info
defaults:
mtdids : %s
mtdparts: %s
mtdparts=ath-nor0:256k(u-boot),64k(u-boot-env),1024k(kernel),6528k(rootfs),256k(cfg),64k(EEPROM)
no such device %s defined in mtdids variable
too long partition description
...
*** Warning: no boot file name; using '%s'
TFTP from server
; our IP address is
; sending through gateway
Filename '%s'.
Size is 0x%x Bytes =
Load address: 0x%lx
Loading: *
Retry count exceeded; starting again
%lu MB reveived
TFTP error: First block is not block 1 (%ld)
Starting again
...
Ve vyse uvedenem vypisu jsem nasel:
mtdparts=ath-nor0:256k(u-boot),64k(u-boot-env),1024k(kernel),6528k(rootfs),256k(cfg),64k(EEPROM)
tak jsem zkusil dd na rootfs:
dd if=XW.v5.6.5.29033.160515.2108.bin count=6684672 skip=1 of=rootfs
ale vubec jsem si nepomohl.
Da se nejak najit oddily ve firmawru a pripojit je?
Myslim jako kdyz si pomoci dd udelam img celeho /dev/sda a pak pripojim jeho oddily pomoci kpartx, nebo je najdu pomoci testdisk.
Ak máš k dispozícii nejaké staršie SDK vytiahni si z nich fwsplit a ubnt-mkfwimage ,
ale budeš musieť upravovať trocha ich zdroják s novšími fw si neporadia.
.bin súbor má 4 časti ubot, kenel , rootfs a scripts
zaujíma ta rootfs na neho budeš potrebovať squash fs tools .
5.6.5 som ešte upravovať neskúšal , ale na starších verziách to funguje.
Mozna tady? https://gist.github.com/WanghongLin/7ed3bce72f628b6b9d4c
Citace od: Thomas kdy 18. 05. 2016, 18:32:43
Ak máš k dispozícii nejaké staršie SDK vytiahni si z nich fwsplit a ubnt-mkfwimage ,
ale budeš musieť upravovať trocha ich zdroják s novšími fw si neporadia.
.bin súbor má 4 časti ubot, kenel , rootfs a scripts
zaujíma ta rootfs na neho budeš potrebovať squash fs tools .
5.6.5 som ešte upravovať neskúšal , ale na starších verziách to funguje.
ubnt-mkfwimage z SDK.UBNT.v5.3.3 opravdu na nove verze nefunguje.
http://www.ubnt.com/downloads/XN-fw-internal/insecure/v5.3.3/SDK.UBNT.v5.3.3.tar.bz2
Nasel jsem jeste mkfwimage2.c (https://dev.openwrt.org/browser/trunk/tools/firmware-utils/src/mkfwimage2.c) z openwrt naposledy upravovany pred 5 mesici. Dokonce tam je nekdo asi z czfree:
* Copyright (C) 2007 Ubiquiti Networks, Inc.
* Copyright (C) 2008 Lukas Kuna <ValXdater@seznam.cz>
* Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>Dokazal by to nekdo upravit? Ja to zkousel a bez uspechu :-(
Citace od: JardaP . kdy 18. 05. 2016, 19:13:52
Mozna tady? https://gist.github.com/WanghongLin/7ed3bce72f628b6b9d4c
To mi vzdy pada na (zkousim na x86, ale to asi nevadi):
# ubiattach /dev/ubi_ctrl -m 0 -O 4096
ubiattach: error!: cannot attach mtd0
error 22 (Invalid argument)
Navic jak zjistim ty paramertry pro nandsim? :
modprobe nandsim first_id_byte=0xec second_id_byte=0xd5 third_id_byte=0x51 fourth_id_byte=0xa6 Z toho http://www.linux-mtd.infradead.org/faq/nand.html#L_nand_nandsim mi to neni jasne.
Zrovna jsem cetl nadherny navod na FW analyzu IoT zarizeni apod.:
http://resources.infosecinstitute.com/firmware-analysis-for-iot-devices/
Ve zkratce pomoci 'binwalk' si najdes filesystem (squashfs):
# binwalk XW.v5.6.5.29033.160515.2108.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 Ubiquiti firmware header, header size: 264 bytes, ~CRC32: 0x8EF801B1, version: "XW.ar934x.v5.6.5.29033.160515.2108"
268 0x10C Ubiquiti partition header, header size: 56 bytes, name: "u-boot", base address: 0x9F000000, data size: 228524 bytes
151956 0x25194 U-Boot version string, "U-Boot 1.1.4-s958 (Jun 10 2015 - 10:56:20)"
228856 0x37DF8 Ubiquiti partition header, header size: 56 bytes, name: "kernel", base address: 0x9F050000, data size: 955903 bytes
228912 0x37E30 uImage header, header size: 64 bytes, header CRC: 0x6BBB011A, created: Sun May 15 20:09:39 2016, image size: 955839 bytes, Data Address: 0x80002000, Entry Point: 0x80002000, data CRC: 0x4958DD23, OS: Linux, CPU: MIPS, image type: OS Kernel Image, compression type: lzma, image name: "MIPS Ubiquiti Linux-2.6.32.68"
228976 0x37E70 LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: 2799616 bytes
1184823 0x121437 Ubiquiti partition header, header size: 56 bytes, name: "rootfs", base address: 0x9F150000, data size: 6029312 bytes
1184879 0x12146F Squashfs filesystem, little endian, version 4.0, compression:lzma, size: 5893816 bytes, 1190 inodes, blocksize: 131072 bytes, created: Sun May 15 20:09:41 2016
7214255 0x6E14AF gzip compressed data, from Unix, last modified: Sun May 15 20:08:24 2016
7241849 0x6E8079 Ubiquiti end header, header size: 12 bytes, cumulative ~CRC32: 0x6E29FA94
Vykopirujes si dany filesystem do souboru:
# dd if=XW.v5.6.5.29033.160515.2108.bin of=ubnt.squashfs bs=1 skip=1184879 count=5893816
A pak uz ho jen staci extrahovat (jako root kvuli zachovani opravneni a blokovych souboru):
# unsquashfs ubnt.squashfs
Pokud by ti nefungoval systemovy 'unsquashfs', pak pouzi 'sasquatch':
https://github.com/devttys0/sasquatch
Dokupy to das zase obracenym postupem. Vysvetlovat presne jak to mas udelat by bylo delsi nez to udelat, tak zkratka pripojis to co bylo pred squashfs a to co bylo po squashfs. Problem muze byt, ze se ti to nepodari zpet dostat do stejneho formatu, nebo ze se nektere casti v tom FW posunou a muzes si tim bricknout cele UBNT.
UBNT nepouzivam, takze jestli neznas postup na unbrick, tak bych se do toho nepoustel!
Tady jsou skripty, které jsem používal na hackování firmwaru 5.5.10, nevím, jestli budou použitelné i pro novější verze:
https://8an.praha12.net/wifi/ubnt/fwtools.tar.xz (https://8an.praha12.net/wifi/ubnt/fwtools.tar.xz)
Určitě to nejde použít u firmwaru 7.x pro AC hardware, tam zavedli ověřování podpisů.