android modified su binary failes on setgid - android

I have created a custom su binary for testing purposes.
I have copied the binary to /system/xbin/mod_su
I have changed the files permissions with chmod 6755 /system/xbin/mod_su,
but still when I run the binary as a non-root user I fail on setgid(0) with 'Operation not permitted1'
Any ideas why this could happen ?
isn't 6755 permmisons enough ?

Did you chown root.root it before chmod?

Apart from chown you can also try
chmod 4755
The 4 specifies set user ID which can be the reason for the error.

Related

on boot my android phone init .sh script run but not fully

Stack!
This my first question on this, so don't be too hard with me.
I want to run my own .sh script file on boot my android. To get this I rebuild kernel image and before that I add to init.rc file my own service which start after boot complete trigger:
on property:dev.bootcomplete=1
start fota-snoop
start fota-trigger
start startup-prober
start fairnet
the service itself:
service fairnet /system/bin/sh /system/etc/init.fairnet.sh
user root
group root
disabled
oneshot
permissions of /system/etc/init.fairnet.sh is set 644 like others init .sh scripts, and owner is root:root :
-rw-r--r-- root root 280 2018-01-09 01:03 init.fairnet.sh
init.fairnet.sh:
#!/system/bin/sh
insmod /system/lib/modules/xt_HL.ko
lsmod > /system/etc/curlsmod
/system/bin/iptables -t mangle -L > /system/etc/preiptables
/system/bin/iptables -t mangle -A POSTROUTING -o rmnet+ -j TTL --ttl-set 64
/system/bin/iptables -t mangle -L > /system/etc/postiptables
the most funny thing is command of load kernel module works fine, on boot too, but the other strings don't works: output files didn't exist, rule for iptables didn't add. I can't understand why insmod works and other commands don't.
Thanks for reading and sorry for my terrible English.
Problem solved!
SELinux blocked iptables in boot.
dmesg | grep iptables
gives me
<36>[ 39.819005] type=1400 audit(1516096993.541:9): avc: denied { create } for pid=2652 comm="iptables" lport=255 scontext=u:r:init_shell:s0 tcontext=u:r:init_shell:s0 tclass=rawip_socket op_res=-13 ppid=2640 pcomm="sh" tgid=2640 tgcomm="sh"
that means in current /sepolicy don't have rule i need.
For adding that rule i use sepolicy-inject, for build it need /usr/lib/libsepol.a, libsepol1-dev contains it. Also may use builded binaries for all archs (don't work for me, I build my own).
./sepolicy-inject -s init_shell -t init_shell -c rawip_socket -p getopt,create,setopt -P sepolicy -o sepolicy_new
add needed rule and make new sepolicy_new from old sepolicy from device.
Flash device with new sepolicy with new boot.img, I use AIK for Win.
Done! Now after boot my .sh script automatically runs and fully.
Thanks for reading and again sorry for my terrible English.
P.S. My own service I replaced from init.sony.rc to init.qcom.rc, also removed group root and disabled, but I done it only for ideological reasons and that not solve problem.
P.P.S. Change mode from Enforced to Permissive may do the thing, but I don't want to lost SELinux.

ADB shell permission issues with python scripts: /data/local/tmp/iperf not found [duplicate]

root#hammerhead:/data/local # ./HelloWorld
tmp-mksh: ./HelloWorld: No such file or directory
Hello!
I compiled using gcc on Linux Deploy, which as I understand downloads Ubuntu and chroots into the environment. The file runs fine inside of this chroot environment.
As I understand this error is given when the file doesn't match the architecture of the machine. But it is running on the same machine! Does anyone know why this may be happening?
File permissions, ownership and context:
-rwxrwxrwx root root u:object_r:system_data_file:s0 HelloWorld
Id output:
uid=0(root) gid=0(root) context=u:r:init:s0
Using /system/bin/sh
/system/bin/sh: ./Helloworld: No such file or directory
Trying to execute a non existant file:
/system/bin/sh: ./test: not found
You should compile your binary with gcc '-static' key. If you don't do that, you binary will need dynamic linker ld.so that doesn't exist on Android (but definitely exists inside your chroot!). This implies that strange error message "No such file or directory".

Android: cannot execute file compiled through Linux Deploy on the same phone

root#hammerhead:/data/local # ./HelloWorld
tmp-mksh: ./HelloWorld: No such file or directory
Hello!
I compiled using gcc on Linux Deploy, which as I understand downloads Ubuntu and chroots into the environment. The file runs fine inside of this chroot environment.
As I understand this error is given when the file doesn't match the architecture of the machine. But it is running on the same machine! Does anyone know why this may be happening?
File permissions, ownership and context:
-rwxrwxrwx root root u:object_r:system_data_file:s0 HelloWorld
Id output:
uid=0(root) gid=0(root) context=u:r:init:s0
Using /system/bin/sh
/system/bin/sh: ./Helloworld: No such file or directory
Trying to execute a non existant file:
/system/bin/sh: ./test: not found
You should compile your binary with gcc '-static' key. If you don't do that, you binary will need dynamic linker ld.so that doesn't exist on Android (but definitely exists inside your chroot!). This implies that strange error message "No such file or directory".

Cannot use dex2jar on my mac: permission denied

I downloaded dex2jar and now trying to use it, but if I type 'sh d2j-dex2jar.sh' it shows the following message.
d2j-dex2jar.sh: line 36: ./d2j_invoke.sh: Permission denied
At first I thought that the permission was denied because the programme required the root permission, so I also tried adding 'sudo' to the command, and it did not work either. How should I solve this problem?
You need to provide execute permissions to your sh script.
To do that : sudo chmod +x d2j_invoke.sh
Still If you find no luck use,
chmod a+x *.sh

bash: ./studio.sh: Permission denied (error installing Android-Studio)

While I was trying to Install Android-Studio
and execute the command
#abhinay-Pc:/android-studio/bin$`./studio.sh
It is showing the error:
bash: ./studio.sh: Permission denied
I have already exported Java directory to /android-studio/bin folder`
(Java_Home = /usr/lib/jvm/java-7-oracle)
I have the java-7 installed on my system.
You might not have chmod +x studio.sh try sh ./studio.sh
If this was not it, try again like this: sh -x ./studio.sh. This will show you every line that is run and will help you debug it.
Good luck.
you must change the properties of the studio.sh file and change in the permission to Allow this file to run as program

Categories

Resources