chroot() - not able to "create" a jail
hello,
I read a text about 'chroot', now I wanted to try it, with "chroot /home/user", but I got that /bin/bash couldn't be found, I read that /bin/(ba)sh is default, when you do not type in your Command. Everything was executed as root, can you help me ? I want to "create" a jail, for testing. I know that it is no real security, but I just wanted to test it. --TOL-- |
A chroot makes any dir you mention the "root" for apps operating in a chroot. They can't see outside of it, so if any libs, devices and files are needed you need to put 'em in the chrooted directory. Library dependancies you can figure out by using "ldd" on apps. Devices and files you can figure out by using "strace" on an app. Make sure you don't provide access to /proc devices (kmem anyone?), suid apps it doesn't really need and provide only stripped down versions of /etc/passwd where needed.
Also try the Jail Chroot Project, it's what I've been using, makes the setup easier, then I tweak it. It's got all the chroot docs on one page, but here's some more chroot docs if you feel an RTM vibe coming on: How to set up... (ok, it's RH but that's besides the point), Using Chroot Securely, the insane Chrooting All Services in Linux (cached doc, couldnt find it elsewhere) and for good measure How to break out of a chroot() jail. Patching your kernel with the GRSecurity patch assures for instance a "chdir" has been done before the actual "chroot", plus it features some more chroot stuff. |
thanks, I'm reading some of the texts.
So, my command typed in is/was nonsense , as only the programs are in "jail" ??? Is it right that f.e. ftp uses chroot() to prevent the user logging in, from "having a look" on the whole system ? Sorry for these Newbie-Questions --TOL-- |
Is it right that f.e. ftp uses chroot() to prevent the user logging in, from "having a look" on the whole system ?
Yes, but some ftpd's are more vulnerable than others in their implementation of chroot, due to either spaghetti code or some trade-off between functionality (f.i. following symlinks outside a chroot, administrators w/o chroot) and security. Have a look at the changes/docs/code for Vsftpd, Muddleftpd (and Proftpd IIRC) for instance, they are considered quite secure. |
thank you very much,
just to make sure that i understood it right , was my first statement (So, my command typed in is/was nonsense , as only the programs are in "jail" ???) right ? thanks again |
Aw well, the "chroot <somedir>" part wasn't wrong, even what came after that wasn't wrong, you just didn't know you should copy the right stuff over.
|
ok, after I read your posting I thought I understood it.
I tried it again , and created a directory /bin in my directory i want to chroot: $ pwd /home/user $mkdir bin $cp /bin/bash /home/user/bin I also copied ls...in /home/user/bin . Then I tried $chroot /home/user/ Again an error message occured, telling me that he could not execute /bin/bash , as he couldn't find it. I also copied bash...in /home/user, but that was no profit |
Ok. I'll give you an example then:
#!/bin/bash # mkchrootStupidExample.sh # Our basedir is /var/jail/test, # we gonna create some subdirs we need: for d in /bin /etc /lib/i686; do echo "mkdir -p /var/jail/test$d"; done # Since we're in examplemode let's just copy in bash, # get the deps from doing "ldd /bin/bash" and # an idea of files it opens by doing # "strace -qf -eopen -o /tmp/strace.log /bin/bash" cp /bin/bash /var/jail/test/bin for f in /lib/libtermcap.so.2 /lib/libdl.so.2 /lib/ld-linux.so.2; do cp $f /var/jail/test/lib; done cp /lib/i686/libc.so.6 /var/jail/test/lib/i686 cp /etc/profile /var/jail/test/etc chroot /var/jail/test #done |
All times are GMT -5. The time now is 03:34 PM. |