SSH Tipps+Tricks Server: Netcat, inetd, Apache, Mail, Samba, Mysql, NFS Franz Schäfer LV Linux: Effiziente Anwendung an Hand von Fallbeispielen
Franz Schäfer ● I.S.T. Austria ● ZID WU ● ISP (akis, silverserver,...) ● Nachtrichtentechnik, Regelungstechnik, Computertechnik ● Linux User seit 1995 (kernel )
Themenübersicht ● Advanced SSH ● Inetd, netcat, tcpwrapper ● Apache Webserver ● Mailserver Grundlagen ● mysql ● samba übersicht ● NFS
Wozu SSH? ● für – terminal verbindung – file transfer – remote execution, automatisierung ● verschlüsselte verbindung – sichert nicht vor: ● kompromitierten eigenen hosts ● kompromitierten fremden hosts
Übersicht SSH ● Implementierungen – openssh – putty –... ● remote einloggen mit ssh – mit passwort – mit kerberos ticket – mit RSA/DSA key
password login mit ssh # ssh The authenticity of host 'login.wu- wien.ac.at ( )' can't be established. RSA key fingerprint is a2:61:d0:f8:1a:13:f7:71:51:26:b8:c2:5f:6 f:00:97. Are you sure you want to continue connecting (yes/no)?
ssh mit kerberos # kinit h # ssh -K -K.... Enables forwarding (delegation) of GSSAPI credentials to the server.
ssh mit.k5login ● Mit einem file.k5login im homverzeichniss: einlogen mit speziellen kerberos principals moeglich: ● z.b. in /root/.k5login
man in the middle ssh WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the- middle attack)! It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sent by the remote host is 90:9c:46:ab:03:1d:30:2c:5c:87:c5:c7:d9:13:5d:7
scp – secure copy # echo bla >bla.txt # scp bla.txt # scp # scp -r diplomarbeit/
ssh configuration ●.ssh/config Host wu HostName pecuchet.wu-wien.ac.at User h ●.ssh/known_hosts ●.ssh/authorized_keys ● Sitewide: – /etc/ssh/ssh_config – /etc/ssh/sshd_config
einlogen mit RSA/DSA key # ssh-keygen (eventuell -f) normalerweise mit passphrase # scp.ssh/id_rsa.pub wu: # cat id_rsa.pub >>.ssh/authorized_keys # ssh -i andererschluessel alternativ: # ssh-copy-id wu
remote execution ssh "ls -l /tmp" echo bla | ssh \ "cat - > bla.txt" ssh "ls -l /tmp" | grep bla nützlich für scripts zum automatisieren von abläufen
Remote Ausführung einschränken ● im.ssh/authorized_keys from=" ",no-pty,no-port- forwarding,command="/root/bla.sh" ssh-dss AAAUH7T9Y....
X11 forwarding # ssh -X # echo $DISPLAY # localhost:10.0 # xterm & # xauth list Achtung: Remote Angreifer bekommt zugriff aufs lokale display
ssh agent ssh-agent kann zugriff auf passphrase cachen # ssh-agent xterm & # ssh-add.... passphrase ● Bei vielen Distributionen: ssh-agent wird automatisch mit X gestartet
ssh port forwarding # ssh \ -L 3333:proxy.wu-wien.ac.at:8080 \ ● von lokal erlauben den wu proxy auf localhost port 3333 zu verwenden (optional: -g ) # ssh -R 4567:localhost:80 \ ● zugriff auf den lokaeln webserver von remote host aus erlauben (default: nur von da)
ssh socks proxy # ssh -D 9999 ● socks proxy ● z.B.: via browser verwendbar
URL in KDE und GNOME
Zusammenfassung SSH ● SSH – mit passwort – mit kerberos – mit RSA Keys – scp – konfiguration – remote kommandos – keys einschränken – X11 Forwarding – port forwarding – agent – eingebauter Socks-Proxy – sftp in KDE/GNOME
netcat # apt-get install netcat # echo bla bla| netcat -l -p 7777 telnet localhost 7777
inetd – der alleskönner ● im /etc/inetd.conf pop-3 stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.pop3d Beispiel Proxy: 4567 stream tcp nowait nobody /usr/sbin/tcpd /bin/nc -t # killall -HUP inetd
Excurs TCP wrapper ● Services schützen via: – /etc/hosts.allow – /etc/hosts.deny ● Beispiel: ALL: , / man hosts_access
Apache Webserver ● Marktanteil ca 67% ● Vergleich IIS ca 17% (von 1 million busiest sites, Aug 2020) t-2010-web-server-survey-4.html
Zugriff auf Webserver # telnet 80 GET / # telnet 80 HEAD / HTTP/1.1 HTTP/ Bad Request Date: Wed, 05 Dec :38:35 GMT Server: Apache Connection: close Content-Type: text/html; charset=iso # wget -S
Apache Installieren, Start/Stop # apt-get install apache oder # apt-get install apache2 # apachectl configtest # apache2ctl configtest # apachectl restart # /etc/init.d/apache2 restart
Apache Configuration ● /etc/apache2/httpd.conf ● /etc/apache/httpd.conf ● manches auch in.htaccess ● weitere files via Include /etc/apache2/bla/*.conf
Apacheconfig Bereiche ● Sitewide – z.B.: Listen 80 – DocumentRoot /var/meinwww/ ● VirtualHost ● Directory ● Location
Excurs: Einfaches HTML ● z.B.: index.html test überschrift test fett
VirtualHost Name/IP-Based ServerAdmin DocumentRoot /var/www/meinserver/ ServerName ServerAlias meinserver.at php_flag register_globals 0 RedirectPermanent /w/
Beispiel: Directory AllowOverride AuthConfig Options +ExecCGI -Indexes Addhandler cgi-script.cgi ScriptAlias /cgi/ /var/www/scripts/
Beispiel Location SetHandler server-status Order Deny,Allow Deny from all Allow from Allow from
Apache SSL ( SSLEngine on SSLCertificateFile /etc/cert/mein.crt SSLCertificateKeyFile /etc/cert/mein.key ServerName meinserver.at DocumentRoot /var/www-secure Problem mit name-based VirtualHosts Keys mit openssl erzeugen
Einschub: Keys mit openssl # openssl req -new -nodes \ -newkey rsa:1024 -keyout mein.key \ -out mein.csr # openssl x509 -req -in mein.csr \ - signkey mein.key -out mein.crt \ - days 365 ● zur kontrolle: # openssl rsa -in mein.key -text # openssl req -in mein.csr -text # openssl x509 -in mein.crt -text
Offizielle Zetrifizierung ● Verisign, Thawte, & Co... ● TCS Terena (aconet) ● Kostenlose Peer2Peer Zertifizierung:
Einfaches CGI script ● im file: test.cgi #!/bin/bash echo Content-type: text/plain echo echo ich bin: id echo datum ist: date
Ein einfaches PHP script
Sicherheit 1.) Updaten 2.) Oft Updaten 3.) Regelmäßig Updaten 4.) Achtung bei Scripts 5.) Achtung bei PHP Scripts! 6.) Forum/CMS/Fertigpakete: Updaten!
Beispiel PHP Insecurity ● /PHP-Security-Mistakes/ include('vorlagen/'. $template) ● $template – aus formular? – aus cookie? ● $template=“../../../../etc/passwd“
Beispiel SQL Injection ● $res= mysql_query( 'SELECT * FROM bla WHERE id="'. $_GET['id']. '"'); ● möglicher Inhalt von 'id': ● "; DELETE FROM bla != "dfssdf ● "; DROP DATABASE meinforum;
Zusammenfassung Apache – webzugriff per telnet GET / – apache start stop, configtest – wichtige config files – Gültigkeits- bereiche der Direktiven – einfches HTML – Name vs. IP Based VirtualHosts – Directory – Location – https, openssl, Zertifizierung – cgi, php, und Sicherheit
Mail Server Grundlagen ● Transport via SMTP: Store and Forward ● Abfrage von Mailboxen: – lokal: /var/spool/mail – POP3 – IMAP ● Hauptproblem: SPAM
Übersicht: MTA ● sendmail: alt aber gut ● exim: klein aber fein ● postfix: der herausforderer ● qmail: hauptsache anders
Eine Verbindung mit einem Mailserver # telnet mx1.wu-wien.ac.at mx1.wu-wien.ac.at ESMT.. helo. mail from: rcpt to: data bla. quit
IMAP Server ● courier – für mittlere installationen – maildir format ● cyrus – für große installationen ● uw-imapd – standard mbox
Commandline Mail # echo test | \ mutt -s test # mutt -f
sendmail config Übersicht ● im Directory /etc/mail/ ● in sendmail. mc (o.ä) ● file editieren # make # make restart
nützliches für.mc file (m4) MASQUERADE_AS(`blabla.at')dnl FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl FEATURE(`genericstable', `hash -o /etc/mail/genericstable.db')dnl FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl FEATURE(access_db)dnl define(`SMART_HOST', `smtp.wu- wien.ac.at')
mysql ● ca 10 million installations (2008) ● wartungsfrei und robust ● inzwischen fast alle features der grossen
mysql commands # mysqladmin -uroot -p create bladb # mysqldump -uroot -p otherdb >other.dump # cat other.dump | mysql -uroot -p bladb # echo "select * from blatable;" \ | mysql -uroot -p bladb
mysql prompt am mysql prompt: # CREATE USER # SET PASSWORD FOR = PASSWORD('geheim'); # GRANT SELECT ON bladb.* TO ;
Samba Linux Server für Windows Netze ● apt-get install samba ● datei: /etc/samba/smb.conf /etc/init.d/samba restart [musik] comment = meine mp3sammlung als share writable = no locking = no path = /extraplatte/mp3/ public = yes hosts allow = /
NFS Server # /etc/exports: the access control list for filesystems which may be exported /home/ gss/krb5i(rw,sync,fsid=0,no_subtree_check) /home/ (rw,no_subtree_check)
NFS Client in /etc/fstab: meinserver:/ /nfs4home/ nfs4sec=krb5i0 3
weitere bliebte serverdienste ● asterisk (telefonie, sip, h323, isdn..) ● nagios (network monitoring) ● small services (dns, dhcp, tftp, time,...) ● ftp (vsftpd) ● terminal services (X11) ● authentisierung und directory: kerberos, ldap ● virtualisierung (vmware, xen, kvm, openvz, linux-vserver) ● postgres, andere datenbanken ● cluster: gridengine ● IRC, etc..etc..
Zusammenfassung ● Advanced SSH ● netcat ● inetd ● tcpwrapper ● Apache Grundlagen ● Mail Server Übersicht ● Einblick in Samba