Attempting to gain r/w access to android /system - android

Working on a root script for the Nexus 4 with the latest stock rom .img for google (occam) and I have the following code snippet:
./adb wait-for-device
echo "remounting system"
./adb shell "mount -o remount,rw /system"
./adb push su /system/bin/
echo "pushing super user"
./adb push Superuser.apk /system/app/
echo "pushing busybox"
./adb push busybox /system/xbin/
./adb shell "chmod 06755 /system/bin/su"
./adb shell "chmod 0644 /system/app/Superuser.apk"
./adb shell "chmod 04755 /system/xbin/busybox"
./adb shell "cd /system/xbin"
./adb shell "busybox --install /system/xbin/"
I keep getting the error
mount: Operation not permitted
failed to copy 'su' to '/system/bin//su': Read-only file system
pushing super user
failed to copy 'Superuser.apk' to '/system/app//Superuser.apk': Read-only file system
pushing busybox
failed to copy 'busybox' to '/system/xbin//busybox': Read-only file system
Unable to chmod /system/bin/su: No such file or directory
Unable to chmod /system/app/Superuser.apk: No such file or directory
Unable to chmod /system/xbin/busybox: No such file or directory
/system/bin/sh: busybox: not found
I've tried using multiple methods of obtaining r/w access, but nothing seems to be working. I have to automate this process due to the fact that other people will use the script so it needs to be automation friendly, but I just can't figure this out.
I've also tried the
#su
#mount
#mount | grep system
followed by inputting the partition with the system mount and changing it to r/w access, but that also hasn't worked.
Really frustrated at this point. Can anyone help?

It gives the error because you aren't root. The system partition is mounted read-only. You can try to push the binary to /data/local/tmp. Then you can make su executable and eventual run it. But it doesn't mean you can have root. To become root you need to push an exploit like psneuter to /data/local/tmp and run it. It crashes the shell and reopen a new one with root rights. Then you can remount the system-partition read-write and install su.

Try the commands below
adb shell "su -c mount -o remount,rw /system"
adb shell "su -c chmod 06755 /system/bin/su"
and so on.

Related

Hosts file for Android emulator

I'm trying to setup hosts file for android emulator. I saw this advice:
adb remount
adb push hosts /etc/system/hosts (most tutorials suggest
this file)
adb push hosts /system/etc/hosts (some VM systems seem to
prefer this file instead!, for me this worked)
But when I do adb remount it writes "remount of the / superblock failed: Permission denied". I'm going to adb shell, but it also writes an error.
generic_x86:/ # mount -o remount,rw /system
mount: '/system' not in /proc/mounts
1|generic_x86:/ # mount -o rw,remount,rw /system
mount: '/system' not in /proc/mounts
generic_x86:/ # mount -o remount,ro /system
mount: '/system' not in /proc/mounts
1|generic_x86:/ # whoami
root
I reinstalled Android Studio twice it didn't help. Could anyone help pls?
Usage of -writable-system flag made ADB remount work. Hosts were replaced with the new file.
Launched emulator as:
emulator.exe -writable-system -avd Nexus_5X_API_28_x86
The hosts file is located at a directory that is not allowed to write over a file. So, you should first copy hosts to somewhere else, edit it, and then copy it back.
For example, let's work on the standard emulator:
Run the following command while the emulator is open:
adb devices
This command will show the running emulators. Run the following command to disable the emulator's read-only behaviour:
adb -s emulator-5554 remount
After this step, it should log remount succeeded. Then you should copy the emulator to another directory for editing:
adb -s emulator-5554 pull /system/etc/hosts ~/Desktop/
After this step, it will log about the file transfer's success. Now you can edit the hosts file. After the edit, you should push the file back. First of all, you should reboot the adb:
adb reboot
Emulator will restart itself. After this, you can remount the adb:
adb -s emulator-5554 remount
After the remount, you can push back hosts file:
adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts

Can't move file from /sdcard/ to /system/app/ with shell, even with su.

Note: I am running this on a rooted device.
From my application, if I try to move a file from /sdcard/ to /system/app/ it fails. The following shell script does not work:
su
mount -o remount,rw /system
mv /sdcard/file.apk /system/app/file.apk
Whereas the following will work:
su
mount -o remount,rw /system
mv /system/app/file.apk /system/app/file.apk.bak
Why doesn't it work when copying from /sdcard/? (or any other file location I've tried).
I can't see the output from the location I'm running this however if I try from ADB then it gives me an error that the source file was not found even though it definitely exists.
adb root
adb remount
adb push my-app.apk /sdcard/
adb shell
su
cd /sdcard
mv my-app.apk /system/priv-app
cd /system/priv-app
chmod 777 my-app.apk
This worked for me on a rooted device
adb root
adb remount
adb push [local-file.apk] /system/app/file.apk
adb reboot

Android Run script in ADB shell

