Wednesday 18 June 2014

How to run adb shell always as a root?

 Goal

How can we run adb shell every time with root permissions. Procedure is shown below.

You can try this method, but be carefully as this allows any app to gain root access. You can say this may led to "Security Hole!"

Procedure


Make your suid binary insecure by typing the following commands.

  1. Go to platform-tools directory inside sdk folder.
  2. Open command prompt in that directory and execute following commands.
  3. adb shell
  4. su
    User will be prompted to grant super user privileges to adb shell.

  5. mount -o remount,rw /system (or: adb remount)
  6. ls -la /system/bin/sh (Observer the output)
  7. chmod 4755 /system/bin/sh
  8. ls -la /system/bin/mksh (Again observe the output. Notice the SUID bit set)
  9. exit



Above steps will make your adb shell run as root every time. If you do not understand how SUID bit works in Linux (android has linux kernel after all) you can look at following post : Quick introduction to SUID: What you need to know .

How to change host file in an Android device?

Goal

In this post we will see how can we edit host file in an android device.

Prerequisites and Background

You must have a rooted device!! You cannot really alter system files if your device is not rooted. Next you need android SDK. Device of course and data cable. We will be using adb tool that comes with the SDK. You can go through my earlier post on What is Android Debug Bridge (adb)?  You can also go through some helpful posts like Android Partitions and Kernel Explained  and Android Partitions Basic. If you want to root your android device you can go through that post to : How to root your Android device?


Editing the host file

  1. Navigate to the window where you adb tool is located. That would be adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk\platform-tools.
  2. There open the terminal and type adb devices. You should see your device listed there. If you cannot see your device listed here try steps provided here Troubleshooting steps when Eclipse ADT does not recognizing your Android device and Troubleshooting steps when Android device is detected but not recognized by Eclipse ADT.

  3. Next pull the host file using the following command

    adb pull /system/etc/hosts ./



    You should get host file in the current directory.
  4. Change the host file as per the mapping you want.

  5. Push the file back to the device using following command.

    adb push hosts /system/etc/That should push your host file back to system/etc folder. And you are done. Your host file is successfully changed.
  6.  You can cross verify your changes by logging into adb shell and viewing the host file.

  7. For above step you will have to grant adb shell su privileges. It will prompt you on the device.

  8.  Finally you can test your changes by typing test.domain.com in your android browser.  You may have to restart your phone to refresh DNS cache. It wont load because there is no server running with that URL. If you map facebook.com to this URL even facebook will not load.


t> UA-39527780-1 back to top