Bonjour,
je souhaite héberger les sites de quelques amis à titre gracieux Afin, de faire quelque chose de propre, je souhaite uniquement laisser un accès sftp/scp dans un chroot.
Voici un récapitulatif de mes actions :
Noyau grsecurity / OS /
$ uname -a
Linux kimsufi 2.6.39.1-last-grsec-xxxx-std-ipv6-64 #2 SMP Sat Jun 18 14:53:00 CEST 2011 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 6.0.2 (squeeze)
Release: 6.0.2
Codename: squeeze
$ aptitude search ssh | grep ^i
i A libssh2-1 - SSH2 client-side library
i A openssh-blacklist - list of default blacklisted OpenSSH RSA an
i A openssh-blacklist-extra - list of non-default blacklisted OpenSSH RS
i A openssh-client - Client shell (SSH), pour accèder de manièr
i A openssh-server - serveur shell sécurisé (SSH), pour accèder
i rssh - Restricted shell allowing scp, sftp, cvs,
i ssh - secure shell client and server (metapackag
Passons aux choses sérieuses, les confs :
/etc/ssh/sshd_config
$ cat /etc/ssh/sshd_config
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel DEBUG
LoginGraceTime 120
PermitRootLogin no
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding no
X11DisplayOffset 10
PrintMotd yes
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server -f LOCAL7 -l INFO
UsePAM yes
DebianBanner yes
/etc/rssh.conf
[code]$cat /etc/rssh.conf
set the log facility. “LOG_USER” and “user” are equivalent.
logfacility = LOG_USER
allowscp
allowsftp
#allowcvs
#allowrdist
#allowrsync
#allowsvnserve
umask = 022
#chrootpath = “/var/www/yoyo_www1 chroot”
user=testa:011:000110:/var/www/testa # sftp with chroot
[/code]
Création d’un utilisateur avec son home et le shell qui va bien
$ useradd --base-dir=/var/www/testa --shell=/usr/bin/rssh --password=test testa
$ cd /var/www
$ mkdir testa
$ chown testa:testa testa/
$ ls -la|grep testa
drwxr-xr-x 2 testa testa 4,0K 12 juil. 22:01 testa/
$ cat /etc/passwd|grep testa
testa:x:1030:1030::/var/www/testa/testa:/usr/bin/rssh
$ cat /etc/group|grep testa
testa:x:1030:
Création du chroot méthode A
[code]$ cd /var/www
$ /usr/share/doc/rssh/examples/mkchroot.sh testa/
NOT changing owner of root jail.
NOT changing perms of root jail.
setting up testa//usr/bin
setting up testa//usr/lib/openssh
setting up testa//usr/lib/rssh
Copying libraries for /usr/bin/scp.
/lib/libc.so.6
/lib64/ld-linux-x86-64.so.2
Copying libraries for /usr/lib/openssh/sftp-server.
/lib/libc.so.6
/lib64/ld-linux-x86-64.so.2
Copying libraries for /usr/bin/rssh.
/lib/libc.so.6
/lib64/ld-linux-x86-64.so.2
Copying libraries for /usr/lib/rssh/rssh_chroot_helper.
/lib/libc.so.6
/lib64/ld-linux-x86-64.so.2
copying name service resolution libraries…
tar: Suppression de « / » au début des noms des membres
lib/libnss_compat-2.11.2.so
lib/libnss_compat.so.2
lib/libnss_files-2.11.2.so
lib/libnss_files.so.2
Setting up /etc in the chroot jail
WARNING: Copying /etc/passwd into the chroot jail. You may wish
to edit out unnecessary users and remove any sensitive information
from it.
Chroot jail configuration completed.
NOTE: if you are not using the passwd file for authentication,
you may need to copy some of the /lib/libnss_* files into the jail.
NOTE: you must MANUALLY edit your syslog rc script to start syslogd
with appropriate options to log to testa//dev/log. In most cases,
you will need to start syslog as:
/sbin/syslogd -a testa//dev/log
NOTE: we make no guarantee that ANY of this will work for you… if it
doesn’t, you’re on your own. Sorry![/code]
Vérification du contenu du chroot :
[code]$ ls -Rla testa/
testa/:
total 28K
drwxr-xr-x 7 testa testa 4,0K 12 juil. 22:37 ./
drwxr-xr-x 3 root root 4,0K 12 juil. 22:01 …/
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 dev/
drwxr-xr-x 3 root root 4,0K 12 juil. 22:37 etc/
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 lib/
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 lib64/
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 usr/
testa/dev:
total 8,0K
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 7 testa testa 4,0K 12 juil. 22:37 …/
srw-rw-rw- 1 root root 0 11 juil. 20:59 log=
crw-rw-rw- 1 root root 1, 3 11 juil. 20:58 null
crw-rw-rw- 1 root root 1, 5 11 juil. 20:58 zero
testa/etc:
total 40K
drwxr-xr-x 3 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 7 testa testa 4,0K 12 juil. 22:37 …/
-rw-r–r-- 1 root root 15K 12 juil. 22:37 ld.so.cache
-rw-r–r-- 1 root root 34 12 juil. 22:37 ld.so.conf
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ld.so.conf.d/
-rw-r–r-- 1 root root 475 12 juil. 22:37 nsswitch.conf
-rw-r–r-- 1 root root 3,0K 12 juil. 22:37 passwd
testa/etc/ld.so.conf.d:
total 16K
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 3 root root 4,0K 12 juil. 22:37 …/
-rw-r–r-- 1 root root 44 12 juil. 22:37 libc.conf
-rw-r–r-- 1 root root 68 12 juil. 22:37 x86_64-linux-gnu.conf
testa/lib:
total 1,5M
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 7 testa testa 4,0K 12 juil. 22:37 …/
-rwxr-xr-x 1 root root 1,4M 12 juil. 22:37 libc.so.6*
-rw-r–r-- 1 root root 31K 23 janv. 21:30 libnss_compat-2.11.2.so
lrwxrwxrwx 1 root root 23 12 juil. 22:37 libnss_compat.so.2 -> libnss_compat-2.11.2.so
-rw-r–r-- 1 root root 47K 23 janv. 21:30 libnss_files-2.11.2.so
lrwxrwxrwx 1 root root 22 12 juil. 22:37 libnss_files.so.2 -> libnss_files-2.11.2.so
testa/lib64:
total 140K
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 7 testa testa 4,0K 12 juil. 22:37 …/
-rwxr-xr-x 1 root root 126K 12 juil. 22:37 ld-linux-x86-64.so.2*
testa/usr:
total 16K
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 7 testa testa 4,0K 12 juil. 22:37 …/
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 bin/
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 lib/
testa/usr/bin:
total 100K
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 …/
-rwxr-xr-x 1 root root 25K 12 juil. 22:37 rssh*
-rwxr-xr-x 1 root root 59K 12 juil. 22:37 scp*
testa/usr/lib:
total 16K
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 …/
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 openssh/
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 rssh/
testa/usr/lib/openssh:
total 72K
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 …/
-rwxr-xr-x 1 root root 59K 12 juil. 22:37 sftp-server*
testa/usr/lib/rssh:
total 36K
drwxr-xr-x 2 root root 4,0K 12 juil. 22:37 ./
drwxr-xr-x 4 root root 4,0K 12 juil. 22:37 …/
-rwxr-xr-x 1 root root 25K 12 juil. 22:37 rssh_chroot_helper*
[/code]
On test ! :
sftp testa@www1.com
Connecting to www1.com...
testa@www1.com's password:
Connection closed
FAIL !
Direction les logs :
/var/log/syslog :
Jul 12 22:41:06 kimsufi rssh[19474]: chroot cmd line: /usr/lib/rssh/rssh_chroot_helper 2 "/usr/lib/openssh/sftp-server -f LOCAL7 -l INFO"
/var/log/auth
Jul 12 22:41:04 kimsufi sshd[19471]: debug1: trying public key file /var/www/testa/testa/.ssh/authorized_keys
...
Jul 12 22:41:04 kimsufi sshd[19471]: debug1: trying public key file /var/www/testa/testa/.ssh/authorized_keys2
...
Jul 12 22:41:06 kimsufi sshd[19471]: Accepted password for testa from 172.16.52.1 port 41042 ssh2
Jul 12 22:41:06 kimsufi sshd[19471]: debug1: monitor_child_preauth: testa has been authenticated by privileged process
...
Jul 12 22:41:06 kimsufi sshd[19473]: subsystem request for sftp
Jul 12 22:41:06 kimsufi sshd[19473]: debug1: subsystem: exec() /usr/lib/openssh/sftp-server -f LOCAL7 -l INFO
Jul 12 22:41:06 kimsufi sshd[19473]: debug1: Received SIGCHLD.
Jul 12 22:41:06 kimsufi sshd[19473]: debug1: session_by_pid: pid 19474
Jul 12 22:41:06 kimsufi sshd[19473]: debug1: session_exit_message: session 0 channel 0 pid 19474
Jul 12 22:41:06 kimsufi sshd[19473]: debug1: session_exit_message: release channel 0
Jul 12 22:41:06 kimsufi sshd[19473]: Received disconnect from 172.16.52.1: 11: disconnected by user
/var/log/debug
Jul 12 22:41:06 kimsufi rssh[19474]: setting log facility to LOG_USER
Jul 12 22:41:06 kimsufi rssh[19474]: allowing scp to all users
Jul 12 22:41:06 kimsufi rssh[19474]: allowing sftp to all users
Jul 12 22:41:06 kimsufi rssh[19474]: setting umask to 022
Jul 12 22:41:06 kimsufi rssh[19474]: line 54: configuring user testa
Jul 12 22:41:06 kimsufi rssh[19474]: setting testa's umask to 011
Jul 12 22:41:06 kimsufi rssh[19474]: allowing sftp to user testa
Jul 12 22:41:06 kimsufi rssh[19474]: chrooting testa to /var/www/testa
Petit message que j’avais hier et que je n’ai pas réussi à reproduire :
Pas très concluant !
Tentative de contournement via cette ce post :
/etc/rssh.conf
[code]$cat /etc/rssh.conf
set the log facility. “LOG_USER” and “user” are equivalent.
logfacility = LOG_USER
allowscp
allowsftp
#allowcvs
#allowrdist
#allowrsync
#allowsvnserve
umask = 022
chrootpath = “/var/www/testa”
#user=testa:011:000100:/var/www/testa # sftp with chroot
[/code]
Même résultat…
On recommence avec l’utilisateur testb et en suivant le tuto cette fois :
/etc/rssh.conf
[code]$cat /etc/rssh.conf
set the log facility. “LOG_USER” and “user” are equivalent.
logfacility = LOG_USER
allowscp
allowsftp
#allowcvs
#allowrdist
#allowrsync
#allowsvnserve
umask = 022
#chrootpath = “/var/www/yoyo_www1 chroot”
user=testa:011:000110:/var/www/testa # sftp with chroot
user=testb:011:000110:/var/www/testb # sftp with chroot[/code]
Création de l’utilisateur testb
$ useradd --base-dir=/var/www/testb --shell=/usr/bin/rssh --password=test testb
$ mkdir /var/www/testb
$ chown testb:testb testb
$ ls -al /var/www|grep testb
drwxr-xr-x 2 testb testb 4,0K 12 juil. 23:04 testb/
$ cat /etc/passwd|grep testb
testb:x:1031:1031::/var/www/testb/testb:/usr/bin/rssh
$ cat /etc/group |grep testb
testb:x:1031:
Création du chroot en suivant le tuto :
$ ls -l /var/www
total 12K
-rwxr-xr-x 1 root root 528 12 juil. 23:08 copie_binaire*
drwxr-xr-x 7 testa testa 4,0K 12 juil. 22:37 testa/
drwxr-xr-x 2 testb testb 4,0K 12 juil. 23:04 testb/
$ ./copie_binaire /usr/bin/sftp /var/www/testb
$ cp /lib/libnss_files.so.2 /var/www/testb/lib
$ mkdir /var/www/testb/usr/lib/openssh
$ cp /usr/lib/openssh/sftp-server /var/www/testb/usr/lib/openssh/
$ cd /var/www/testb/
$ mkdir dev
$ mknod dev/null c 1 3
$ chmod 666 dev/null
$ chmod u+s /usr/lib/rssh/rssh_chroot_helper
Listing des fichiers du chroot
[code]ls -Rl /var/www/testb/
/var/www/testb/:
total 16K
drwxr-xr-x 2 root root 4,0K 12 juil. 23:13 dev/
drwxr-xr-x 2 root root 4,0K 12 juil. 23:11 lib/
drwxr-xr-x 2 root root 4,0K 12 juil. 23:09 lib64/
drwxr-xr-x 4 root root 4,0K 12 juil. 23:09 usr/
/var/www/testb/dev:
total 0
crw-rw-rw- 1 root root 1, 3 12 juil. 23:13 null
/var/www/testb/lib:
total 1,8M
-rwxr-xr-x 1 root root 40K 12 juil. 23:09 libbsd.so.0*
-rwxr-xr-x 1 root root 1,4M 12 juil. 23:09 libc.so.6*
-rwxr-xr-x 1 root root 15K 12 juil. 23:09 libdl.so.2*
-rwxr-xr-x 1 root root 281K 12 juil. 23:09 libncurses.so.5*
-rw-r–r-- 1 root root 47K 23 janv. 21:30 libnss_files.so.2
/var/www/testb/lib64:
total 132K
-rwxr-xr-x 1 root root 126K 12 juil. 23:09 ld-linux-x86-64.so.2*
/var/www/testb/usr:
total 8,0K
drwxr-xr-x 2 root root 4,0K 12 juil. 23:09 bin/
drwxr-xr-x 3 root root 4,0K 12 juil. 23:11 lib/
/var/www/testb/usr/bin:
total 104K
-rwxr-xr-x 1 root root 99K 12 juil. 23:09 sftp*
/var/www/testb/usr/lib:
total 152K
-rwxr-xr-x 1 root root 142K 12 juil. 23:09 libedit.so.2*
drwxr-xr-x 2 root root 4,0K 12 juil. 23:12 openssh/
/var/www/testb/usr/lib/openssh:
total 64K
-rwxr-xr-x 1 root root 59K 27 déc. 2010 sftp-server*[/code]
Même résultat final…
Qu’est ce que j’ai loupé de si évident ?