1
我在chroot jail中執行shell命令時遇到問題。這裏是一個例子:如何在chroot jail中執行shell命令
#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;
}
問題是exec:根據errno,錯誤是「沒有這樣的文件或目錄」。 如果我使用exec(「/ bin/ls」,...)會出現同樣的錯誤
我認爲由於chroot監獄,「ls」無法使用他需要的共享庫。
有沒有解決這個問題的建議?
在我的OpenBSD筆記本電腦上正常工作我正在輸入這個值,它的值是什麼,在哪裏運行「ldd/bin/ls」告訴我這是一個靜態可執行文件。如果你發現有需要的庫,你將不得不僞裝成在chroot下找到它們的方式。 – tbert 2012-07-06 20:13:50
它可能與位於/ usr/bin中的'ls'一樣簡單,並且只有符號鏈接/ bin。正如ataylor下面所說的,chroot想要一個真正的root環境,在它自己的/ lib,/ usr/lib和/ dev中的一些文件中有一些庫。 – 2012-07-06 20:39:03