当前位置: 首页 > news >正文

Android11 关于三方应用获取su权限

客户的apk运行报错Cannot run program "su": error=13, Permission denied,查看报错日志,发现是客户apk想使用su命令提权,但是没有权限!
系统这边做修改,让su权限下放到三方应用.

userdebug版本,
adb shell getenforce 为Permissive(宽容模式)

修改之前:/ $ ls -al system/xbin/su
-rwsr-x--- 1 root shell 11192 2024-08-07 01:31 system/xbin/su修改之后:/ $ ls -al system/xbin/su
-rwsr-sr-x 1 root shell 11632 2024-08-02 08:48 system/xbin/sur 只读
w 只写
x 只执行RK Android 11:关闭selinux 
+++ b/device/rockchip/common/BoardConfig.mk
@@ -59,7 +59,7 @@ BOARD_BOOT_HEADER_VERSION ?= 2BOARD_MKBOOTIMG_ARGS :=
-BOARD_SELINUX_ENFORCING ?= true
+BOARD_SELINUX_ENFORCING ?= falseAndroid 13:关闭selinux bool IsEnforcing() {return false;// if (ALLOW_PERMISSIVE_SELINUX) {//     return StatusFromProperty() == SELINUX_ENFORCING;// }// return true;
}Android 13 diff
+++ b/system/core/libcutils/fs_config.cpp
@@ -86,7 +86,7 @@ static const struct fs_path_config android_dirs[] = {{ 00751, AID_ROOT,         AID_SHELL,        0, "system/bin" },{ 00755, AID_ROOT,         AID_ROOT,         0, "system/etc/ppp" },{ 00755, AID_ROOT,         AID_SHELL,        0, "system/vendor" },
-    { 00750, AID_ROOT,         AID_SHELL,        0, "system/xbin" },
+    { 00751, AID_ROOT,         AID_SHELL,        0, "system/xbin" },//update text { 00751, AID_ROOT,         AID_SHELL,        0, "system/apex/*/bin" },{ 00751, AID_ROOT,         AID_SHELL,        0, "system_ext/bin" },{ 00751, AID_ROOT,         AID_SHELL,        0, "system_ext/apex/*/bin" },
@@ -190,7 +190,7 @@ static const struct fs_path_config android_files[] = {// the following two files are INTENTIONALLY set-uid, but they// are NOT included on user builds.{ 06755, AID_ROOT,      AID_ROOT,      0, "system/xbin/procmem" },
-    { 04750, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },
+    { 06755, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },//update text

SELinux,全称Security-Enhanced Linux,是一种基于Linux内核的安全机制。它通过强制访问控制(MAC)来增强Linux系统的安全性,
对于保护系统资源和防止未经授权访问非常有帮助!
如果不禁用SELinux,完成下面的修改可能会导致设备进入Recovery界面!(这是关键!)

Android14之禁掉Selinux的两种方式(一百七十四)
Android 13 aosp 默认关闭SELinux

修改文件清单

frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
kernel/security/commoncap.c
system/core/libcutils/fs_config.cpp
system/extras/su/su.cpp

diff

+++ b/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
@@ -658,7 +658,7 @@ static void EnableKeepCapabilities(fail_fn_t fail_fn) {}static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) {
-  for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {;
+  /*for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {;if (prctl(PR_CAPBSET_DROP, i, 0, 0, 0) == -1) {if (errno == EINVAL) {ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
@@ -667,7 +667,7 @@ static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) {fail_fn(CREATE_ERROR("prctl(PR_CAPBSET_DROP, %d) failed: %s", i, strerror(errno)));}}
-  }
+  }*/}+++ b/system/core/libcutils/fs_config.cpp
@@ -190,7 +190,7 @@ static const struct fs_path_config android_files[] = {// the following two files are INTENTIONALLY set-uid, but they// are NOT included on user builds.{ 06755, AID_ROOT,      AID_ROOT,      0, "system/xbin/procmem" },
-    { 04750, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },
+    { 06755, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },// the following files have enhanced capabilities and ARE included// in user builds.+++ b/kernel/security/commoncap.c
static int cap_prctl_drop(unsigned long cap)
{struct cred *new;
+/*if (!ns_capable(current_user_ns(), CAP_SETPCAP))return -EPERM;if (!cap_valid(cap))return -EINVAL;
+*/new = prepare_creds();if (!new)return -ENOMEM;//对当前进程的uid 做一个鉴权,当不是 ROOT 或 SHELL 用户的时候直接抛异常,注释掉
+++ b/system/extras/su/su.cpp
@@ -80,8 +80,8 @@ void extract_uidgids(const char* uidgids, uid_t* uid, gid_t* gid, gid_t* gids, i}int main(int argc, char** argv) {
-    uid_t current_uid = getuid();
-    if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");
+    //uid_t current_uid = getuid();
+    //if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");// Handle -h and --help.++argv;

Android11、12 修改系统获取root权限(su权限)
Android11编译第六弹:user版本增加su+内置root用户

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 以Zed项目为例学习大型Rust项目的组织与管理
  • 数据结构----二叉树
  • Cairo库移植到安卓记录
  • 【登录扫码】--集成企业微信
  • todoList清单(HTML+CSS+JavaScript)
  • Linux中apache服务安装与mysql安装
  • git强制推送代码教程
  • 如何使用css写三角形
  • 操作系统(进程通信)
  • Spring 中的InitializingBean
  • C语言实现数据结构之队列
  • 基于GeoTools使用JavaFx进行矢量数据可视化实战
  • NoSQL之Redis配置与优化
  • 36集网剧《天降神医朱丹溪》电影《百草园里杏花香》在义乌启动
  • Java 并发编程:ReentrantLock 锁与 AQS
  • Brief introduction of how to 'Call, Apply and Bind'
  • CentOS7简单部署NFS
  • CSS居中完全指南——构建CSS居中决策树
  • CSS选择器——伪元素选择器之处理父元素高度及外边距溢出
  • isset在php5.6-和php7.0+的一些差异
  • java2019面试题北京
  • Java超时控制的实现
  • Just for fun——迅速写完快速排序
  • Node.js 新计划:使用 V8 snapshot 将启动速度提升 8 倍
  • PHP变量
  • Shadow DOM 内部构造及如何构建独立组件
  • Swoft 源码剖析 - 代码自动更新机制
  • Travix是如何部署应用程序到Kubernetes上的
  • Vue ES6 Jade Scss Webpack Gulp
  • 初识MongoDB分片
  • 搭建gitbook 和 访问权限认证
  • 基于HAProxy的高性能缓存服务器nuster
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 写代码的正确姿势
  • MiKTeX could not find the script engine ‘perl.exe‘ which is required to execute ‘latexmk‘.
  • 积累各种好的链接
  • ​业务双活的数据切换思路设计(下)
  • ## 临床数据 两两比较 加显著性boxplot加显著性
  • ### RabbitMQ五种工作模式:
  • #pragma data_seg 共享数据区(转)
  • #微信小程序:微信小程序常见的配置传旨
  • (2)(2.4) TerraRanger Tower/Tower EVO(360度)
  • (2024最新)CentOS 7上在线安装MySQL 5.7|喂饭级教程
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (Windows环境)FFMPEG编译,包含编译x264以及x265
  • (二)c52学习之旅-简单了解单片机
  • (附源码)ssm考试题库管理系统 毕业设计 069043
  • (每日一问)基础知识:堆与栈的区别
  • (十六)串口UART
  • (四)图像的%2线性拉伸
  • (小白学Java)Java简介和基本配置
  • (一)搭建springboot+vue前后端分离项目--前端vue搭建
  • (转)http-server应用
  • .net core webapi 大文件上传到wwwroot文件夹