Skip to content

Extract cram filesystem with lzma compression for debug or forensic

License

Notifications You must be signed in to change notification settings

joseigbv/xcramfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xcramfs

Extract cram filesystem with lzma compression for debug or forensic.

CramFS + LZMA, used by many home routers in their firmware.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Tools can be compiled on any Win32 or UNIX/Linux box. You only need a relatively modern C compiler.

Installing

Download a copy of the project from github:

$ git clone https://github.com/joseigbv/xcramfs.git

Edit 'search.c' and set firmware file and signature bytes:

...
#define FNAME "openrg.rta9211w_6_0_18_1_11.img"
const char PAT[] = { 0x45, 0x3d, 0xcd, 0x28 };
...

Compile:

$ gcc -Wall -O2 search.c -o search

Edit 'xcramfs.c' and change configuration (optional):

...
#define FNAME "data.cramfs"
#define BASE "x"
...

Compile:

$ cd LZMA_C && make && cd ..
$ gcc -m32 -Wall -ILZMA_C xcramfs.c LZMA_C/decode.o LZMA_C/LzmaDecode.o -o xcramfs 

Usage

First, you need to find and extract the cramfs with lzma compression:

$ ./search

Searching for CRAMFS filesystem...
* Pattern found in byte 1490944.

Struct Super:
=============

Magic:          0x28cd3d45
Size:           0x00350000
Flags:          0x0000a003
Future:         0x00000000
Signature:      C o m p r e s s e d   R O M F S
Fsid:           0x08 0x18 0x79 0x2b 0x00 0x00 0x00 0x00 0x0a 0x02 0x00 0x00 0xa4 0x01 0x00 0x00
Name:           0x08 0x18 0x79 0x2b 0x00 0x00 0x00 0x00 0x0a 0x02 0x00 0x00 0xa4 0x01 0x00 0x00


(1490944 / 512 = 2912)
(0x00350000 / 512 = 6784)

$ dd if=openrg.rta9211w_6_0_18_1_11.img of=data.cramfs skip=2912 count=6784

Extract the filesystem:

$ ./xcramfs 

*** cramfs test ***

struct super:
=============

        magic:          0x28cd3d45
        size:           0x  350000
        flags:          0x    a003
        future:         0x       0
        signature:      C o m p r e s s e d   R O M F S
        fsid:           0x 8 0x18 0x79 0x2b 0x 0 0x 0 0x 0 0x 0 0x a 0x 2 0x 0 0x 0 0xa4 0x 1 0x 0 0x 0
        name:           0x 8 0x18 0x79 0x2b 0x 0 0x 0 0x 0 0x 0 0x a 0x 2 0x 0 0x 0 0xa4 0x 1 0x 0 0x 0


x/bin (dir)
x/bin/adslctrl (file)
x/bin/busybox (file)
x/bin/dhcp6c (file)
x/bin/dhcp6s (file)
...

Create library links:

$ ln-libs.sh 

We can now use qemu to launch and debug the binaries (e.g.)

$ chroot ./x qemu-mips-static -g 12345 /bin/busybox

And:

$ mips-linux-gnu-gdb ./x/bin/busybox
(gdb) target remote 127.0.0.1:12345
(gdb) info functions
(gdb) break main 
(gdb) cont 
(gdb) disassemble main
...

References

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

  • LZMA_C extract from 7zip source code (old)

About

Extract cram filesystem with lzma compression for debug or forensic

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages