Debian GNU/Linux - Unix Sicherheit - Institut für Experimentelle und
Transcription
Debian GNU/Linux - Unix Sicherheit - Institut für Experimentelle und
Debian GNU/Linux: Sicherheit Debian GNU/Linux Unix Sicherheit Christian T. Steigies Institut für Experimentelle und Angewandte Physik Christian-Albrechts-Universität zu Kiel Debian crash course – 21.02.2007 Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit Anmelden am System I login an der Konsole I login per xdm/gdm/kdm I remote login mit telnet, rsh, ftp I secure login mit ssh, scp, slogin Pluggable Authentication Modules (PAM) I I I pam_cracklib: Mindestanforderungen an Passwort pam_opie: one time passwords Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit Remote-Logins I nur per SSH, niemals mit telnet, ftp vermeiden I verschlüsselte Kommunikation mit SSH, dadurch kein Abhören I (password im Klartext auch bei fetchmail ohne ssl oder ssh tunneling) I kein login als root I keine leeren Passworte I nur ssh2, nicht ssh1 I login per authorized_keys Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit Verbesserung der Sicherheit I /etc/ssh/sshd_config I ändern des ports (security by obscurity) I PasswordAuthentication no I PermitRootLogin no (Problem mit faubackup?) I restrict users I /etc/hosts.allow|deny I iptables (ssh_blocking) Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit ssh-keygen I ssh-keygen -trsa I passphrase statt password I .ssh/id_rsa.pub I kopieren nach .ssh/authorized_keys auf remote host I ssh-copy-id user@machine I ssh-add I .ssh/config Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit ~/.ssh/config Host 192.168.1.9 ForwardAgent yes ForwardX11 yes PasswordAuthentication no StrictHostKeyChecking no Port 2201 Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit Ssh-faker Ssh-faker 1.1 There’s a worm out there that tries to log in through ssh using a long list of popular usernames and passwords. If you don’t want it to succeed, it’s a good idea to not let it connect to your actual sshd program. Ssh-faker was initially written to deal with buffer overflow attacks back when sshd was vulnerable (it may still be), but it works well for this too. This program is called by /etc/hosts.deny whenever someone connects to port 22. Unless they type in a plaintext password or type the wrong password, they get an ssh-compatible error message, and a syslog message is generated. If they type in the right password, they are added to /etc/hosts.allow, and their next connection will reach the real sshd. In my opinion, this is better than denying ip addresses as soon as they fail ssh logins three times because: - I don’t want to be locked out of my own computer if I can’t type my password right for some reason (broken key on keyboard/fingers on wrong keys/too much caffeine+sugar?) - This way, the /etc/hosts.deny file or iptables deny list doesn’t grow all the time. - The bad guys can’t get more chances just by changing their ip address. Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit http://www.aerospacesoftware.com/ssh-kiddies.html SSH vs Script Kiddies How-to Guide Some idiot created a SSH worm that uses a dictionary attack to try to log into a computer over port 22. The worm tries to set up shop on your computer and tries to find the next vulnerable computer. This clogs up networks with bazillions of SSH login attempts. A number of people created scripts that scan the system log files to identify the IP address of attackers and block them either using TcpWrappers or Netfilter. The problem with these approaches is that it consumes local computer resources. It also creates the risk that you can lock yourself out accidentally - maybe not a problem if the computer is in the next room, but it is a serious concern if the computer is far away on the other side of the globe. Another solution is to set SSHD to use a different port. This will work, till the attacker adds a port scanner to his worm. What is needed is a simple solution that consumes the resources of the attacker instead of your own. This little guide shows how to slow down SSH password authentication to accomplish this in a single line of code. This simple modification has been proven to completely defeat the attack, as Christian discussed below. T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb ... 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 09:53:54 09:53:58 09:54:01 09:54:08 09:54:13 09:54:17 09:54:21 09:54:26 09:54:34 09:54:41 09:54:47 09:54:54 09:54:59 09:55:03 09:55:07 09:55:11 09:55:17 09:55:25 09:55:29 09:55:36 09:55:40 09:55:43 09:55:47 09:55:51 09:55:56 09:56:00 09:56:03 09:56:13 09:56:18 09:56:22 09:56:27 batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf sshd[17915]: sshd[17917]: sshd[17919]: sshd[17921]: sshd[17923]: sshd[17925]: sshd[17927]: sshd[17929]: sshd[17931]: sshd[17933]: sshd[17935]: sshd[17937]: sshd[17939]: sshd[17941]: sshd[17943]: sshd[17945]: sshd[17947]: sshd[17950]: sshd[17952]: sshd[17954]: sshd[17956]: sshd[17958]: sshd[17960]: sshd[17962]: sshd[17964]: sshd[17966]: sshd[17968]: sshd[17970]: sshd[17972]: sshd[17974]: sshd[17976]: Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Christian T. Steigies user user user user user user user user user user user user user user user user user user user user user user user user user user user user user user user lpd from 218.75.69.132 lpa from 218.75.69.132 admin from 218.75.69.132 admin from 218.75.69.132 admin from 218.75.69.132 ftpuser from 218.75.69.132 ftpuser from 218.75.69.132 ftpuser from 218.75.69.132 ftpuser from 218.75.69.132 ftpuser from 218.75.69.132 ftpuser from 218.75.69.132 ftpuser from 218.75.69.132 mailtest from 218.75.69.132 mailtest from 218.75.69.132 mailtest from 218.75.69.132 mailtest from 218.75.69.132 mailtest from 218.75.69.132 mailtest from 218.75.69.132 testuser from 218.75.69.132 testuser from 218.75.69.132 testuser from 218.75.69.132 testuser from 218.75.69.132 testuser from 218.75.69.132 testuser from 218.75.69.132 sales from 218.75.69.132 sales from 218.75.69.132 sales from 218.75.69.132 sales from 218.75.69.132 sales from 218.75.69.132 sales from 218.75.69.132 sales from 218.75.69.132 Debian GNU/Linux Debian GNU/Linux: Sicherheit mit ssh_blocking Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb 20 20 20 21 21 21 21 21 21 21 21 21 21 14:31:33 14:31:35 14:31:38 13:48:16 13:48:19 13:48:22 13:53:56 13:59:32 14:05:10 14:53:01 14:53:03 14:58:36 16:14:09 batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf batdaf sshd[1721]: sshd[1723]: sshd[1725]: sshd[2492]: sshd[2494]: sshd[2496]: sshd[2517]: sshd[2531]: sshd[3421]: sshd[3484]: sshd[3487]: sshd[3490]: sshd[5355]: Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Invalid Christian T. Steigies user user user user user user user user user user user user user lpd from 210.118.94.55 lpa from 210.118.94.55 admin from 210.118.94.55 delta from 131.206.19.202 admin from 131.206.19.202 test from 131.206.19.202 project from 131.206.19.202 jeeto from 131.206.19.202 http from 131.206.19.202 delta from 210.115.43.58 admin from 210.115.43.58 violet from 210.115.43.58 from 202.8.178.250 Debian GNU/Linux Debian GNU/Linux: Sicherheit #!/bin/bash # block annoying ssh login attemps # allow 10 attemps per hour, remembers attemps for one hour # needs iptables from unstable, ie 1.3.2-1 case "$1" in start) iptables -v -I INPUT -p tcp --syn -d 0.0.0.0/0 --dport 22 -j ACCEPT \ -m hashlimit --hashlimit 10/hour --hashlimit-mode srcip,dstip \ --hashlimit-burst 3 --hashlimit-name ssh --hashlimit-htable-expire 3600000 iptables -v -A INPUT -p tcp --syn -d 0.0.0.0/0 --dport 22 -j REJECT \ --reject-with icmp-host-prohibited ;; stop) iptables -D INPUT 1 iptables -D INPUT 1 ;; show) iptables -L -vn echo "" echo "/proc/net/ipt_hashlimit/ssh" echo "" cat /proc/net/ipt_hashlimit/ssh ;; *) echo "start stop show" ;; esac Christian T. Steigies Debian GNU/Linux Debian GNU/Linux: Sicherheit Misc I Sound konfigurieren mit alsaconf I Volume einstellen mit aumix, alsamixer I Drucker einrichten mit lprng (einfach) oder CUPS (AMD64: drucken aus OO, Acroread, . . . ) I faubackup Christian T. Steigies Debian GNU/Linux