267 Hacking Linux Powered Devices
267 Hacking Linux Powered Devices
267 Hacking Linux Powered Devices
Devices
Stefan Arentz
<stefan@soze.com>
Part I
Introduction
What is Embedded Linux?
Embedded usually means that it is a device
with limited and specialized capabilities. It is
not a ‘personal computer’ as your laptop or
PC on your desk.
Start a Wiki!
Example - Linksys WRT54G
Our Goal
RADIO
FLASH
ETH SWITCH
POWER
Back to our Goal: Hacking the
Firmware Image
Header
Compressed Kernel
Compressed File System
(CRAMFS)
Firmware Image Header
% hexdump -C ~/WRT54G_1.30.1_US_code.bin
00000000 57 35 34 47 00 00 00 00 03 06 17 01 1e 01 55 32 |W54G..........U2|
00000010 4e 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |ND..............|
00000020 48 44 52 30 00 d0 29 00 78 53 6c d5 00 00 01 00 |HDR0.?).xSl?....|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
struct trx_header {
uint32_t magic; /* "HDR0" */
uint32_t len; /* Length of file including header */
uint32_t crc32; /* 32-bit CRC */
uint32_t flag_version; /* 0:15 flags, 16:31 version */
uint32_t offsets[3]; /* Offsets of sections */
};
Extract the Kernel and
CRAMFS
% ls -l /mnt
drwxr-xr-x 1 root root 444 1970-01-01 01:00 bin/
drwxr-xr-x 1 root root 0 1970-01-01 01:00 dev/
drwxr-xr-x 1 root root 88 1970-01-01 01:00 etc/
drwxr-xr-x 1 root root 164 1970-01-01 01:00 lib/
drwxr-xr-x 1 root root 0 1970-01-01 01:00 mnt/
drwxr-xr-x 1 root root 0 1970-01-01 01:00 proc/
drwxr-xr-x 1 root root 292 1970-01-01 01:00 sbin/
drwxr-xr-x 1 root root 0 1970-01-01 01:00 tmp/
drwxr-xr-x 1 root root 64 1970-01-01 01:00 usr/
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 var -> tmp/var
drwxr-xr-x 1 root root 1328 1970-01-01 01:00 www/
# ls -l /mnt/bin
-rwxr-xr-x 1 root root 268408 1970-01-01 01:00 busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 cat -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 chmod -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 cp -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 date -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 dd -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 df -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 echo -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 false -> busybox*
lrwxrwxrwx 1 root root 7 1970-01-01 01:00 grep -> busybox*
# file /mnt/bin/busybox
bin/busybox: ELF 32-bit LSB MIPS-I executable, MIPS,
version 1 (SYSV), for GNU/Linux 2.3.99,
dynamically linked (uses shared libs), stripped
% ls -l /mnt/lib
-rwxr-xr-x 1 root root 140264 1970-01-01 01:00 ld.so.1*
-rwxr-xr-x 1 root root 35180 1970-01-01 01:00 libcrypt.so.1*
-rwxr-xr-x 1 root root 871936 1970-01-01 01:00 libc.so.6*
-rwxr-xr-x 1 root root 15460 1970-01-01 01:00 libdl.so.2*
-rwxr-xr-x 1 root root 13564 1970-01-01 01:00 libm.so.6*
-rwxr-xr-x 1 root root 13564 1970-01-01 01:00 libnsl.so.1*
drwxr-xr-x 1 root root 20 1970-01-01 01:00 modules/
% cd crosstool-0.28
% ./demo-mipsel.sh
Header
The script simply takes the kernel and the
CRAMFS sections and creates a new
Compressed Kernel
firmware image with a header with the right
CRC32 checksum. Compressed File System
(CRAMFS)