Advertisement
Guest User

andrewdre

a guest
Jul 25th, 2023
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | Software | 0 0
  1. #include <iostream>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <sys/mount.h>
  5. #include <sys/wait.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     if (unshare(CLONE_NEWNS|CLONE_NEWCGROUP|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWPID) == -1){
  12.         perror("unshare");
  13.         exit(1);
  14.     }
  15.     int namespace_fd = open("/var/run/netns/chromium_netns", O_RDONLY|O_CLOEXEC);
  16.     if ((namespace_fd) == -1){
  17.         perror("open");
  18.         exit(1);
  19.     }
  20.     if (setns(namespace_fd, CLONE_NEWNET) == -1){
  21.         perror("setns");
  22.         exit(1);
  23.     }
  24.     if (close(namespace_fd) == -1){
  25.         perror("close");
  26.         exit(1);
  27.     }
  28.    
  29.     int pid = fork();
  30.     if (pid != 0) {
  31.         if (setresuid(-1, 1001, 1001) == -1){
  32.             perror("setresuid");
  33.             exit(1);
  34.         }
  35.         int status;
  36.         if (waitpid(-1, &status, 0) == -1){
  37.             perror("waitpid");
  38.             exit(1);
  39.         }
  40.         return status;
  41.     }
  42.  
  43.     if (mount("none", "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
  44.         perror("mount");
  45.         exit(1);
  46.     }
  47.     if (chroot("/path/to/new/root/") == -1){
  48.         perror("chroot");
  49.         exit(1);
  50.     }
  51.     if (chdir("/") == -1){
  52.         perror("chdir");
  53.         exit(1);
  54.     }
  55.     if (mount("proc", "/proc", "proc", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL) == -1) {
  56.         perror("mount");
  57.         exit(1);
  58.     }
  59.  
  60.     if (setresuid(-1, 1001, 1001) == -1){
  61.         perror("setresuid");
  62.         exit(1);
  63.     }
  64.  
  65.     if (execlp("/bin/bash", "/bin/bash", NULL) == -1){
  66.         perror("execlp");
  67.         exit(1);
  68.     }
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement