• Android7.1 ROOT权限的获取


    修改文件:

    system/extras/su/su.c

    system/core/include/private/android_filesystem_config.h

    system/core/libcutils/fs_config.c

    frameworks/base/core/jni/com_android_internal_os_Zygote.cpp

    frameworks/base/cmds/app_process/app_main.cpp

    device/qcom/msm8909/BoardConfig.mk

    目的:为了在应用层App中可以通过调用su来获取root权限,进而执行一些命令。

    system/extras/su/su.c

    在“main”函数中,注释掉uid的验证条件:

    1. //uid_t current_uid = getuid();
    2. //if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");

    system/core/libcutils/fs_config.c

    修改su程序的权限配置相关的内容:

    1. /* the following two files are INTENTIONALLY set-uid, but they
    2. * are NOT included on user builds. */
    3. { 06755, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },

    /system/core/init/init.cpp

    直接return false

    1. static bool selinux_is_enforcing(void)
    2. {
    3. return false;
    4. if (ALLOW_PERMISSIVE_SELINUX) {
    5. return selinux_status_from_cmdline() == SELINUX_ENFORCING;
    6. }
    7. return true;
    8. }

    /system/core/adb/daemon/main.cpp

    should_drop_privileges直接return false

    1. static bool should_drop_privileges() {
    2. return false;
    3. // "adb root" not allowed, always drop privileges.
    4. if (!ALLOW_ADBD_ROOT && !is_device_unlocked()) return true;
    5. // The properties that affect `adb root` and `adb unroot` are ro.secure and
    6. // ro.debuggable. In this context the names don't make the expected behavior
    7. // particularly obvious.
    8. //
    9. // ro.debuggable:
    10. // Allowed to become root, but not necessarily the default. Set to 1 on
    11. // eng and userdebug builds.
    12. //
    13. // ro.secure:
    14. // Drop privileges by default. Set to 1 on userdebug and user builds.
    15. bool ro_secure = android::base::GetBoolProperty("ro.secure", true);
    16. bool ro_debuggable = __android_log_is_debuggable();
    17. // Drop privileges if ro.secure is set...
    18. bool drop = ro_secure;
    19. // ... except "adb root" lets you keep privileges in a debuggable build.
    20. std::string prop = android::base::GetProperty("service.adb.root", "");
    21. bool adb_root = (prop == "1");
    22. bool adb_unroot = (prop == "0");
    23. if (ro_debuggable && adb_root) {
    24. drop = false;
    25. }
    26. // ... and "adb unroot" lets you explicitly drop privileges.
    27. if (adb_unroot) {
    28. drop = true;
    29. }
    30. return drop;
    31. }

    frameworks/base/core/jni/com_android_internal_os_Zygote.cpp

    注释掉如下内容:

    1. static void DropCapabilitiesBoundingSet(JNIEnv* env) {
    2. /*
    3. for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {
    4. int rc = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
    5. if (rc == -1) {
    6. if (errno == EINVAL) {
    7. ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
    8. "your kernel is compiled with file capabilities support");
    9. } else {
    10. RuntimeAbort(env, __LINE__, "prctl(PR_CAPBSET_DROP) failed");
    11. }
    12. }
    13. }
    14. */
    15. }

    frameworks/base/cmds/app_process/app_main.cpp

    注释“main”函数中的如下内容:

    1. /*
    2. if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
    3. // Older kernels don't understand PR_SET_NO_NEW_PRIVS and return
    4. // EINVAL. Don't die on such kernels.
    5. if (errno != EINVAL) {
    6. LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno));
    7. return 12;
    8. }
    9. }
    10. */

    device/qcom/msm8909/BoardConfig.mk

    在启动参数“BOARD_KERNEL_CMDLINE”中加入对SELinux的设置“androidboot.selinux=permissive”,放宽权限:

    BOARD_KERNEL_CMDLINE := console=ttyHSL0,115200,n8 androidboot.selinux=permissive androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 earlyprintk

    或者

    BOARD_KERNEL_CMDLINE := androidboot.selinux=permissive

    添加px30-android.dts

    androidboot.selinux=permissive

    1. chosen: chosen {
    2. bootargs = "earlycon=uart8250,mmio32,0xff160000 swiotlb=1 console=ttyFIQ0 androidboot.baseband=N/A androidboot.selinux=permissive androidboot.veritymode=enforcing androidboot.hardware=rk30board androidboot.console=ttyFIQ0 init=/init kpti=0";
    3. };

  • 相关阅读:
    使用Docker快速连接远程Mysql
    【论文阅读】(2023TPAMI)PCRLv2
    2023年第一批次申请考核制博士网上报名相关通知
    【opencv】Opencv中数据类型CV_8U, CV_16U, CV_16S, CV_32F、CV_64F
    2022-07-30 mysql8执行慢SQL[Q17]分析
    Weblogic漏洞 CVE-2021-2109 处理
    SQL注入绕过safedog原理分析(二)
    文心一言 VS 讯飞星火 VS chatgpt (97)-- 算法导论9.3 3题
    C++ Reference: Standard C++ Library reference: Containers: deque: deque: cbegin
    升级降级苹果手机iOS系统工具iMazing2024
  • 原文地址:https://blog.csdn.net/u010823818/article/details/132846557