LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-20-2002, 11:12 AM   #1
--TOL--
LQ Newbie
 
Registered: May 2002
Posts: 13

Rep: Reputation: 0
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--
 
Old 05-20-2002, 06:09 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.

Last edited by unSpawn; 05-20-2002 at 06:10 PM.
 
Old 05-21-2002, 10:53 PM   #3
--TOL--
LQ Newbie
 
Registered: May 2002
Posts: 13

Original Poster
Rep: Reputation: 0
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--
 
Old 05-22-2002, 05:40 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
 
Old 05-22-2002, 09:23 AM   #5
--TOL--
LQ Newbie
 
Registered: May 2002
Posts: 13

Original Poster
Rep: Reputation: 0
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
 
Old 05-22-2002, 09:39 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
 
Old 05-23-2002, 11:03 AM   #7
--TOL--
LQ Newbie
 
Registered: May 2002
Posts: 13

Original Poster
Rep: Reputation: 0
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
 
Old 05-23-2002, 11:29 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create a chroot jail netcrusher88 Linux - Security 3 08-07-2005 01:12 AM
chroot to md0 for "rescue" from live CD??? f1d094 Ubuntu 0 06-13-2005 07:38 AM
"cannot exec `as': ..." AND "C compiler cannot create ..." pr3st0 Linux - Software 0 10-15-2004 12:42 PM
serving website from inside chroot "Permissions" jeffpoulsen Linux - Security 1 07-01-2004 01:55 PM
Problem with "Jail Chroot Project 1.9" Agento- Linux - General 2 01-19-2003 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration