Reputation: 1645
I have a problem with the execution of shell commands inside a chroot jail. Here is an exemple:
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
int main()
{
if (geteuid() == 0) // check root privileges
{
chroot("/bin");
chdir("/");
execl("/ls", "ls", "-l", (char *) NULL); // "/ls" should be equivalent to "/bin/ls"
perror(strerror(errno));
}
else
printf("Permission denied\n");
return 0;
}
The problem is the exec: according to errno, the error is "No such file or directory". The same error appears if I use exec("/bin/ls", ...)
I think that "ls" cannot use the shared libraries he needs, because of chroot jail.
Any suggestion to solve this problem?
Upvotes: 1
Views: 2081
Reputation: 66099
You're probably right regarding shared libraries being inaccessible. Setting up a chroot jail typically involves copying parts of /bin
, /usr/bin
, /lib
, and /usr/lib
into a parallel directory structure.
A simpler alternative is to use only statically linked executables. On many linux systems there will be a statically linked executable called busybox
that provides the base functionality of many Unix commands including ls
. Invoking it like busybox ls -l
provides similar output to the regular ls
program without needed to access addition shared libraries outside the chroot jail.
Upvotes: 1