Android root的两种方法-udev漏洞和setuid漏洞

本文深入探讨了针对Android设备的两个关键漏洞利用攻击:init进程的udev和adbd进程的setuid。通过分析源代码,解释了如何利用这些漏洞实现root权限。包括对RageAgainstTheCage程序的描述及其针对udev的攻击方法,以及adb setuid漏洞的利用过程。
AI助手已提取文章相关产品:
转载自:http://intrepidusgroup.com/insight/2010/09/android-root-source-code-looking-at-the-c-skills/


Root Andoid现在主要是依靠两个漏洞:init进程的udev和adbd进程的setuid,下面是详细描述。之前的文章提到的rageagainstthecage这个程序利用的是setuid这个漏洞。


这两个漏洞的攻击程序源码在这里:/Files/super119/RageAgainstTheCage.zip



This is a bit of a follow up to our previous post, but we thought it would be interesting to dissect the source code of two of the recent Android root attacks: the udev exploit and the adb setuid exhaustion attack. The c-skillz site has posted the code for both exploits in the downloads available from their site. As they state, these attacks work basically against all Android phones released to date (and probably future ones if they run Android 2.1 or 2.2).

The udev exploit gained attention as one of the first attacks used against the Droid X, but was posted on the c-skillz site about a week before it made a great deal of noise on other blogs and forums. The download also included a README file which points out this attack mainly follows the exploit reported against udev and patched in 2009. Here’s a link to the CVE it points out: CVE-2009-1185.

Android does not have a separate udev executable and process link on standard Linux deployments. However, large portions of the udev code have been moved into the init daemon (init, like on a standard Linux system, is typically the first userland process and runs as root). In a simplistic and brief nutshell, udev offers dynamic management of devices; notably, it allows standard users to “hotplug” devices that may require root level access, such as a USB device. The kernel will pass a message to the userland udev demon, which will in turn act on the message. The issue is that versions of udev before 1.4.1 did not verify if these messages actually came from the kernel. Thus, a rogue application can submit a message to udev and have an action executed (which in the case of Android, is the init process running as root). While the kernel will need to be updated to send credentials with its messages to udev, the userland udev/init process is really where this vulnerability exists. I had originally referred to this as a kernel exploit, but that would technically be incorrect.

So here’s a quick overview of the exploid.c code: when the application runs, it copies itself to the sqlite_stmt_journals directory (remember, we’re not root yet, so we need a directory the “shell” user can write to). It will then send a NETLINK_KOBJECT_UEVENT message to run the copy of itself when the next hotplug event is triggered. The copied version of the executable then check if it is being run as root (this is our userland udev/init process) and if so, remounts the system partition (which is normally mounted as a read-only partition) and dumps a copy of /system/bin/sh as /system/bin/rootshell with the permissions of 04711 (executable with the user ID bit set so it always runs as root).

[img]http://dl2.iteye.com/upload/attachment/0097/2985/11f01478-431d-374d-ab2b-0158d48a5308.png[/img]

Now lets look at the adb setuid exhaustion attack. Compiled, this typically has the name “rageagainstthecage” and the code refers to it has “CVE-2010-EASY” in one comment, but whatever you call it, it’s a pretty smooth way of getting adbd (android’s debugging bridge daemon) to run as root. First the code will check that there is an NPROC setting. This is the maximum number of simultaneous processes which the system will allow. A quick “ulimit -a” once connected over adb should show you this setting for your device (this is set to 3301 processes on a Droid Incredible). The code will then try to find the process ID of the currently running adb daemon on the device. After that, the attack starts a loop to generated processes until it can no longer fork any more processes. Once the limit is hit, one process is killed off and the adb daemon process is restarted. As the code comment points out, this is a bit of a race at this point to make sure the adb can restart, but the number of processes stays maxed out. When the adb daemon starts up on an Android device, it is running as root. The code will later check if it should stay as root, or run in “secure” mode which drops its privileges to the “shell” account. This attack attemps to max out the process so that when the adb daemon attempts to call “setuid” in its code, the call will fail. The current adb code does not check if the setuid call was successful or not, so will happily keep running as root even if this fails.


[img]http://dl2.iteye.com/upload/attachment/0097/2987/7a812487-6ff9-3454-b4d6-863db514eed5.png[/img]

您可能感兴趣的与本文相关内容

