设为首页 加入收藏

TOP

Adb分析及获取root权限 (二)
2014-11-23 17:41:22 来源: 作者: 【 】 浏览:57
Tags:Adb 分析 获取 root 权限
return 0;
} else {
return 1;
}
}

if(!strcmp(argv[0], "devices")) {
char *tmp;
snprintf(buf, sizeof buf, "host:%s", argv[0]); //命令格式为:host:devices
tmp = adb_query(buf); //发送命令并返回命令执行结果
if(tmp) {
printf("List of devices attached \n");
printf("%s\n", tmp); //打印结果
return 0;
} else {
return 1;
}
}2. 在adb_query()函数中调用adb_connect()函数发送socket数据,返回后再调用adb_close()关闭socket连接

下面再来分析目标机器即Android上的adbd守护进程,在刚才的入口函数中,它直接进入了adb_main()函数,并传入DEFAULT_ADB_PORT 5037作为默认端口。在adb_main()函数里进行了一系列初始化动作如,USB,端口监听,运行级别,权限设置等,最后进入到事件循环中等待连接(这儿使用epoll机制)。

[java]
fdevent_loop();

fdevent_loop();
其中我们对运行级别比较感兴趣,一般情况下我们的adb都是运行在shell用户下,而事实上,adb.c中的代码都是以root权限运行的,以完成部分初始化工作,直到执行了下面的代码:
[cpp]
if (should_drop_privileges()) {
......
if (setgid(AID_SHELL) != 0) {
exit(1); //这儿曾经是个漏洞,没有检查返回值,可以被某些恶意软件利用来破解root权限
}
if (setuid(AID_SHELL) != 0) {
exit(1);
}

if (should_drop_privileges()) {
......
if (setgid(AID_SHELL) != 0) {
exit(1); //这儿曾经是个漏洞,没有检查返回值,可以被某些恶意软件利用来破解root权限
}
if (setuid(AID_SHELL) != 0) {
exit(1);
}
它被强行将为shell用户,失去了root权限,那么它在什么情况下才被降级呢?我们看到是因为should_drop_privileges()函数,代码如下:
[cpp]
static int should_drop_privileges() {
#ifndef ALLOW_ADBD_ROOT
return 1;
#else /* ALLOW_ADBD_ROOT */
int secure = 0;
char value[PROPERTY_VALUE_MAX];

/* run adbd in secure mode if ro.secure is set and
** we are not in the emulator
*/
property_get("ro.kernel.qemu", value, "");
if (strcmp(value, "1") != 0) {
property_get("ro.secure", value, "1");
if (strcmp(value, "1") == 0) {
// don't run as root if ro.secure is set...
secure = 1;

// ... except we allow running as root in userdebug builds if the
// service.adb.root property has been set by the "adb root" command
property_get("ro.debuggable", value, "");
if (strcmp(value, "1") == 0) {
property_get("service.adb.root", value, "");
if (strcmp(value, "1") == 0) {
secure = 0;
}
}
}
}
return secure;
#endif /* ALLOW_ADBD_ROOT */
}

static int should_drop_privileges() {
#ifndef ALLOW_ADBD_ROOT
return 1;
#else /* ALLOW_ADBD_ROOT */
int secure = 0;
char value[PROPERTY_VALUE_MAX];

/* run adbd in secure mode if ro.secure is set and
** we are not in the emulator
*/
property_get("ro.kernel.qemu", value, "");
if (strcmp(value, "1") != 0) {
property_get("ro.secure", value, "1");
if (strcmp(value, "1") == 0) {
// don't run as root if ro.secure is set...
secure = 1;

// ... except we allow running as root in userdebug builds if the
// service.adb.root property has been set by the "adb root" command
property_get("ro.debuggable", value, "");
if (strcmp(value, "1") == 0) {
property_get("service.adb.root", value, "");
if (strcmp(value, "1") == 0) {
secure = 0;
}
}

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 4612 Warm up(边-双连通+缩点.. 下一篇HDU2089:不要62(数位DP)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 教程 - W3Sch (2025-12-26 12:00:51)
·Python基础教程,Pyt (2025-12-26 12:00:48)
·神仙级python入门教 (2025-12-26 12:00:46)
·“我用Java 8”已成 (2025-12-26 11:19:54)
·下载 IntelliJ IDEA (2025-12-26 11:19:52)