Chapter 2. Android Rooting

This chapter, Android Rooting, gives an introduction to the techniques typically used to root Android devices. We will begin with the basics of rooting and its pros and cons. Then, we shall move on to topics such as various Android partition layouts, boot loaders, boot loader unlocking techniques, and so on. This chapter acts as a guide for those who want to root their devices and want to know the ins and outs of rooting concepts before they proceed.

The following are some of the major topics that we will discuss in this chapter:

Android is built on top of Linux Kernel. In Unix based machines such as Linux, we see two types of user accounts – normal user accounts and root accounts. Normal user accounts usually have low privileges and they need permission from root to perform privileged operations such as installing tools, making changes to the Operating System, and so on. Whereas root accounts have all the privileges such as applying updates, installing software tools, ability to run any command, and so on. Essentially, this account has granular control over the whole system. This privilege separation model is one of the core Linux security features.

As mentioned earlier, Android is an operating system built on top of Linux Kernel. So many features that we see in traditional Linux systems will also be present in Android devices. Privilege separation is one among them. When you buy a brand new Android device, technically you are not the owner of your device, meaning you will have limited control over the device in terms of performing privileged operations that are possible for root accounts. So gaining full control over the device by gaining root access is termed as rooting.

One simple way to check if you have root access on the device is by running the su command on an adb shell. su is Unix's way of executing commands with the privileges of another user:

As we can see in the preceding excerpt, we have no root access on the device.

On a rooted device, we usually have UID value 0 with a root shell having # rather than $ representing root account. This looks as shown following:

This section describes various disadvantages of rooting an Android device and why it is dangerous for end users to root their devices.

Once a device is rooted, it compromises the security of your device.

By default each application runs inside its own sandbox with a separate user ID assigned to it. This user id segregation ensures that one application with its UID running on the device cannot access the resources or data of other apps with different UID running on the same device. On a rooted device, a malicious application with root access will not have this limitation and so it can read data from any other application running on the device. A few other examples would be bypassing lock screens, extracting all the data such as SMS, call logs, contacts, and other app specific data from a stolen/lost device.

Let's see a practical example of how it looks like. content://sms/draft is a content provider URI in Android to access the draft SMS from the device. For any application on your device to access the data through this URI, it requires READ_SMS permission from the user. When an application tries to access this without appropriate permission, it results in an exception.

Open up a shell over USB using adb and type in the following command with a limited user shell (without root access):

As we can see in the preceding excerpt, it is throwing an exception saying permission denied.

Now, let's see how it looks like when we query the same URI using a root shell:

As we can see in the preceding output, we do not require seeking any permission from the user to be able to read SMS with root privileges and thus compromising the data of the application sitting on the device. It is quite common to see root apps executing shell commands on devices to steal sensitive files such as mmssms.db.