zondag 6 mei 2012

Interactive shell

In the last post I described how to get scripts running when you boot your Eee Note, but rebooting every time becomes cumbersome quickly, so the first thing I wanted to do was finding a better way to execute code. I used a simple dvt_check script to copy /etc and some other interesting directories:
#!/bin/sh

# cd to sdcard
cd /mnt/extsdcard
mkdir -p asus_ea800
cd asus_ea800

cp /userStyle.css .
cp /wac_tch .

mkdir -p bin
cp /bin/ts_* bin

cp -Ppr /etc etc

cp -Ppr /eTablet eTablet

mkdir -p sbin
cp /sbin/firmware.sh sbin

mkdir -p usr/local
cp -Ppr /usr/local/eTablet usr/local/eTablet

mkdir -p usr/sbin
cp /usr/sbin/formatuser.sh usr/sbin
cp /usr/sbin/scanuser.sh usr/sbin
cp /usr/sbin/sdcoldplugin usr/sbin
The folder /usr/local/eTablet contains a pretty large file that actually takes a long time to copy (the external card slot seems to have a very slow write speed), but I couldn't find an easy way to exclude just this file so I just let it work for an hour or two.


When going through the files, I noticed a script /etc/udev/scripts/sdautomount.sh. It makes sense that this script is called every time the external SD card is mounted, but lets check just to be sure.
hans:~/ea800/files/etc/$ ls udev/rules.d
05-udev-early.rules  11_sd_auto_mount.rules
hans:~/ea800/files/etc/$ cat udev/rules.d/11_sd_auto_mount.rules
KERNELS=="mmc01",KERNEL=="mss/blk*",SUBSYSTEM=="block",ACTION=="add",RUN+="/etc/udev/scripts/sdautomount.sh %k /mnt/extsdcard"
KERNEL=="mss/blk*",SUBSYSTEM=="block",ACTION=="remove",RUN+="/etc/udev/scripts/sdautoumount.sh %k /mnt/extsdcard"   


So any time the external SD card is added the script /etc/udev/scripts/sdautomount.sh is run, with the device path and the mountpoint as arguments. When unmounting, the script /etc/udev/scripts/sdautoumount.sh is run.


So my idea was to add a line like
/mnt/extsdcard/my_script
To the end of /etc/udev/scripts/sdautomount.sh so that myscript is run every time an external SD card is inserted. But when I checked the contents of the default script:
hans:~/ea800/files/etc/$ cat udev/scripts/sdautomount.sh
#!/bin/sh

pathName="$1"
mountPoint="$2"

umount $mountPoint
mkdir -p $mountPoint
mount -t vfat -o sync,utf8=1 /dev/$pathName $mountPoint
$mountPoint/./ASUS_ETABLE_HOPPER_TEST &
Notice the last line: the script already tries to run a script on the external SD card called ASUS_ETABLE_HOPPER_TEST! An engineer at Asus probably added this line to do make testing and, lucky for us, forgot to take it out. So instead of dvt_check I can now name my shell scripts ASUS_ETABLE_HOPPER_TEST and it will run without rebooting. (Note: a quick google search shows I'm not the first one to discover this, but it's still a nice find :P).

Shell scripts good, interactive shell better!


With the ability to run scripts as root you can do anything you want in Linux, however it is not necessarily the most efficient way to do things. So next up I tried to get an interactive shell running on the device. Like many other embedded Linux devices, the Eee Note uses BusyBox to provide the common Unix utilities. Luckily BusyBox also a telnet server daemon. So one could use the following ASUS_ETABLE_HOPPER_TEST script to listen for incoming connections:
telnetd &
This script has two problems however. Firstly this will cause the shell to execute /etc/profile, which contains much of the startup functionality of the Eee Note. The result is that when opening a shell, many startup processes get executed again, causing to Eee Note to freak out. So we need to prevent the shell from executing /etc/profile. This is simply done by passing an extra argument to telnetd:
telnetd -l /bin/sh &
Now the shell will be started as a non-login shell, causing it to skip /etc/profile

The second problem is that telnetd gets started every time you insert the external SD card. So if we insert, remove it again and insert it a second time, telnetd will run twice. We could use a simple check to detect if telnetd is running already, but a more elegant solution is to start telnetd on startup:
#! /bin/sh

if [ -z "`grep telnetd /etc/init.d/rcS`" ]
then
 echo "/usr/sbin/telnetd -l /bin/sh &" >> /etc/init.d/rcS
fi

Disclaimer

  • Executing this script will modify files on your Eee Note, this may very well void your warranty.
  • Execuring the scripts on this blog is AT YOUR OWN RISK, only do it you know what you are doing. I am in no way responsible for any damage done to your Eee Note by executing scripts from this blog, either directly or indirectly.

Security warning

The telnet daemon will listen for incoming connections and will grant root access to anyone that can connect to your Eee Note. This means that it is no longer safe to connect to a wifi access point unless you are absolutely sure that you trust everyone on the network! On public access points and company or university networks this usually means THE WHOLE INTERNET, since every device is assigned a unique ip-address. If use your Eee Note to connect to untrusted networks, use a less permanent way to start the telnet daemon, or use the uninstall script below before connecting.

Run this script once and reboot the device to start the Eee Note. You don't need the SD card from this point on :P
Connecting to the Eee Note can be done using either wifi or usb. I recommend usb since it is more secure.
To connect over usb just connect the Eee Note to your Linux PC with the included usb to micro-usb cable (On Windows, putty will probably work, but I have not tested it). Select the 'Eee Note Sync Mode' option on your Eee Note. On you computer, open a terminal and type:
ifconfig usb0 169.254.2.2
telnet 169.254.2.1

