Android 手机Root 原理解析

Root 手机的原理 ?

  Root 是Linux 等类Unix 系统的超级管理员用户账户,手机Root 也就是系统破解(在 iOS 设备中叫做“越狱”),当手机被Root ,其他用户就可以以超级管理员的身份运行程序。

  Root 的原理是 修改系统的/system/bin/su 文件

su 源代码 下载地址:http://download.csdn.net/detail/jinzhu117/4821630

SuperUser 是什么?

SuperUser 是用来管理用户Root 权限的软件。当手机被Root 之后,相当于所有的用户都有了以Root 用户的身份运行只能Root 用户才能执行的程序和命令,用户可以任意的修改系统密码,删除系统重要文件等等,系统变得非常不安全,SuperUser 就是用来管理其他用户是否有权限使用超级管理员身份的运行应用程序的系统软件。当有用户(程序)想以root 权限 或者以root 权限执行命令及程序时,su.c 会先启动SuperUser ,询问用户是否给予该程序(用户)Root 权限,如果给则将该进程设置为root 

安装SuperUser 后,会替换掉 /system/bin/su 文件,

SuperUser 源代码下载地址:http://download.csdn.net/detail/jinzhu117/4821569

一个软件获取Root 权限之后,能给其他应用程序 Root 权限吗?

1.把su.c 替换成自己修改后的su.c

2.把共享应用程序的UserId.

Root 手机?

其实就是修改系统的/system/bin/su 文件

应用获得Root 权限

Root 之前,只有Root 用户才能以超级管理员的权限运行应用程序,看su.c 的代码:

if (myuid != AID_ROOT && myuid != AID_SHELL) {
        fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
        return 1;
    }
    
if(setgid(gid) || setuid(uid)) {
        fprintf(stderr,"su: permission denied\n");
        return 1;
    }

NAME

setuid - set user ID
SYNOPSIS

#include <unistd.h>

int setuid(uid_t uid);

DESCRIPTION

If the process has appropriate privileges, setuid() shall set the real user ID, effective user ID, and the saved set-user-ID of the calling process to uid.

If the process does not have appropriate privileges, but uid is equal to the real user ID or the saved set-user-ID, setuid() shall set the effective user ID to uid; the real user ID and saved set-user-ID shall remain unchanged.

The setuid() function shall not affect the supplementary group list in any way.

RETURN VALUE

Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.

ERRORS

The setuid() function shall fail, return -1, and set errno to the corresponding value if one or more of the following are true:

[EINVAL]
The value of the uid argument is invalid and not supported by the implementation.
[EPERM]
The process does not have appropriate privileges and uid does not match the real user ID or the saved set-user-ID.


Root 之后,使用SuperUser 管理系统的Root 权限,SuperUser 有一个白名单,白名单中都是允许以使用超级管理员的用户。

if (!checkWhitelist())
	{
		char sysCmd[1024];
		sprintf(sysCmd, "am start -a android.intent.action.MAIN -n com.koushikdutta.superuser/com.koushikdutta.superuser.SuperuserRequestActivity --ei uid %d --ei pid %d > /dev/null", g_puid, ppid);
		if (system(sysCmd))
			return executionFailure("am.");

		int found = 0;
		int i;
		for (i = 0; i < 10; i++)
		{
			sleep(1);
			// 0 means waiting for user input
			// > 0 means yes/always
			// < 0 means no
			int checkResult = checkWhitelist();
			if (checkResult > 0)
			{
				found = 1;
				break;
			}
			else if (checkResult < 0)
			{
				// user hit no
				return permissionDenied();
			}
		}


Root 之后,自己写一个程序,替换系统的su.c 文件,当其他应用程序想以 Root 用户的身份运行程序时,都放行。


看完之后可以试着回答下面几个问题:

1,Root 是什么?

2,Android 手机Root 的原理?

3,什么是SuperUser ?

4,su.c 的作用?

5,setUid() 和setGid() 的左右?


su 源代码 下载地址:http://download.csdn.net/detail/jinzhu117/4821630

SuperUser 源代码下载地址:http://download.csdn.net/detail/jinzhu117/4821569



评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值