开放系统root权限

From:http://blog.chinaunix.net/uid-12845622-id-3063276.html

开放系统root权限,即使任何用户都可以执行su程序,以使得临时用户也具有了root的权限,然后去进行一些系统级的设置,如设置IP地址,DNS等。


1、修改su程序对临时用户的限制,默认su只允许root和shell用户执行
vi system/extras/su/su.c
注释掉语句块


1./*

2.myuid = getuid();

3.if (myuid != AID_ROOT && myuid != AID_SHELL) {

4.fprintf(stderr,"su: uid %d not allowed to su\n", myuid);

5.return 1;

6.}

7.*/

就安全性而言这种方式是不太可取的,因此才有了类似于superuser.apk的出现,它们的作用就是在外面再提供一层保护。




2、修改su程序的suid,可以通过ls -l来查看,在system/core/rootdir/init.rc中添加语句
chmod 4755 /system/xbin/su




3、如果涉及到/data目录而非/data/data/<你的包名>/的修改,则修改system/core/rootdir/init.rc
将 mount yaffs2 mtd@userdata /data nosuid nodev 改为 mount yaffs2 mtd@userdata /data nodev




4、通过java app进行验证


1.package com.test;

2.

3.import java.io.DataOutputStream;

4.import java.io.IOException;

5.

6.import android.app.Activity;

7.import android.os.Bundle;

8.import android.util.Log;

9.

10.public class TestActivity extends Activity {

11./** Called when the activity is first created. */

12.@Override

13.public void onCreate(Bundle savedInstanceState) {

14.super.onCreate(savedInstanceState);

15.setContentView(R.layout.main);

16.try {

17.Process process = Runtime.getRuntime().exec("su");//(这里执行是系统已经开放了root权限,而不是说通过执行这句来获得root权限)

18.DataOutputStream os = new DataOutputStream(process.getOutputStream());

19.os.writeBytes("ifconfig eth0 192.168.18.122\n");

20.os.writeBytes("exit\n");

21.os.flush();

22.} catch (IOException e) {

23.e.printStackTrace();

24.}

25.}

26.}


Reference
1、http://android-dls.com/wiki/index.php?title=Magic_Root_Access
2、https://github.com/git-core/su-binary/wiki
3、http://my.unix-center.net/~Simon_fu/?p=1069

猜你喜欢

转载自sunj.iteye.com/blog/1912776