SSH Tipps+Tricks Server: Apache, Mail, Samba Franz Schäfer LV Linux: Effiziente Anwendung an Hand von Fallbeispielen
Franz Schäfer ● ZID ● ISP (akis, silverserver,...) ● Nachtrichtentechnik, Regelungstechnik, Computertechnik ● Linux User seit 1995 (kernel )
Themenübersicht ● Advanced SSH ● Apache Webserver ● Mailserver Grundlagen
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.
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 -i.ssh/id_rsa.pub wu
remote execution ssh “ls -l /tmp” echo didldoe | 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
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
Apache Webserver ● Marktanteil ca 50% (Nov 2007) ● Vergleich IIS ca 35%
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 Keys mit openssl erzeugen Problem mit name-based VirtualHosts
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... ● SureServerEDU TLS ● 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/Fertigpackte: 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')
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 = /
Zusammenfassung ● Advanced SSH ● Apache Grundlagen ● Mail Server Übersicht ● Einblick in Samba