0

Is it possible to change the rights of normal user in android to super user?

My requirement is to run the super user code(I want to read a file data from system directory) in a device that has rooted shell but we can not install any super user manager(SuperSu, Magisk etc.) on that device.

I thought of a solution like following:

  1. Install an apk in your device that has UI to call the required function on JNI side to start reading data from the file.
  2. Find the user id of the installed application. I found it in data/system/packages.list file.
  3. Make file owner is this new user id with su shell.
  4. Call the required function in the application that further try to open file.

but this solution is not working. The file is not opened by code and return -8002. The errno is 13.

fd = open("/system/file.txt", O_RDWR | O_LARGEFILE | O_NONBLOCK);
    if (fd < 0) {
        return -8002;
    }

This is very important for us. I shall be very thankful to all who will help me on this.

11
  • 2
    If phone isn't rooted with SuperSU/Magisk, from where comes the su binary? What file do you want to read from /system? May be the required information is available through some Android API. Jun 14, 2019 at 6:54
  • 1
    Rooted shell is given by the manufacturer and I want to read a android port data to log the network usage. Reading file is just an example to prove the concept that we can read privileged data with the help of rooted shell. I am really sorry if I am fail to explain the requirement but there is no such thing like hidden malware. Jun 14, 2019 at 7:12
  • 1
    I want my app to run NDK code for accessing the port without calling the su command. Because in NDK you can not create a su process and without su process an app can not read data from port. e.g. mobileinsight.net/diag-revealer.html These developers are reading data from /dev/diag port but they actually make an executable and copy the executable to system directory where they have root access. I do not want to use executable and instead want to create a shared library which can directly pass the port data to my android app. Jun 14, 2019 at 8:13
  • 1
    I know nothing about development; Java or native. So can't help you directly. But what I can tell is that it's not possible at all to change UID of an app to privileged UID. Android 4.3+ won't allow apps to execute /system/xbin/su because of multiple reasons explained here: android.stackexchange.com/a/207902/218526 Jun 14, 2019 at 17:30
  • 1
    Magisk is open-source. See how they do it. Jun 17, 2019 at 13:44

1 Answer 1

1

Depends what you want to do. With su (if it is installed) you became a superuser... But if you want to access some files you actually need to be the user system. This looks like it is your case. The credentials of user system can be given to an app (apk) if you are the owner of the android os image or you have access to the private keys the os was built with... If you do then you need to sign your app with those keys and mark it in manifest as user system...

1
  • Thanks Gogu. I know I can do this by making my app as system app. But this required platform signature to sign the apk. Manufacturer will never share this credential with us so we are looking to do it without the need of system app and platform signatures. That is why I am exploring the permissions in android. Jun 14, 2019 at 7:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .