====== vsFTPd ====== ===== kurze Konfigurationsanleitung ===== ==== das ganze über PAM ==== [[https://www.fachinformatiker.de/topic/39292-der-sicherste-ftp-server/?tab=comments#comment-313069]] Dazu muss pam und die DB von Berkley installiert sein. Dann folgendes: - ''vi text.txt'' - Benutzer und Passwort einfach untereinander schreiben - ''db_load -T -t hash -f text.txt /etc/vsftpd_login.db'' - ''rm -rf text.txt'' (Aber Passwörter nicht vergessen :-D ) - ''chmod 600 /etc/vsftpd_login.db'' - ''vi /etc/vsftpd.pam'' - Dann diese 2 Zeilen in der Datei speichern (Kann je nach Pfad anders sein) - ''auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login.db'' - ''account required /lib/security/pam_userdb.so db=/etc/vsftpd_login.db'' - ''chmod 755 /etc/vsftpd.pam'' - ''cp /etc/vsftpd.pam /etc/pam.d/ftp'' - ''vi /etc/vsftpd.conf'' - Anonymous deaktivieren - Pfad zur ''vsftp_login.db'' eintragen - ''chroot''-Datei angeben (muss nur eine einfache Textdatei sein wo die user drin stehen) Ansonsten ein paar Tips: * Shell für ftp User abschalten ''/etc/passwd'' * vsftpd kann nur als root gestartet werden. Einen anderen user mit Rootrechten anlegen und diesem die Shell entnehmen :-) * chroot auf jedenfall benutzen * Sicherheit testen * besser wäre ein anderer Server Port Wenn du die normalen User zugreifen lassen willst, ändere zumindest in der ''/etc/passwd'' die ''/bin/bash'' in ''/bin/false''. Die Verzeichnisspfade können verschieden sein. Beim RedHat RPM werden die user DB's z.B. in ''/etc/vsftpd/*'' abgelegt. Auch das chroot und so befindet sich in dem Verzeichnis. Unter Redhat ist der Server viel einfacher aufzusetzen als unter Debian. ===== Ubuntu 12.04 LTS ===== ===== Quellen: ===== **VSFTP Installation** * [[http://wiki.ubuntuusers.de/vsftpd]] * [[https://security.appspot.com/vsftpd/vsftpd_conf.html]] **SSH Jail/Chroot** * [[http://allanfeid.com/content/creating-chroot-jail-ssh-access]] * [[http://itsprite.com/how-to-restrict-the-user-from-ssh-login-only-work-under-the-specified-directory/]] ===== Installation ===== > aptitude install vsftpd > echo "/bin/false/" >> /etc/shells Die Anpassung der Datei Shells ist notwendig, damit der vsftp Benutzeranmeldungen akzeptiert, deren Shell auf false konfiguriert wurde. ==== /etc/vsftpd.conf ==== Innerhalb der vsftpd.conf sind folgende Anpassungen Werte anzupassen/zu ergänzen. anonymous_enable=NO ftpd_banner=Willkommen auf dem FTP-Server. local_enable=YES local_umask=022 userlist_deny=NO userlist_enable=YES userlist_file=/etc/vsftpd.user_list user_config_dir=/etc/vsftpd_user_conf chroot_local_user=YES ==== Benutzerkonfiguration ==== === Anlegen der Benutzer und Homeverzeichnisse im OS === useradd fritz -m -s /bin/bash -d /home/ftp/ useradd clupdate -m -s /bin/false -d /home/ftp/mguard-live chown root:root /home/ftp/ chmod 555 /home/ftp/ chown fritz:clupdate /home/ftp/mguard-live chmod 755 /home/ftp/mguard-live === benutzerspezifische vsftpd Konfiguration === **Berechtigung für den FTP Zugang** Durch diese Einstellung werden die für FTP zugelassenen OS-Benutzer definiert echo fritz >> /etc/vsftpd.user_list echo clupdate >> /etc/vsftpd.user_list ** spezifische Einschränkungen für den Benutzer clupdate** mkdir /etc/vsftpd_user_conf echo "dirlist_enable=NO" >> /etc/vsftpd_user_conf/clupdate echo "write_enable=NO" >> /etc/vsftpd_user_conf/clupdate echo "write_enable=YES" > /etc/vsftpd_user_conf/fritz Diese Einstellungen verbieten dem Benutzer clupdate das Verzeichnislisting, sowie den schreibenden Zugriff === Konfiguration eines Jail für den SSH Zugriff von fritz === **Ergänzen der /etc/ssh/sshd_config** Match user fritz ChrootDirectory /home/ftp X11Forwarding no AllowTcpForwarding no **Einrichtung des Zugangs und des Jail** mkdir /home/ftp/.ssh/ echo ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDB9jnAYmxi+QOX0QTXPWBd4Pco+91F3u2A986DJ+vzvUvoksx4z4uePp+LEt0KtWB8MeFoUARregx2/KtExdkkCHln8WPbOGxT3ZwNszvyV0vCraePnLj4jwpDoWXTAZcg37Ffe4M7eCBU4ol3WZullyyRQCdlTZvBkU3HZc2B+ZcQxUn3NvYfQK6L+9f0== name@domain.de >>/home/ftp/.ssh/authorized_keys chown -R fritz:root /home/ftp/.ssh/ chmod 555 /home/ftp/.ssh/ chmod 400 /home/ftp/.ssh/authorized_keys chsh -s /bin/bash fritz mkdir /home/ftp/{dev,etc,lib,lib64,usr,bin} mkdir /home/ftp/usr/bin mknod -m 666 /home/ftp/dev/null c 1 3 cd /home/ftp/etc cp /etc/ld.so.cache . cp /etc/ld.so.conf . cp /etc/nsswitch.conf . cp /etc/hosts . cd /home/ftp/bin cp /bin/ls . cp /bin/bash . cp /bin/ln . cd /home/ftp cp /lib/x86_64-linux-gnu/libtinfo.so.5 lib64/ cp /lib/x86_64-linux-gnu/libdl.so.2 lib64/ cp /lib/x86_64-linux-gnu/libc.so.6 lib64/ cp /lib64/ld-linux-x86-64.so.2 lib64/ cp /lib/x86_64-linux-gnu/libselinux.so.1 lib64/ cp /lib/x86_64-linux-gnu/librt.so.1 lib64/ cp /lib/x86_64-linux-gnu/libacl.so.1 lib64/ cp /lib/x86_64-linux-gnu/libc.so.6 lib64/ cp /lib/x86_64-linux-gnu/libdl.so.2 lib64/ cp /lib64/ld-linux-x86-64.so.2 lib64/ cp /lib/x86_64-linux-gnu/libpthread.so.0 lib64/ cp /lib/x86_64-linux-gnu/libattr.so.1 lib64/ cp -r lib64 lib **Ausschluss von Jail-Files vom FTP Zugriff** echo 'hide_file={bin,dev,etc,lib,lib64,usr,.ssh,.bash*,.profile,linkTemplate.sh}' >> /etc/vsftpd.conf echo 'deny_file={bin,dev,etc,lib,lib64,usr,.ssh,.bash*,.profile,linkTemplate.sh}' >> /etc/vsftpd.conf ==== Zusätzliche Härtung des Systems mit CSF ==== [[https://extremeshok.com/2012/10/25/kvm-vmware-standalone-ubuntu-12-04-12-10-server-preparation/|CSF LINK]] dpkg --list 'linux-image*' | egrep -v "linux-image-generic|`uname -r | cut -d'-' -f1-2`|linux-image-server" | awk '/^ii/ { print $2 }' | xargs apt-get -y purge apt-get autoclean && apt-get echo -e "\n\n# eXtremeSHOK.com Secured\n#IP Spoofing protection\nnet.ipv4.conf.all.rp_filter=1\nnet.ipv4.conf.default.rp_filter=1\n#Ignore ICMP broadcast requests\nnet.ipv4.icmp_echo_ignore_broadcasts=1\n#Disable source packet routing\nnet.ipv4.conf.all.accept_source_route=0\nnet.ipv6.conf.all.accept_source_route=0 \nnet.ipv4.conf.default.accept_source_route=0\nnet.ipv6.conf.default.accept_source_route=0\n#Ignore send redirects\nnet.ipv4.conf.all.send_redirects=0\nnet.ipv4.conf.default.send_redirects=0\n#Block SYN attacks\nnet.ipv4.tcp_syncookies=1\n#Log Martians\nnet.ipv4.conf.all.log_martians=1\nnet.ipv4.icmp_ignore_bogus_error_responses=1\n#Ignore ICMP redirectsv\nnet.ipv4.conf.all.accept_redirects=0\nnet.ipv6.conf.all.accept_redirects=0\nnet.ipv4.conf.default.accept_redirects=0\nnet.ipv6.conf.default.accept_redirects=0\n#Ignore Directed pings\nnet.ipv4.icmp_echo_ignore_all=0" > /etc/sysctl.d/20-extremeshok.conf echo -e "# eXtremeSHOK.com Optimised\n#Close connections in the TCP FIN timeout state 10 seconds ( default 60 )\nnet.ipv4.tcp_fin_timeout=10\n#Increase the range of ports available for client connections ( default 32768 61000 )\nnet.ipv4.ip_local_port_range="15000 61000"\n#limits the maximum number of requests queued to a listen socket ( default 128 )\nnet.core.somaxconn=1024" > /etc/sysctl.d/10-extremeshok.conf echo -e "\n# eXtremeSHOK.com Optimised\n* soft nofile 8192\n* hard nofile 8192" >> /etc/security/limits.conf echo -e "net.ipv6.conf.all.disable_ipv6=1" > /etc/sysctl.d/10-no-ipv6.conf echo -e "nospoof on" >> /etc/host.conf apt-get purge -y ufw shorewall apf-firewall apt-get -y install iptables perl libwww-perl libgd-graph-perl libio-socket-inet6-perl libio-socket-ssl-perl libcrypt-ssleay-perl libnet-libidn-perl libsocket6-perl apt-get install -y nullmailer vim vim-nox screen unzip zip python-software-properties aptitude curl denyhosts dos2unix nullmailer smarthost -> 192.168.15.22 Konfigurieren denyhosts sed -i 's/ADMIN_EMAIL = root@localhost/ADMIN_EMAIL = csf_notifications@iq-optimize.de/g' /etc/denyhosts.conf sed -i 's/#SYNC_SERVER/SYNC_SERVER/g' /etc/denyhosts.conf sed -i 's/#SYNC_INTERVAL/SYNC_INTERVAL/g' /etc/denyhosts.conf sed -i 's/#SYNC_DOWNLOAD = yes/SYNC_DOWNLOAD = yes/g' /etc/denyhosts.conf installation csf export http_proxy=http://192.168.195.180:3128/ export HTTP_PROXY=http://192.168.195.180:3128/ wget http://www.configserver.com/free/csf.tgz -O /tmp/csf.tgz cd /tmp/ && tar -xzf csf.tgz cd csf && chmod 777 install.sh sh install.sh sysctl -w net.ipv4.icmp_echo_ignore_all=0 cd /usr/local/csf/tpl/ sed -i "s/To: root/To: administrator@domain.de/" *.txt update-rc.d -f ipmievd remove Proxy erweiterung "/usr/sbin/csf" **mit aktueller csf Version scheinbar überflüssig** zeile 3006 -> Bereich # start urlgetLWP my $req = HTTP::Request->new(GET => $url); ## WEG $ENV{HTTP_proxy} = "http://192.168.195.180:3128"; $ua->env_proxy; # initialize from environment variables ## my $res; zeile 3657 }; ##WEG delete $ENV{HTTP_PROXY}; ## alarm(0); danach und Erweiterung wieder vornehmen csf -uf Test csf perl /etc/csf/csftest.pl sed -i 's/IPV6 = "1"/IPV6 = "0"/g' /etc/csf/csf.conf cd /etc/csf/ echo -e "\n#Enable SSHD login tracking with ldf (csf)\nUseDNS no" >> /etc/ssh/sshd_config service ssh restart sed -i 's/TESTING = "1"/TESTING = "0"/g' /etc/csf/csf.conf /etc/csf/csf.allow 192.168.45.100 192.168.45.102 192.168.45.103 # icmp|in|d=ping|s=192.168.43.102 icmp|in|d=ping|s=192.168.43.103 icmp|out|d=pong|s=192.168.45.240 192.168.69.73 # csf SSH installation/upgrade IP address - Wed Oct 16 13:15:55 2013 192.168.43.102 # csf SSH installation/upgrade IP address - Wed Oct 30 15:13:19 2013 service csf restart /etc/csf/csf.pignore exe:/usr/sbin/vsftpd exe:/usr/sbin/nrpe exe:/usr/sbin/atd exe:/usr/sbin/rsyslogd exe:/usr/sbin/nullmailer-send # exe:/usr/sbin/sshd exe:/usr/sbin/ntpd exe:/bin/dbus-daemon exe:/sbin/ntpd exe:/usr/local/sbin/named