Skip to content

Instantly share code, notes, and snippets.

@kgadek
Created July 21, 2014 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgadek/11895058c1c7405275c8 to your computer and use it in GitHub Desktop.
Save kgadek/11895058c1c7405275c8 to your computer and use it in GitHub Desktop.
Chrooter
#include <stdio.h>
#include <unistd.h>
const char newroot[] = "/home/buildbot_flowbox/jail-" JAIL_NAME;
const char cmd[] = "/bin/bash";
char *args[2] = {"--init-file", "/home/buildbot_flowbox/initfile-jail-" JAIL_NAME};
int main(int c, char **v, char **e) {
int rc; const char *m;
if ( (m = "chdir" ,rc = chdir(newroot) ) == 0
&& (m = "chroot",rc = chroot(newroot) ) == 0
&& (m = "setuid",rc = setuid(getuid())) == 0 )
m="execve", execve(cmd,args,e);
perror(m);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment