对Android系统 root的理解

来源:互联网 发布:php array remove key 编辑:程序博客网 时间:2024/05/16 10:02
一键root原理

利用某漏洞,让拥有root权限的进程执行

copyfile("/data/local/tmp/su","/sytem/xbin/su",07777);
chmod("/system/xbin/su",07777);
copyfile("/data/local/tmp/su","/system/bin/su",07777);
chmod("/sytem/bin/su",07777);



一键root后,正常程序的执行过程
先决条件

1.su在/system/xbin/su或/system/bin/su.

2.su文件权限为 -rwsr-xr-x  root root .

注:su拷贝到 /data/lcoal/tmp/目录下 ,即-rwsr-xr-x root root data/local/tmp/su。

su执行setuid(0)函数失败,提示权限不够,经了解 su不能在data分区执行。



1.adb shell 执行su命令
1.1 shell fork ()一个shell子进程
1.2 shell 子进程 内执行 exec("su").
1.3 su 调用setgid(0)|setuid(0). 把 shell子进程提取到root权限。
1.4 进行execlp("/system/bin/sh","sh",NULL);



注意:
1.fork()函数。
代码段共享,数据独立。父进程与子进程都从fork()函数地方运行。fork函数父进程返回子进程ID。 子进程返回0.

2.exec()函数系列

进程的代码与数据都会被替换。只是保留了pid的少量信息。(Windows的ShellExecute 等API 完全不同)

3.可以利用fork() 子进程 +  子进程exec() + 父进程wait() 模拟 ShellExecute(),CreateProcess等API.





0 0
原创粉丝点击