site_vineetk

Source for vineetk.net website
Log | Files | Refs | LICENSE

kobo_clara-nickel.md (10458B)


      1 title: Kobo Clara HD Notes for Nickel
      2 date: 2021-01-13 12:00
      3 ---
      4 
      5 My ereader of choice is the Kobo Clara HD and I particularly like it
      6 because my eyes hurt less when reading for long periods of time
      7 compared to when I read on my phone or when I still had my iPad. It
      8 also had much longer battery life and only need to charge it about once
      9 every two weeks when I read for about 4 hours on average daily.
     10 
     11 However, the two notable things I don't like about it is it's included
     12 telemetry, like using Google Analytics by default and keeping a unique
     13 salt
     14 
     15 Spyware/Anti-Features:
     16 - Google Analytics (a lot of actions, if not everything, is sent to
     17 Google)
     18 - Auto-update by default
     19   - I prefer being able to review what the new update provides and
     20     choose not to apply it
     21   - I don't like the new redesign in firmware v4.23.15505
     22 
     23 I'm also assuming your Kobo reader and it's SD card's device file would
     24 be would located at `/dev/sdf` and be mounted at `/mnt/kobo`.
     25 
     26 If you're going to not be using Nickel and instead be using something
     27 like [Plato](https://github.com/baskerville/plato), there's a newer version of this article available
     28 [here](./kobo-clara-plato.html), but the notes are for ~KSM~ loading Plato directly and not
     29 though k/fmon because I don't want to load Nickel if I'm already using
     30 a different reader.
     31 
     32 ## Upgrade/Backup Included SD Card
     33 While the included 8GB microSD card is decent for storing your ebook
     34 library that may not have a lot of images, that would likely not be
     35 enough if you were aiming to read some comics on your ereader as they
     36 can be pretty big (quite a few of mine are over a gigabyte, with some
     37 over. Luckily, you can replace the microSD card with another one.
     38 
     39 Before upgrading, you should backup the SD card to into an image file
     40 so the filesystem would be preserved when putting the contents of the
     41 image on the new SD card. I'm using the command dd but there might be
     42 another program doing the same thing. Even if you're not going to
     43 upgrade, I still suggest to backup the SD card in case something goes
     44 wrong.
     45 ```sh
     46 dd if=/dev/sdf of=kobo_sd.img conv=sync
     47 ```
     48 
     49 After this is done, you can plug in your new SD card and reimage
     50 kobo_sd.img onto it. With dd, you can do something like:
     51 ```sh
     52 dd if=kobo_sd.img of=/dev/sdf conv=sync
     53 ```
     54 
     55 Checking it's partition table via lsblk or fdisk -l should show three
     56 partitions. If you replaced the SD card with something bigger, than you
     57 should resize the third partition.
     58 
     59 ## Bypassing Registration On Setup
     60 When setting up your Kobo, you will be asked to sign into a Kobo
     61 account. There are other options like logging in via Google, Walmart,
     62 and other stores, but I don't like having to login to a device that
     63 would likely not be connected to the public internet. Fortunately, you
     64 can bypass this by choosing that you cannot connect to a Wi-Fi network
     65 and mount your Kobo to your computer. In, `.kobo/KoboReader.sqlite`, you
     66 can run:
     67 ```sh
     68 echo "INSERT INTO user(UserID,UserKey) VALUES('1','');" \
     69      | sqlite3 KoboReader.sqlite
     70 ```
     71 
     72 This way you don't have to install their application just to be able to
     73 use your device.
     74 
     75 Note: Do not try doing this when you still have your SD card mounted
     76 before you setup your device. The device's screen would likely not
     77 update, at least on an early firmware version like v4.7.10733.
     78 
     79 ## Blocking Google Analytics and other Telemetry
     80 Just adding 0.0.0.0 analytics.google.com to `/etc/hosts` may be enough to
     81 block most of the telemetry from being sent. However, you can try
     82 intercepting what connections your Kobo is making via mitmproxy set to
     83 transparent mode or using a hosts file that blocks all connections to
     84 Google (but not necessarily to Kobo's servers) like [Baobab's hosts file](https://codeberg.org/baobab/hosts)
     85 [(raw)](https://codeberg.org/baobab/hosts/raw/branch/master/hosts).
     86 EDIT 2022-10-21: Baobab has deleted his account from Codeberg for quite a
     87 while, so these two links are dead. Instead, I now recommend [Steven Black's](https://github.com/StevenBlack/hosts)
     88 instead [(raw)](https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts).
     89 
     90 To put the hosts file without root (which will be detailed in another
     91 section), you can make a directory called etc, put the hosts file in
     92 there, and tar it into a file called KoboRoot.tgz.
     93 ```sh
     94 mkdir etc
     95 wget -O etc/hosts https://codeberg.org/baobab/hosts/raw/branch/master/hosts
     96 tar czvf KoboRoot.tgz etc
     97 cp KoboRoot.tgz /mnt/kobo/.kobo/
     98 ```
     99 
    100 When you move a tar file with that name into your Kobo's .kobo folder,
    101 it's contents gets untarred into it's root at `/` when the device is
    102 turned on again, which is usually done for their updates but can be
    103 used for custom files like this and gaining root access.
    104 
    105 ## Gaining Root Access via Telnet
    106 To gain root access, we first need to get the `/etc/inittab` and
    107 `/etc/inetd.conf` which you can get from mounting the SD card's first
    108 partition into your computer (the second partition seems to be like a
    109 backup). You should copy those two files into a folder called etc
    110 somewhere (probably not on the SD card).
    111 
    112 In the `etc/inittab` file, you should add these two lines:
    113 ```
    114 ::sysinit:/etc/custominit.sh
    115 ::respawn:/usr/sbin/inetd -f /etc/inetd2.conf
    116 ```
    117 
    118 You would want to rename the `etc/inetd.conf` file you copied into
    119 `etc/inetd2.conf` (or whatever the custom inetd.conf's filename is) and
    120 when editing that, you should add:
    121 ```
    122 23 stream tcp nowait root /bin/busybox telnetd -i
    123 ```
    124 
    125 However, if there is already a commented line for root telnet in the
    126 inetd2.conf, you should probably still add the above line and ignore
    127 the commented line as that may or may not work (didn't for me).
    128 
    129 To actually start inetd, you should add these lines somewhere in
    130 `/etc/custominit.sh`:
    131 ```sh
    132 mkdir -p /dev/pts
    133 mount -t devpts devpts /dev/pts
    134 /usr/sbin/inetd /etc/inetd2.conf
    135 ```
    136 
    137 After that, you just have to tar the `etc/` folder again and copy it to
    138 your Kobo's onboard/third partition's `.kobo` folder.
    139 ```sh
    140 tar czvf KoboRoot.tgz etc
    141 cp KoboRoot.tgz /mnt/kobo/.kobo/
    142 ```
    143 
    144 Now you could put your SD card back into your Kobo provided that they
    145 are already unmounted and turn your Kobo back on.
    146 
    147 After connecting to the WiFi, simplying telnetting (?) into your Kobo
    148 and logging in as root should give you a root shell. :D
    149 ```sh
    150 telnet $KOBO_IP
    151 ```
    152 
    153 By default, root has no password so you should change it with passwd.
    154 
    155 ## Getting SSH and SFTP access via Dropbear
    156 I'm using Dropbear instead of OpenSSH because it's better suited for
    157 embedded hardware like the Kobo Clara HD. Obviously we can't copy a
    158 binary compiled for amd64 or whatever architecture your compiling
    159 computer is running so we would have to cross-compile for our ereader.
    160 
    161 Fortunately, we are not required to cross-compile `gcc`/`clang` and friends
    162 as we can simply download the linaro arm toolchain which has the
    163 binaries for gcc and others included. You could get the toolchain
    164 [here](https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/) and you should get the release that matches your host's
    165 
    166 architecture. After untarring the file, you should also set your PATH
    167 variable to the toolchain's `bin/` folder so you don't have to manually
    168 set the CC and CXX variables when building Dropbear.
    169 
    170 ```sh
    171 wget https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
    172 tar xvf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
    173 export PATH=$(pwd)/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin:$PATH
    174 ```
    175 
    176 Now you could get the source for Dropbear and cross-compile it. The
    177 source can be found on their [homepage](https://matt.ucc.asn.au/dropbear/dropbear.html) or [github](https://github.com/mkj/dropbear/releases) repo.
    178 ```sh
    179 wget https://matt.ucc.asn.au/dropbear/releases/dropbear-2020.81.tar.bz2
    180 tar xvf dropbear-2020.81.tar.bz2
    181 cd dropbear-2020.81
    182 ./configure --enable-static --host=arm-linux-gnueabihf
    183 # MULTI=1 combines the binaries like busybox does and is also smaller in size
    184 make MULTI=1 PROGRAMS="dropbear dropbearkey"
    185 ```
    186 
    187 Now you only need to copy the dropbearmulti binary over to your Kobo.
    188 What I've done is running `python3 -m http.server` and downloading the
    189 file onto my Kobo but you could also just copy it onto the microSD
    190 card.
    191 ```sh
    192 wget your.computer.ip:8000/dropbearmulti
    193 chmod +x dropbearmulti
    194 mv dropbearmulti /usr/bin
    195 cd /usr/bin
    196 # below are optional but dropbear(key) would be an argument for dropbearmulti
    197 ln -s dropbearmulti dropbear
    198 ln -s dropbearmulti dropbearkey
    199 ```
    200 
    201 Now you only need to generate the host keys. My client key is ed25519
    202 so I'm not going to generate the others.
    203 ```sh
    204 mkdir /etc/dropbear
    205 dropbearkey -t ed25519 -f /etc/dropbear/dropbear_ed25519_host_key
    206 dropbear -F -r /etc/dropbear/dropbear_ed25519_key
    207 ```
    208 
    209 Now you could `ssh` into your Kobo and login as `root`. Remember to change
    210 `root`'s password beforehand though if you haven't already! I suggest
    211 copying your public key to your Kobo via `ssh-copy-id` so you don't have
    212 to enter root's password all the time and so password-based logins can
    213 be disabled in dropbear.
    214 
    215 To start it on boot, you could add the following line to
    216 `/etc/inetd2.conf`:
    217 ```
    218 22 stream tcp nowait root /usr/bin/dropbearmulti dropbear -i -r /etc/dropbear/dropbear_ed25519_key
    219 ```
    220 
    221 For some reason, the symlink wasn't resolving for me inetd so I had to
    222 call the multi-binary directly. You could also add the command/args
    223 into `/etc/custominit.sh`.
    224 
    225 ## FTP Access
    226 If you don't or can't use sftp or scp for some reason, there's always ftp :D
    227 There's a ftp daemon included in busybox so all we have to do is enable it
    228 in `/etc/inetd2.conf`:
    229 ```
    230 21 stream tcp nowait root /bin/busybox ftpd -w -S /
    231 ```
    232 
    233 This would share the entire filesystem so you may or may not want to
    234 restrict the shared directory to maybe just your ebook directory
    235 (`/mnt/onboard`) and move the files out via `telnet` or `ssh`.
    236 EDIT 2022-10-21: A chroot would also work.
    237 
    238 ## References and Other Links
    239 - [Rémy's notes on hacking a Kobo Aura H2O](https://remy.grunblatt.org/kobo-aura-h2o-electronic-reader-hacking.html)
    240 - [Ying's notes on bypassing registration and setting up telnet, ssh, etc.](https://yingtongli.me/blog/2018/07/30/kobo-rego.html)
    241 - [MobileRead forum thread on disabling Google Analytics on the Kobo Touch](https://www.mobileread.com/forums/showthread.php?t=162713)
    242 - [MobileRead wiki on hacking the Kobo Touch](https://wiki.mobileread.com/wiki/Kobo_Touch_Hacking)