从你提供的 `ps` 输出来看,你的系统使用的是 **`hotplug2` + `udevtrigger`** 的热插拔机制,这是 **基于 `mdev` 或 `udev` 的热插拔兼容层**,常见于一些基于 **OpenWrt 改造或嵌入式 Linux** 的系统中(如某些 NVR、路由器、IoT 设备)。 --- ## ✅ 你的系统使用的是 `hotplug2`,它是: - 一个兼容 `udev` 风格规则的轻量级热插拔守护进程 - 可以执行 `/etc/hotplug.d/` 目录下的脚本 - 通常配合 `/etc/hotplug2.rules` 规则文件工作 --- ## 🧰 为什么你的热插拔脚本没执行? 你添加的 `echo` 到 `/etc/hotplug.d/iface/` 脚本没有输出,说明: ### ✅ 可能原因如下: | 原因 | 说明 | 检查方法 | |------|------|----------| | ❌ 热插拔事件未匹配规则 | `hotplug2.rules` 中没有匹配网络接口事件的规则 | 查看 `/etc/hotplug2.rules` | | ❌ 脚本权限或命名问题 | 脚本没有可执行权限或命名不符合规范 | `ls -l /etc/hotplug.d/iface/` | | ❌ 事件类型不匹配 | `hotplug2` 可能只监听了 `device add/remove`,而不是网络链路状态变化 | 使用 `ethtool` 或 `/dev/kmsg` 监听 | | ❌ 脚本路径错误 | 脚本放在了错误的目录(如 `net/` 而不是 `iface/`) | 确认路径是否正确 | --- ## 🛠️ 排查步骤 ### ✅ 1. 检查 `/etc/hotplug.d/iface/` 下的脚本是否可执行 ```bash ls -l /etc/hotplug.d/iface/ ``` 确保脚本有执行权限: ```bash chmod +x /etc/hotplug.d/iface/your_script ``` --- ### ✅ 2. 查看 `/etc/hotplug2.rules` 是否包含网络接口规则 ```bash cat /etc/hotplug2.rules ``` 看看是否有类似以下规则: ```bash SUBSYSTEM == "net", ACTION == "add", RUN += "/sbin/hotplug-call iface" SUBSYSTEM == "net", ACTION == "remove", RUN += "/sbin/hotplug-call iface" ``` 如果没有这些规则,那么 `hotplug2` 不会为网络接口调用 `/etc/hotplug.d/iface/` 脚本。 --- ### ✅ 3. 手动测试脚本是否有效 ```bash sh /etc/hotplug.d/iface/20-auto_down_wan ``` 如果能输出 `echo` 内容,说明脚本没问题,只是没有被触发。 --- ### ✅ 4. 使用 `strace` 追踪 `hotplug2` 是否调用脚本(高级) ```bash strace -p 1706 ``` 观察是否调用了 `/etc/hotplug.d/iface/` 下的脚本。 --- ### ✅ 5. 手动发送热插拔事件测试 你可以尝试手动发送一个热插拔事件来测试: ```bash echo 'ACTION="add" SUBSYSTEM="net" INTERFACE="eth0"' > /proc/sys/kernel/hotplug ``` 或者: ```bash echo 'ACTION="remove" SUBSYSTEM="net" INTERFACE="eth0"' > /proc/sys/kernel/hotplug ``` 然后查看你的脚本是否执行。 --- ## 🧩 替代方案:监听网络链路状态变化(不依赖热插拔机制) ### ✅ 方法一:使用 `ethtool` 轮询链路状态变化 ```bash INTERFACE="eth0" while true; do LINK_STATUS=$(ethtool $INTERFACE | grep "Link detected:" | awk '{print $3}') if [ "$LINK_STATUS" = "yes" ]; then echo "[$(date)] Cable plugged in" else echo "[$(date)] Cable unplugged" fi sleep 1 done ``` --- ### ✅ 方法二:监听 `/dev/kmsg` 获取内核 uevent ```bash while read line < /dev/kmsg; do if echo "$line" | grep -q 'SUBSYSTEM=net'; then echo "Netlink event: $line" if echo "$line" | grep -q 'ACTION=remove'; then echo "[$(date)] Device removed (cable unplugged)" elif echo "$line" | grep -q 'ACTION=add'; then echo "[$(date)] Device added (cable plugged in)" fi fi done ``` --- ## 🎯 总结:你应该怎么做? | 问题 | 原因 | 解决方案 | |------|------|----------| | ❌ 热插拔脚本未执行 | `hotplug2` 没有为网络接口调用脚本 | 检查 `/etc/hotplug2.rules` | | ❌ 系统不是标准 OpenWrt | `hotplug.d` 机制可能受限 | 使用替代监听方式(如 `ethtool`、`/dev/kmsg`) | | ✅ 替代监听方式 | 推荐使用 `ethtool` 轮询 | 稳定、兼容性强 | --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值