The first line creates a usb network interface with ip address 169.254.2.2, you can replace the ip with any address in the 169.254.2.0/8 subnet except 169.254.2.1 (which is the Eee Notes address). You will need root access to do this so use sudo if necessary.
The second line connects to the Eee Note and will give you an interactive shell. Be carefull, you are now root on the Eee Note!
You may need to install telnet using your package manager, most distributions include a package called telnet, Arch Linux bundles telnet in the inetutils package.

Uninstall script

To uninstall this hack run the following two commands on the Eee Note (either from over telnet or using a ASUS_ETABLE_HOPPER_TEST script):
cat /etc/init.d/rcS | grep -v telnetd > /etc/init.d/rcS2
mv /etc/init.d/rcS2 /etc/init.d/rcS
chmod a+x /etc/init.d/rcS

and reboot the Eee Note.

dinsdag 24 april 2012

Getting Started

The first step in hacking any device is gathering as much information as possible. Since there is no file explorer or terminal software available on the Eee Note by default, the most obvious way to do this is by removing the internal SD card and using a card reader to clone the file system. Luckily for me, someone has already done this, so I don't have to open up my Eee Note, which would void my warranty.
In the cloned filesystem Joshua.Lamorie on the tabletpcreview forum found the following lines in /etc/profile:
if [ -e /mnt/extsdcard/dvt_check ] ;then
cd /mnt/extsdcard
./dvt_check
fi
So every time the Eee Note is booted, it checks for the existence of a file called dvt_check in the folder /mnt/extsdcard/ which is, not surprisingly, the external SD card. If the file exists, it is executed as the root user. So running a script is as easy as naming it dvt_check and copying it to the root of a micro-SD card, inserting it the external card slot of the Eee Note and rebooting the device.

So lets try it out with a simple information gathering script: As expected, the script runs as root, uname returns:

Linux Linux 2.6.21 #5 PREEMPT Wed Aug 3 16:59:11 CST 2011 armv5tel unknown
df shows the partitions on the internal SD card:
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/mss/blk0p6        2956236     95400   2710664   3% /
/dev/mss/blk0p5         806288    563220    202108  74% /usr
/dev/mss/blk1p1        7756980     14968   7742012   0% /mnt/extsdcard
You can find the output of dmesg here.

The filesystem is basically structured as follows:

/ 
  -+- UserApp
   +- bin
   +- boot
   +- cross-tools
   +- dev
   +- eTablet
   |   +- Settings
   |   +- etc
   |   +- var
   |
   +- etc
   +- home
   +- lib
   +- lost+found
   +- media
   +- mnt
   +- opt
   +- proc
   +- root
   +- sbin
   +- srv
   +- sys
   +- tmp
   +- usr
   |   +- bin
   |   +- ...
   |   +- local
   |   |   +- ...
   |   |   +- eTablet
   |   |   |   +- bin
   |   |   |   +- lib
   |   |   |   +- translator
   |   |   +- ...
   |   |
   |   +- ...
   |
   +- var
Apart from the standard Posix folder structure we see two folders: /eTables and /usr/local/eTablet.
  • /usr/local/eTablet contains mostly binaries and some translation files.
  • /eTablet/Settings only contains one file ('Trolltech.conf') with settings for Qt)
  • /eTablet/etc contains config files for the individual applications developed by Asus, but also the notebook templates (backgrounds) and the SQLite database files that manage the notes, ebooks etcetera.
  • /eTablet/var contains the actual notes (one gif file per page) and ebooks.

vrijdag 13 april 2012

Obligatory introduction post

Welcome to my blog.

A few weeks ago I bought the Asus Eee Note to keep my lecture notes. I chose the Eee Note because it uses a Wacom digitizer instead of a regular touchscreen which makes it much more comfortable to write on than regular tablets with capacitive touchscreens. And, more importantly, it is a very hackable device and I do enjoy a bit of hacking ;)

About the Asus Eee Note

The Eee Note is a $200 device that is best described as a blend between a e-reader and a tablet. It's main purpose is to take notes and view documents.

The hardware

The Eee Note's hardware is pretty basic. It has an 8'' greyscale LCD display with XGA resolution (768x1024) with a wacom digitizer. It has WLAN, a 2 megapixel camera, USB connection, a micro SD slot and an audio plug.
Internally it has 4GB of storage in the form of an SD card.
The processor is an 312 MHz ARMv5tel (turbo mode: 624MHz). It has a bus speed of 208MHz and has 256MB RAM.

Nothing too spectacular here, but it is enough to keep the device quite responsive.

The software

This is where it gets interesting ;)
The device runs a Linux kernell (version 2.6.21) and no barriers are installed to keep the user from installing their own software. It even seems that Asus has made the device very open on purpose (for example there is a /UserApp folder already present in the filesystem).

This blog

I have already done a little bit of hacking on the device and I have a lot of ideas. So may in fact that I am already forgetting many of them, so that is why I started this blog. It gives me a place to write down my progress and ideas. And maybe the information here will even be usefull to someone.

There has already been done much research by other people on this device, much of it can be found on this forum:
http://forum.tabletpcreview.com/asus-eee-line/
This (very long) thread is useful in particular:
Asus Eee Note - A peek within
I read the first few pages of this thread, but stopped ready because I enjoy figuring stuff out myself and didn't want to spoil it ;)


Disclaimer

Since I use the word 'hacking' a lot in this blog, I should probably explain what I mean with this word.
I do not mean breaking into computer systems (which seems to be what most people think about when I say hacking [Thanks a lot, popular media <:-( ]).
I also do not mean circumventing security measures on a system or device (which is by some [mostly companies] regarded as illegal, even if you actually OWN the device).
What I do mean is using skills to make the best possible use of the systems that I own. This is the original meaning of the word hacking and this is the way I shall use it in this blog.