Tim Hatch

Weblog | Photos | Projects | Panoramas | About

An Exercise in Futility 01 Oct, 2008

A project called busybox is commonly used on tiny computers to give them usable versions of the standard utilities you’re used to on a GNU/Linux system. We use it at work, and it’s also used for all of the Linux router projects (DD-WRT, OpenWRT, etc). Its primary claim to fame is that most of the utilities are actually in one binary, so they can share a lot of code. Here’s the one we use at work:

$ ls -l /bin/
lrwxrwxrwx    1 root     root           14 Jan  1  1970 addgroup -> /bin/tinylogin
lrwxrwxrwx    1 root     root           14 Jan  1  1970 adduser -> /bin/tinylogin
lrwxrwxrwx    1 root     root            7 Jan  1  1970 ash -> busybox
-rwxr-xr-x    1 root     root       668428 Jan  1  1970 busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 cat -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 chattr -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 chgrp -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 chmod -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 chown -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 cp -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 cpio -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 date -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 dd -> busybox
lrwxrwxrwx    1 root     root           14 Jan  1  1970 delgroup -> /bin/tinylogin
lrwxrwxrwx    1 root     root           14 Jan  1  1970 deluser -> /bin/tinylogin
lrwxrwxrwx    1 root     root            7 Jan  1  1970 df -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 dmesg -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 dumpkmap -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1  1970 echo -> busybox
...

The fun part is when I used a DD-WRT micro build for the first time, which uses busybox but has a number of useful commands disabled. ls is one of them.

BusyBox v1.9.2 (2008-05-24 15:04:29 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

\u@\h:\w\$ ls /
-sh: ls: not found

ls is pretty easy to get around, just do echo * and it’ll show you a list of files. echo */ will list directories. cat is a little more interesting, I just had to go through all the commands on the system (before you ask, there’s no perl or python). Turns out the easiest way is to grep -v SDLFJKHSDLJFHS $filename (that is, grep out some impossible string, which works surprisingly well).

\u@\h:\w\$ echo /*
/bin /dev /etc /jffs /lib /mmc /mnt /opt /proc /sbin /sys /tmp /usr /var /www
\u@\h:\w\$ grep -v SDLFJKHSDLJFHS /tmp/hosts
127.0.0.1       localhost
10.123.1.1      border.hq.nutricateonline.com
...