Git Product home page Git Product logo

xcramfs's Introduction

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)

xcramfs's People

Contributors

joseigbv avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.