Debian da kullaniciyi libpam-chroot ile hapis etme

Debian Türkiye sitesinden

Debian'da kullaniciyi libpam-chroot ile hapis etme.

Yapacagimiz islemle bir dizine ufak bir debian sistemi kurup bazi kullanicilari sadece bir dizin altina hapsedebiliriz. Bu sekilde kullanicinin ne yapacagi kontrolludur ve kullanicinin root haklarini kazanmasi olanaksizdir.

Once chroot icin kullanacagimiz dizini olusturalim;

fb:/# mkdir /chroot

ve debootstrap ile olusturgumuz dizine paketleri istedigimiz depodan yukleyebiliriz. Ama debootstrap sistemimizde kurulu degilse,

fb:/# apt-get install debootstrap

ve olusturdugumuz dizine debootstrap ile ana paketleri kuralim.

fb:/# debootstrap sarge /chroot http://ftp.tr.debian.org/debian

ana paketleri depodan indirip kurmasi biraz vakit alabilir, gereken paketleri elimizde olan debian cdlerinden de kurabiliriz.Ornegin kurmamiz gereken paketleri cdlerimizden alip dizinin icine tasiyip orada acarak.

fb:/chroot# cp /cdrom/pool/main/w/wget/wget_1.9.1-8_i386.deb /chroot fb:/chroot# dpkg-deb -x wget_1.9.1-8_i386.deb . (sondaki noktaya dikkat!)

kurulum tamamlandiktan sonra,

fb:/# apt-get install libpam-chroot

paketini kuralim ve sistemimize kullanici ekleyelim.

fb:/# useradd -c "Chrooted User" -d /home/test -s /bin/bash test

ve kontrol edelim ekledigimiz kullaniciyi,

fb:/# grep -i test /etc/passwd test:x:1003:100:Chrooted User:/home/test:/bin/bash

fb:/# grep -i test /etc/passwd > /chroot2/etc/passwd

ve /etc/security/chroot.conf ici bu halde olmalidir.

fb:/# cat /etc/security/chroot.conf

  1. /etc/security/chroot.conf
  2. format:
  3. username chroot_dir

test /chroot

/etc/pam.d/ssh dosyasinin icine asagidaki satiri ekliyoruz.

session required pam_chroot.so debug

gerekli olan sistem aygitlarini olusturalim.

fb:/# cd chroot/ fb:/chroot# cp /dev/MAKEDEV dev/ fb:/chroot# cd dev/ fb:/chroot/dev# ./MAKEDEV generic fb:/chroot/dev# rm -f MAKEDEV fb:/chroot/dev# mount -t devpts devpts /chroot/dev/pts

Eger chroot kullanicilarina ssh erisimi vermek istiyorsak, /etc/ssh/sshd_config dosyasinda UsePrivilegeSeparation no satirinin olmasi gerekiyor, chroot kullanicisinin home dizinini de olusturalim ve sifresini tanimlayalim;

fb:/chroot# cd home/ fb:/chroot/home# mkdir test fb:/chroot/home# chown -R test test/ fb:/chroot/home# passwd test Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

Simdi test edelim, chroot kullanicimizla sistemimize ssh ile baglanalim,

fb:/# ssh -l test fb

kullanici olusturdugumuz chroot dizininin disina cikamaz.

Faydalanilan Kaynaklar:

http://www.chains.ch/chroot.php file:///usr/share/doc/libpam-chroot/ man MAKEDEV