- SSH-Zugang
- Kommandos via Busybox, ssh und bash
- chroot-Sperre
- Obskurer Zugang
ACHTUNG: Nur fuer Experten!
Von: Oliver Schade <os *AT* ls-la.net>
Code: Select all
Benoetigter Quellcode:
a) OpenSSH (www.openssh.org)
b) Busybox (www.busybox.net)
c) bash (ftp.gnu.org/pub/gnu/bash)
d) chroot-Patch fuer OpenSSH (chrootssh.sourceforge.net)
Schritte:
a) bash statisch kompilieren
tar -xvzf bash-2.05b.tar.gz
cd bash-2.05b
export CFLAGS="--static -O2 -funroll-loops"
./configure
make
Mit "ldd bash" nachschauen, ob es geklappt hat - zur Not wiederholen.
b) Busybox statisch kompilieren
tar -xvzf busybox-0.60.3.tar.gz
cd busybox-0.60.3
vim +36 Makefile # Makefileoptionen
DOSTATIC = true # statisches Binary
vim +52 Makefile
USE_SYSTEM_PWF_GRP = true # /etc/passwd group verwenden
vim +77 Makefile
DOLFS = true # Large Filesystem support
vim Config.h # Die Benutzerbefehle aussuchen
# Dies sind die harmlosen erlaubten:
#define BB_BASENAME
#define BB_CAT
#define BB_CHMOD
#define BB_CLEAR
#define BB_CMP
#define BB_CP
#define BB_GREP
#define BB_GUNZIP
#define BB_GZIP
#define BB_HEAD
#define BB_ID
#define BB_KILL
#define BB_LN
#define BB_LOGGER
#define BB_LS
#define BB_MD5SUM
#define BB_MKDIR
#define BB_MORE
#define BB_MV
#define BB_NC
#define BB_NSLOOKUP
#define BB_PIDOF
#define BB_PING
#define BB_PS
#define BB_PWD
#define BB_RM
#define BB_RMDIR
#define BB_SED
#define BB_SLEEP
#define BB_SORT
#define BB_CUT
#define BB_DATE
#define BB_DD
#define BB_DF
#define BB_DIRNAME
#define BB_DOS2UNIX
#define BB_DU
#define BB_ECHO
#define BB_ENV
#define BB_EXPR
#define BB_FIND
#define BB_TAIL
#define BB_TAR
#define BB_TEST
#define BB_TELNET
#define BB_TOUCH
#define BB_TRACEROUTE
#define BB_TRUE_FALSE
#define BB_UNIQ
#define BB_UNAME
#define BB_UPTIME
#define BB_VI
#define BB_WC
#define BB_WGET
#define BB_WHICH
#define BB_WHOAMI
#define BB_XARGS
#define BB_YES
make
Mit "ldd busybox" kontrollieren, ob das Binary statisch und gestrippt
ist.
c) Benutzer fuer chroot-Zugang anlegen (hier am Beispiel fuer user "os")
groupadd -g 2000 os # GID anpassen!
useradd -u 2000 -g 2000 # UID und GID anpassen!
-d /home/os/./ # /./ am Ende ist entscheidend!
-s /bin/bash os
chfn os
passwd os
d) chroot-Umgebung aufbauen
mkdir /home/os
cd /home/os
mkdir bin dev etc lib usr usr/lib usr/bin etc/ssh
Wird zu:
/home/os
|-- bin
|-- dev
|-- etc
| `-- ssh
|-- lib
`-- usr
|-- bin
`-- lib
mknod dev/null c 1 3 # /home darf nicht mit nodev
mknod dev/random c 1 8 # gemountet sein!
mknod dev/tty c 5 0
mknod dev/urandom c 1 9
cd ...../busybox-0.60.3 # Busybox-Binaries installieren
sh install.sh /home/os # Prima!
cd ...../bash-2.05b # Bash installieren
cp bash /home/os/bin
# Minimal benoetigte Bibliotheken installieren
cd /home/os/lib
for i in libdl libnss_compat libnss_dns libnss_files libresolv; do
cp /lib/$i-2.2.5.so .
ln -s $i-2.2.5.so $i.so.2
done
cp /lib/libc-2.2.5.so .
ln -s libc-2.2.5.so libc.so.6
cp /lib/libnsl-2.2.5.so .
ln -s libnsl-2.2.5.so libnsl.so.1
cp /lib/libutil-2.2.5.so .
ln -s /libutil-2.2.5.so libutil.so.1
cd /home/os/usr/lib
cp /usr/lib/libcrypto.so.9.6 .
ln -s libcrypto.so.9.6 libcrypto.so
cp /usr/lib/libz.so.1.1.4 .
ln -s libz.so.1.1.4 libz.so.1
cp /usr/bin/ssh /home/os/usr/bin
cp /usr/bin/scp /home/os/usr/bin
cp /usr/bin/sftp /home/os/usr/sftp
# Benoetigte Daten in etc
grep root /etc/passwd >> /home/os/etc/passwd
grep os /etc/passwd >> /home/os/etc/passwd
grep root /etc/group >> /home/os/etc/group
grep os /etc/group >> /home/os/etc/group
cp /etc/nsswitch.conf /home/os/etc/nsswitch.conf
cp /etc/resolv.conf /home/os/etc/resolv.conf
echo "/bin/bash" > /home/os/etc/shells
cp /etc/ssh/moduli /home/os/etc/ssh
cp /etc/ssh/ssh_config /home/os/etc/ssh
# Ein wenig Security
find /home/os -type d -exec chmod a=x {} ;
chmod a=x /home/os/bin/bash
chmod a=x /home/os/bin/busybox
chmod a=x /home/os/usr/bin/ssh
chmod a=x /home/os/usr/bin/scp
chmod a=x /home/os/usr/bin/sftp
cd /home/os
chmod -R +i dev bin usr etc lib
Jetzt muesste das ganze so aussehen:
/home/os
|-- bin/
| |-- bash*
| |-- busybox*
| |-- cat -> busybox*
| |-- chmod -> busybox*
| |-- cp -> busybox*
| |-- date -> busybox*
| |-- dd -> busybox*
| |-- df -> busybox*
| |-- echo -> busybox*
| |-- false -> busybox*
| |-- grep -> busybox*
| |-- gunzip -> busybox*
| |-- gzip -> busybox*
| |-- kill -> busybox*
| |-- ln -> busybox*
| |-- ls -> busybox*
| |-- mkdir -> busybox*
| |-- more -> busybox*
| |-- mv -> busybox*
| |-- pidof -> busybox*
| |-- ping -> busybox*
| |-- ps -> busybox*
| |-- pwd -> busybox*
| |-- rm -> busybox*
| |-- rmdir -> busybox*
| |-- sed -> busybox*
| |-- sh -> busybox*
| |-- sleep -> busybox*
| |-- tar -> busybox*
| |-- touch -> busybox*
| |-- true -> busybox*
| |-- uname -> busybox*
| |-- vi -> busybox*
| `-- zcat -> busybox*
|-- dev/
| |-- null
| |-- random
| |-- tty
| `-- urandom
|-- etc/
| |-- group
| |-- nsswitch.conf
| |-- passwd
| |-- resolv.conf
| |-- shells
| `-- ssh/
| |-- moduli
| `-- ssh_config
|-- lib/
| |-- ld-linux.so.2*
| |-- libc-2.2.5.so*
| |-- libc.so.6 -> libc-2.2.5.so*
| |-- libdl-2.2.5.so
| |-- libdl.so.2 -> libdl-2.2.5.so
| |-- libnsl-2.2.5.so
| |-- libnsl.so.1 -> libnsl-2.2.5.so
| |-- libnss_compat-2.2.5.so
| |-- libnss_compat.so.2 -> libnss_compat-2.2.5.so
| |-- libnss_dns-2.2.5.so
| |-- libnss_dns.so.2 -> libnss_dns-2.2.5.so
| |-- libnss_files-2.2.5.so
| |-- libnss_files.so.2 -> libnss_files-2.2.5.so
| |-- libresolv-2.2.5.so
| |-- libresolv.so.2 -> libresolv-2.2.5.so
| |-- libutil-2.2.5.so
| `-- libutil.so.1 -> libutil-2.2.5.so
`-- usr/
|-- bin/
| |-- [ -> ../../bin/busybox*
| |-- basename -> ../../bin/busybox*
| |-- clear -> ../../bin/busybox*
| |-- cmp -> ../../bin/busybox*
| |-- cut -> ../../bin/busybox*
| |-- dirname -> ../../bin/busybox*
| |-- dos2unix -> ../../bin/busybox*
| |-- du -> ../../bin/busybox*
| |-- env -> ../../bin/busybox*
| |-- expr -> ../../bin/busybox*
| |-- find -> ../../bin/busybox*
| |-- free -> ../../bin/busybox*
| |-- head -> ../../bin/busybox*
| |-- id -> ../../bin/busybox*
| |-- logger -> ../../bin/busybox*
| |-- md5sum -> ../../bin/busybox*
| |-- nc -> ../../bin/busybox*
| |-- nslookup -> ../../bin/busybox*
| |-- scp*
| |-- sftp*
| |-- sort -> ../../bin/busybox*
| |-- ssh*
| |-- tail -> ../../bin/busybox*
| |-- telnet -> ../../bin/busybox*
| |-- test -> ../../bin/busybox*
| |-- traceroute -> ../../bin/busybox*
| |-- uniq -> ../../bin/busybox*
| |-- uptime -> ../../bin/busybox*
| |-- wc -> ../../bin/busybox*
| |-- wget -> ../../bin/busybox*
| |-- which -> ../../bin/busybox*
| |-- whoami -> ../../bin/busybox*
| |-- xargs -> ../../bin/busybox*
| `-- yes -> ../../bin/busybox*
`-- lib/
|-- libcrypto.so -> libcrypto.so.0.9.6
|-- libcrypto.so.0.9.6
|-- libz.so.1 -> libz.so.1.1.4
`-- libz.so.1.1.4
Es empfiehlt sich, nach der Erstanlegung daraus ein tar-
Archiv zu erzeugen und dies fuer weitere Benutzer einzuspielen.
Dann muss nur /home/neu/etc/group und /home/neu/etc/passwd
geaendert werden, sowie
find /home/neu -user ALT -exec chown neu {} ;
find /home/neu -group ALT -exec chgrp neu {} ;
for i in bin etc dev lib usr; do
chattr -R +i /home/neu/$i
done
verwendet werden.
d) OpenSSH mit chroot-Patch kompilieren
# Neuen Benutzer fuer PrivilegeSeperation installieren
# UID und GID anpassen!
groupadd -g 34 chrsshd
useradd -u 34 -g 34 -d /usr/local/ChrootSSH -s /bin/false
tar -xvzf openssh-3.4p1.tar.gz
cd openssh-3.4p1
# Patch einspielen
cat /tmp/osshChroot-3.4.diff | patch -p1
# Uebersetzen
./configure --prefix=/usr/local/ChrootSSH --with-pam
--with-ipaddr-display --with-ipv4-default
--with-md5-passwords --with-zlib
--with-pid-dir=/usr/local/ChrootSSH/var/run
--with-privsep-user=chrsshd
Dazu muessen einige dev-Pakete installiert sein: zlib-dev, pam-dev
libssl-dev.
make
make install
make clean
Konfiguration in /usr/local/ChrootSSH/etc/sshd_config anpassen.
Ich habe einen abweichenden Port genommen (Obksurer Zugang :):
# $OpenBSD: sshd_config,v 1.56 2002/06/20 23:37:12 markus Exp $
Port 2222
Protocol 2
ListenAddress 217.160.XXX.YYY
PermitRootLogin no
[schnipp]
Ein Zugang ist dann mit ssh -p 2222 -l account 217.160.XXX.YYY
moeglich - nur fuer User, die automatisch im chroot landen.
# Initscript erzeugen
cd /etc/init.d
cp ssh chroot-ssh.tmp
cat chroot-ssh.tmp
| sed -e 's//usr/sbin/sshd//usr/local/ChrootSSH/sbin/sshd/g'
> chroot-ssh
chmod u=wrx,o=,g= chroot-ssh
rm chroot-ssh.tmp
cd /etc/rc2.d
ln -s /etc/init.d/chroot-ssh S21chroot-ssh
d) Bingo - fertig.
Laeuft alles, kann der originale SSH von Debian umkonfiguriert
werden:
vim /etc/ssh/sshd_config
# What ports, IPs and protocols we listen for
Port 22
PermitRootLogin yes
ListenAddress 127.0.0.1
Protocol 2
Nun kann Root sich nur noch einloggen, wenn er vorher in einer
chroot-Shell ein "ssh 127.0.0.1 -l root" gestartet hat...