Guest User

Untitled

a guest
Aug 23rd, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. /*
  2.  * fj-stub.c
  3.  *
  4.  * PUBLIC DOMAIN
  5.  *
  6.  * Create folders first:
  7.     sudo mkdir /tmp/firejail
  8.     sudo mkdir /tmp/firejail/mnt/oroot
  9.     sudo mkdir /tmp/firejail/mnt/odiff
  10.     sudo mkdir /tmp/firejail/mnt/owork
  11.  
  12.  * Compile:
  13.     gcc fj-stub.c -o fj-stub
  14.     sudo chown root fj-stub
  15.     sudo chgrp root fj-stub
  16.     sudo chmod u+s fj-stub
  17.  
  18.  * Confirm issue:
  19.     ./fj-stub
  20.     ls -la /home
  21.  
  22.  * NOTE: if /home is nosuid then copy the binary before chmod/confirm
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <sys/mount.h>
  28. #include <errno.h>
  29. #include <unistd.h>
  30.  
  31. int main(int argc, char **argv) {    
  32.    
  33.     if (setreuid(-1,0)<0){
  34.         fprintf(stderr, "Error: Unable to setuid root %i\n",errno);
  35.         return -1;
  36.     }
  37.    
  38.     if (mount("overlay", "/tmp/firejail/mnt/oroot/", "overlay", MS_MGC_VAL, "lowerdir=/,upperdir=/tmp/firejail/mnt/odiff/,workdir=/tmp/firejail/mnt/owork/") < 0){
  39.         printf("Failed overlay: %i\n",errno);
  40.         return -1;
  41.     }
  42.    
  43.     if (chroot("/tmp/firejail/mnt/oroot/") == -1){
  44.         printf("Failed chroot: %i\n",errno);
  45.         return -1;
  46.     }
  47.     system("/usr/bin/bash");
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment