转adb Shell root 权限
永久root带文件
因为开发需要,我经常会用到adb这个工具(Android Debug Bridge),我们都知道adb shell默认是没有root权限的,修改系统文件就很不方便了,adb push一个文件就提示Permission Denied。删除system下的文件也没有权限。其实有两种方法可以获取adb shell的root权限,这两种方法的前提都是手机已经root。 1、用su可以提权,直接执行su就会看到用户命令提示符由”$”变成了”#”,如果手机没有root,会提示su: Permission Denied。这个文件不是每个手机都有的,可以百度。 解压后把su放在adb同一目录下,执行:
adb push su /system/bin/adb shell chmod4755/system/bin/su
如果提示Read-only filesystem,那么就要重新挂载一下/system,把只读挂载成可读写,只有手机root了才能运行:
mount -o remount,rw/dev/block/mtdblock0/system /
再运行su就能让adb shell获取root权限了。 2、可以修改根目录下的default.prop提权: 根目录默认是不允许修改的,执行
mount -o remount,rw rootfs/
用vi打开default.prop,找到ro.secure,修改为ro.secure=0,保存后重启,再adb shell一下,就会有root权限了。 方法:
修改./default.prop
把ro.secure设为0,persist.service.adb.enable设为1,adbd进程就会以root用户的身份启动。
其实两篇文章大体效果不同,这个是完全破除限制,下文只是部分 至于文中所提到的su文件,是指被修改过的,无任何验证的,这样安全性大大降低,推荐完整root前,先备份原su文件。
原理:
可以看一下Android系统根目录下的/init.rc的片段:
... ...
# adbd is controlled by the persist.service.adb.enable system property
service adbd /sbin/adbd
disabled
# adbd on at boot in emulator
on property:ro.kernel.qemu=1
start adbd
on property:persist.service.adb.enable=1
start adbd
on property:persist.service.adb.enable=0
stop adbd
... ...
这里定义了一个触发器,只要persist.service.adb.enable值被置为1,就会启动/sbin/adbd。
在build目录下搜索一下,发现了main.mk中有这样的代码片段
## user/userdebug ##
user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))
enable_target_debugging := true
ifneq (,$(user_variant))
# Target is secure in user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
tags_to_install := user
ifeq ($(user_variant),userdebug)
# Pick up some extra useful tools
tags_to_install += debug
else
# Disable debugging in plain user builds.
enable_target_debugging :=
endif
# TODO: Always set WITH_DEXPREOPT (for user builds) once it works on OSX.
# Also, remove the corresponding block in config/product_config.make.
ifeq ($(HOST_OS)-$(WITH_DEXPREOPT_buildbot),linux-true)
WITH_DEXPREOPT := true
endif
# Disallow mock locations by default for user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
else # !user_variant
# Turn on checkjni for non-user builds.
ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
# Set device insecure for non-user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
# Allow mock locations by default for non user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
endif # !user_variant
ifeq (true,$(strip $(enable_target_debugging)))
# Target is more debuggable and adbd is on by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
# Include the debugging/testing OTA keys in this build.
INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging
# Target is less debuggable and adbd is off by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
endif # !enable_target_debugging
这段代码我大致解释一下:
主要通过判断当前的编译模式来给几个属性赋予不同的值,然后把属性存储在ADDITIONAL_DEFAULT_PROPERTIES这个变量中,这个变量在后面是要写到根目录下的/default.prop中去,在系统启动时被属性服务加载的。也就是说我们在/default.prop中看到的几个属性的值是在这里设置的。
只看两个属性ro.secure,persist.service.adb.enable。当前是user模式的话,编译系统会把ro.secure置为1,把persist.service.adb.enable置为0.也就是说,用user模式编译出来的系统运行在安全模式下,adbd默认关闭。即使通过设置属性的方式打开,adbd进程的用户也是shell,不具有root权限。这样,普通用户或者开发者拿到一个机器后,通过PC运行adb shell时,是以shell用户登录机器的。
好了,现在把ro.secure置为0,再重新编译,只要设置属性persist.service.adb.enable的值为1,adbd进程就会以root用户的身份启动。
转adb Shell root 权限的更多相关文章
- user版本如何永久性开启adb 的root权限【转】
本文转载自:http://blog.csdn.net/o0daxu0o/article/details/52933926 [Solution]* adb 的root 权限是在system/core/a ...
- Android 如何永久性开启adb 的root权限【转】
本文转载自:https://www.2cto.com/kf/201702/593999.html adb 的root 权限是在system/core/adb/adb.c 中控制.主要根据ro.secu ...
- adb shell root
因为开发需要,我经常会用到adb这个工具(Android Debug Bridge),我们都知道adb shell默认是没有root权限的,修改系统文件就很不方便了,adb push一个文件就提示Pe ...
- android apk 的root 权限和USB adb 权限的差别
USB adb 权限是指,当adb 连接手机时,手机中的守护进程adbd 的权限为root 权限,从而它的子进程也具有root 权限.通常假设adb shell 看到是: Android 4.0 以后 ...
- Android之通过adb shell 模拟器 error: more than one device and emulator 改ip dns
error: more than one device and emulator 如果出现上面那种情况 请关闭 ide 输入下面的 再次重新启动 模拟器 如果实际上只有一个设备或模拟器,并且查到有 ...
- adb shell top 命令
原文地址https://blog.csdn.net/kittyboy0001/article/details/38562515 原文地址https://blog.csdn.net/u010503912 ...
- appium+python自动化-adb shell模拟点击事件(input tap)
前言 appium有时候定位一个元素很难定位到,或者说明明定位到这个元素了,却无法点击,这个时候该怎么办呢? 求助大神是没用的,点击不了就是点击不了,appium不是万能的,这个时候应该转换思路,换其 ...
- 使用adb shell 进入手机修改文件的权限
1.将android的tools目录加入到path中,或者直接在adb.exe路径下启动cmd窗口2.adb shell 进入手机后,发现是 $ ,不是 # 号3.在进入shell后运行 su ,就可 ...
- ADB工具 获取ROOT权限及复制文件方法
adb push d:\tm3_sqlit.db data/zouhao/tm3_sqlit.dbadb pull data/zouhao/tm3_sqlit.db d:\tm3_sqlit.db a ...
随机推荐
- DP 题集 1
关于 DP 的一些题目 参考资料 [Tutorial] Non-trivial DP Tricks and Techniques DP Rain and Umbrellas Mr. Kitayuta, ...
- 【JAVAWEB学习笔记】网上商城实战4:订单模块
今日任务 完成订单模块的功能 1.1 订单 模块的功能 1.1.1 我的订单: [我的订单的查询] * 在header.jsp中点击我的订单. * 提交到Servlet: * 获得用户 ...
- 【搜索】还是N皇后
先看题才是最重要的: 这道题有点难理解,毕竟Code speaks louder than words,所以先亮代码后说话: #include<iostream> using namesp ...
- Vue 2.0学习(一)简介
简介 Vue是一套用于构建用户界面的渐进式框架.简单小巧( 压缩后仅17KB),Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件.它不仅易于上手,还便于与第三方库或既 ...
- 数据仓库之父——Bill Inmon(转载)
从此处转载 http://blog.sina.com.cn/s/blog_615f9dba0100f67p.html 比尔·恩门(Bill Inmon),被称为数据仓库之父,最早的数据仓库概念提出者, ...
- 较有意思的Apple XSS(CVE-2016-7762)漏洞
文章作者:Avfisher0x00 前言应CVE作者的要求帮忙分析一下这个漏洞,实际上这是一个思路比较有意思的Apple XSS(CVE-2016-7762).漏洞作者确实脑洞比较大也善于尝试和发掘, ...
- [CodeForces-332E]Binary Key
题目大意: 给你两个字符串p和s,让你求出一个字典序尽量小的长度为k的01串密钥,能将p转化为s. 密钥的工作方式如下: 第i位是0,表示这一位无用: 第i位是1,表示这一位有用. 若密钥的长度比s短 ...
- Android消息机制——Handler
/**android的消息处理有三个核心类:Looper,Handler和Message.其实还有一个MessageQueue(消息队列), * 但是MessageQueue被封装到Looper里 ...
- HDU 5293 Annoying problem 树形dp dfs序 树状数组 lca
Annoying problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 Description Coco has a tree, w ...
- [原]Redis使用场景及使用经验
Redis is an open source (BSD licensed), in-memory data structure store! 欢迎转载,转载请注明出处 刚刚结束一个游戏类的活动项目, ...