This is a practice lab. It is not graded. It is a jumping off point for exploring chroot jails.
The chroot command can be used to set an existing directory as the visible root for a process. All child processes of that process will inherit that chroot, confining them all to the specific directory tree. For anything to actually work under chroot, all the file resources that the processes running under the chroot will need must be present in that directory tree.
We will create a chroot space to run bash in where the ls command works, the tree command works, and bash builtin commands work, but nothing else is accessible.
mkdir ~/playspace
mkdir ~/playspace/bin
cp /bin/{ls,bash,tree} ~/playspace/bin
ldd ~/playspace/bin/{bash,ls,tree}
tar chf - /lib/x86_64-linux-gnu/{libtinfo.so.5,libdl.so.2,libc.so.6,libselinux.so.1,libpcre.so.3,libpthread.so.0} /lib64/ld-linux-x86-64.so.2 |
tar -C ~/playspace/ -xf -
sudo chroot ~/playspace/ /bin/bash
You are now in a shell that thinks the entire system consists only of what is under our playspace directory. You will notice you don’t have a custom prompt. That is because it would have come from bash environment files on bash process startup, but we didn’t provide those files in our jail. You can play with bash, ls, and tree (e.g. tree /
) but you will find it rather limited. Use exit
when you are tired of being in jail.
Some service programs are built with the ability to use chroot to limit the potential for misuse that can be incurred by users of the service. For this example, we will examine vsftpd, the Very Secure File Transfer Protocol daemon. It provides ftp services. It can allow local Linux user accounts to log into the ftp service using their Linux account username and password. Those users can then view, retrieve and upload files through ftp with the same access they would have when at the shell prompt. The vsftpd daemon has the ability to create a chrooted connection for these users, so that they can only work with files in their own home directory while connected to the ftp service.
ftp localhost
*login as user student*
ls /
bye
/etc/vsftpd.conf
file on the supplied VM. Look for the option chroot_local_user
.
vi /etc/vsftpd.conf
chroot_local_user
option) you construct and place in an auxiliary file. Also note that this file is world-readable. Do you think that is a good thing?sudo vi /etc/vsftpd.conf
systemctl restart vsftpd
bye
command. Change the user alice
’s home directory to be read-only, and login to the ftp service as user alice
(her password is bob
). See what she now sees for a root directory.
sudo chmod 555 ~alice
ftp localhost
*login as alice with password bob*
ls /
bye
sudo vi /etc/vsftpd.conf
systemctl restart vsftpd
sudo chmod 755 ~alice
So we can see that chroot for vsftpd provides a jail capability, but it has side effects, so it isn’t something we would just turn on for all users without considering the impacts. This is true for more or less all services that have chroot capabilities.