cifz
cifz

Reputation: 1078

How to execute linux command in a chroot jail

I need to code a jailed command executor and it needs to execute linux command, I've tried copying /bin to my new root, but system() (e.g. system("ls")) still doesn't work. I've read about copying libraries, however there are any other ways to execute linux command that doesn't involve copying stuff ?

Moreover (and maybe more important), there is a way for a jailed process that's not root to execute linux command ?

Thanks, any help is appreciated

Upvotes: 0

Views: 835

Answers (1)

caf
caf

Reputation: 239191

Either the binaries you copy in to your chroot environment must be statically linked, or you need to copy in the necessary shared libraries as well (/lib / /usr/lib).

Non-root processes can execute in a chroot environment just as root processes can, but only root processes can call chroot() so you will need to have a root process set up the chroot environment and then switch to the unprivileged user id.

Upvotes: 1

Related Questions