I am trying to fallow this tutorial in order to install SSL certificate on Android emulator.
I need to start the emulator from command line, so I run
emulator -avd myDevice -http-proxy myIp:8888
After device is started I want to copy my certificate file from PC to the device, so I run those commands
mount -o remount,rw /system
cp /sdcard/5ed36f99.0 /system/etc/security/cacerts/
cd /system/etc/security/cacerts/
chmod 644 5ed36f99.0
I bundle them all together using this suggestion
The final command looks like this:
adb shell su -c 'mount -o remount,rw /system; cp /sdcard/5ed36f99.0 /system/etc/security/cacerts/; cd /system/etc/security/cacerts/; chmod 644 5ed36f99.0'
But I am getting an error:
su: invalid uid/gid '-c'
If I do it from the shell it works, but then when I restart the emulator it restore the system to previous state without saving my changes.
How can I solve those two problems?

Push build.prop to /system/build.prop

I have edited build.prop and now my phone cannot boot. I have pulled build.prop using adb and now I have the correct build.prop file
What I need is to push build.prop using adb.
First try: Read-only file system
when I mount system:
Second try: Permision Denied
what can I do?
Probably because adb push uses the shell user, which does not have write permissions to /system/build.prop. You can, however, push the file to a different location first (e.g. /data/local/tmp/) and then move the file to the right place with the root user (after mounting).
Here are the commands you need to use:
adb push <Path to build.prop>/build.prop /data/local/tmp/
adb shell
su
mount -o rw,remount /system
adb push /data/local/tmp/build.prop /system/build.prop
I tried the following code... it works but i do not know if is the solution because my phone still cannot boot.
adb shell
su
mount -o remount,rw /dev/block/stl9 /system
chmod 777 /system
exit
exit
adb push build.prop /system
please let me know if the following code is correct or not...
adb remount
adb push build.prop /system/
adb shell chmod 644 /system/build.prop
adb reboot
this works for me for Galaxy S6:
cd C:\Users[here the userprofilename]\AppData\Local\Android\sdk\platform-tools>
1.) adb pull /system/build.prop
- this download the file from the phone in the adb folder
- edit the file, then load up to the phone:
2.) adb root
3.) adb root remount rw
4.) adb root chmod 664 /system/build.prop
5.) adb root push ./build.prop /system/build.prop
adb shell
su
mount -o remount,rw /dev/block/st19 /system
chmod 777 /system
exit
exit
push build.prop /system
adb shell
su
chmod 644 /system/build.prop
exit
exit
reboot
that worked for me :)
This is what worked for me:
adb push \build.prop /data/local/tmp/
adb shell
su
rm /system/build.prop
cp /data/local/tmp/build.prop /system
exit
exit
adb reboot
Hope it helps.
Ok lets do it. i found a simple way to by pass root permissions.
If u have a CWM recovery... enter on it and on "mounts and storage" enter and mounts /system/ them your pc will recognize it on adb push and send it to system.
Use your command codes above you write them voilá... your tablet/phone will boot again. if you have a backup of original build.prop

Why can't I push sqlite into Android using adb command?

I have a rooted Nexus S and it doesn't have Sqlite installed so I googled it and found I need to use
this command:
adb push sqlite3 /sdcard/
However it gave me this error:
failed to copy 'sqlite3' to '/sdcard//sqlite3': Read-only file system
So that means the /system is read only. Then I searched it and found that I need to remount my /system folder as rw. I used this command in the adb shell:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock5 /system
I still cannot push Sqlite3 and it produces the same error as before in the command line window.
I then typed
root#android:/ # mount
But all I can see is the /system is mounted differently:
/dev/block/platform/s3c-sdhci.0/by-name/system /system ext4 rw,relatime,barrier=
1,data=ordered 0 0
How can I mount my system folder as "rw" and push the sqlite3 into my Android phone?
Maybe you can try another location. The script I used to root my phone was placing its stuff on the /data/local/ after creating a tmp folder:
adb shell "cd /data/local && mkdir tmp"
adb push sqlite3 /data/local/tmp/.
adb shell "chmod 755 /data/local/tmp/sqlite3"
adb shell "cp /data/local/tmp/sqlite3 /system/bin/sqlite3"
adb shell "cd /data/local/tmp && rm *"
In fact, the two answers are mandatory. If we set only
adb shell "cd /data/local && mkdir tmp"
adb push sqlite3 /data/local/tmp/.
adb shell "chmod 755 /data/local/tmp/sqlite3"
adb shell "cp /data/local/tmp/sqlite3 /system/bin/sqlite3"
adb shell "cd /data/local/tmp && rm *"
We have the same error
Read-only file system
So, before copy the sqlite3 to /system/bin/sqlite3, we must add the following line :
mount -o rw,remount -t yaffs2 /dev/block/mtdblock5 /system

Categories

Resources