Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: SSH Brute Force Attacks
PostPosted: Mon Sep 13, 2004 12:03 pm 
Offline
Senior Member
User avatar

Joined: Fri Aug 15, 2003 2:15 pm
Posts: 111
Website: http://fubegra.net/
Recently, a script-kiddie tool for brute forcing SSH passwords made its way into the wild. Early versions generally would make a few random attempts at logging into the root, admin, test, and guest accounts, choosing randomly from a list of 2000-odd "obvious" passwords.

I've seen an extended version of this hit a Linode that I manage for my employer, trying a variety of other accounts as well (such as people's names, webmaster, etc.), and failing.

This raises two issues:
1. Make sure that you do not use an "obvious" password for lish. It's almost inevitable that someone will try this tool against a Linode host box, if it hasn't already happened.

2. If you run sshd on your own Linode, use RSA or DSA key authentication only. You will need to generate a key pair, and place a copy of the public key into the user's $HOME/.ssh/authorized_keys file, and then set:

RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication no

in your sshd_config file (usually /etc/ssh/sshd_config). Keep your existing SSH session open, restart sshd, and test a new login using the RSA key.

Keep your private key PRIVATE! It is a good idea to protect it with a passphrase. You might want to keep a copy of it on a USB flash drive.

You can generate key pairs using ssh-keygen on a Linux/FreeBSD/other *nix/Cygwin installation, or with PuTTYgen if you use PuTTY on Windows.

edit: add PubkeyAuthentication

_________________
Bus error (passengers dumped)


Top
   
 Post subject:
PostPosted: Wed Mar 16, 2005 8:24 am 
Offline
Senior Member
User avatar

Joined: Tue Aug 17, 2004 11:37 pm
Posts: 262
Website: http://www.our-lan.com
WLM: nf@our-lan.com
Location: Brisbane, Australia
so.. on this note i found i had the same thing, so i wrote a perl script to handle this.. it needs a bit of work because it takes a while sometimes, but the shortversion is after 3 failed logins u get added to iptables drop.. the details for it are all here
http://www.our-lan.com/blog


Top
   
 Post subject:
PostPosted: Mon Mar 21, 2005 12:47 pm 
Offline
Senior Member
User avatar

Joined: Wed Mar 17, 2004 12:35 am
Posts: 118
Website: http://www.necrobones.com/
Location: Sterling, VA
Another band-aid fix you can do if you have a very small number of users is to run sshd on a non-standard port. This of course is not a fix, but for 99.99% of the attacks out there, it'll be effective, since these brute-force approaches look for the low-hanging fruit, and they're not going to take the time to do a complete port scan on every IP. Not yet, anyway...

_________________
----
Ed/Bones.


Top
   
 Post subject:
PostPosted: Mon Mar 21, 2005 1:02 pm 
Offline
Senior Member

Joined: Sun Nov 14, 2004 6:37 pm
Posts: 138
Website: http://oldos.org
WLM: jasonlfaulkner@hotmail.com
Yahoo Messenger: jasonfncsu
AOL: jaylfaulkner
Location: NC, USA
NecroBones wrote:
Another band-aid fix you can do if you have a very small number of users is to run sshd on a non-standard port. This of course is not a fix, but for 99.99% of the attacks out there, it'll be effective, since these brute-force approaches look for the low-hanging fruit, and they're not going to take the time to do a complete port scan on every IP. Not yet, anyway...


That's exactly what I do :)

_________________
Jay Faulkner
http://oldos.org


Top
   
 Post subject:
PostPosted: Mon Mar 21, 2005 4:01 pm 
Offline
Junior Member

Joined: Fri Aug 20, 2004 10:32 am
Posts: 38
Quote:
Another band-aid fix you can do if you have a very small number of users is to run sshd on a non-standard port. This of course is not a fix, but for 99.99% of the attacks out there, it'll be effective, since these brute-force approaches look for the low-hanging fruit, and they're not going to take the time to do a complete port scan on every IP. Not yet, anyway...


n00b question, but how can I set that up? Recommend any good tutorials, or any recommendations?

Thanks,
-Kevin


Top
   
 Post subject:
PostPosted: Mon Mar 21, 2005 4:26 pm 
Offline
Senior Member
User avatar

Joined: Fri Oct 24, 2003 3:51 pm
Posts: 965
Location: Netherlands
chapterthree wrote:
n00b question, but how can I set that up? Recommend any good tutorials, or any recommendations?

Edit /etc/ssh/sshd_config - change the value of the Port parameter, uncomment the Port statment if necessary and then restart the ssh daemon.

To connect, specify the -p portnum option for ssh, in addition to your normal options.

Choose a port number less than 1023, so that if sshd ever goes down, a user cannot start his own compromised version of ssh listening on your chosen port.

_________________
/ Peter


Top
   
 Post subject:
PostPosted: Mon Mar 21, 2005 4:40 pm 
Offline
Junior Member

Joined: Fri Aug 20, 2004 10:32 am
Posts: 38
Peter,

Thanks! I'll go set that up in a few.

One question, I assume this would affect how scp would work as well, correct? I noticed there is a -P (port) option for scp, so I would just need to do -P and the port number, is that correct?

[Follow up] So it appears to have worked, except when I connect to Lish. If I type 'ssh [username]@host34.linode.com' it connects fine. Any idea why that is?

Thanks
-Kevin


Top
   
 Post subject:
PostPosted: Mon Mar 21, 2005 4:58 pm 
Offline
Senior Member
User avatar

Joined: Fri Oct 24, 2003 3:51 pm
Posts: 965
Location: Netherlands
chapterthree wrote:
So it appears to have worked, except when I connect to Lish. If I type 'ssh [username]@host34.linode.com' it connects fine. Any idea why that is?

Lish is accessed via a separate instance of sshd running under the host kernel - so that Lish is still available to access your Linode's console even if you hose your ssh daemon. You have no control over which port the daemon running under the host kernel listens on (it's common to all Linodes on that host and controlled by caker).

_________________
/ Peter


Last edited by pclissold on Mon Mar 21, 2005 6:26 pm, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Mon Mar 21, 2005 5:02 pm 
Offline
Junior Member

Joined: Fri Aug 20, 2004 10:32 am
Posts: 38
Ahh, OK yeah that makes sense now :)

Thanks for your help!

-Kevin


Top
   
 Post subject:
PostPosted: Tue Mar 29, 2005 11:52 am 
Offline
Junior Member

Joined: Fri Aug 20, 2004 10:32 am
Posts: 38
As a follow up, I have started using a different port under 1023, but I think it's causing issues, as after a period of time, the connection seems to freeze, then time out. I'm thinking I might be using a port that is being used by something else. Anybody recommend a range of ports that are relatively safe to use without running the risk of being used by something else.

Thanks,
-Kevin


Top
   
 Post subject:
PostPosted: Tue Mar 29, 2005 12:06 pm 
Offline
Linode Staff
User avatar

Joined: Fri Oct 17, 2003 12:38 am
Posts: 287
Location: Dr Wierd's Lab, South Jersey Shore
Check out this link for an alternative. It uses the recent netfilter module which is installed in the Linode kernels. This limits ssh connection attempts to 3 per 60 secoond period without having effects on existing connections.

http://blog.andrew.net.au/2005/02/17


Top
   
 Post subject:
PostPosted: Tue Mar 29, 2005 12:24 pm 
Offline
Senior Member
User avatar

Joined: Fri Oct 24, 2003 3:51 pm
Posts: 965
Location: Netherlands
Try 203, 205, 207 & 208. The block from 201 to 208 inclusive is assigned to AppleTalk, and the four just listed are currently marked as unused by that protocol.

_________________
/ Peter


Top
   
 Post subject:
PostPosted: Tue Mar 29, 2005 8:32 pm 
Offline
Senior Member
User avatar

Joined: Tue Aug 17, 2004 11:37 pm
Posts: 262
Website: http://www.our-lan.com
WLM: nf@our-lan.com
Location: Brisbane, Australia
So im corious to know, if there is a way to makeip tables load certian rules on startup? cause i would like to implement the methods that were described in the link posted by mike

cheers
Nathan


Top
   
 Post subject:
PostPosted: Wed Mar 30, 2005 2:36 am 
Offline
Senior Member

Joined: Sun Jul 20, 2003 8:29 am
Posts: 100
Website: http://www.ipo-australia.com
Location: Tropical Queensland, Australia
You can put startup scripts in /etc/init.d or /etc/rc*.d.
LSB (linux standard base) is now /etc/init.d but redhat 9 uses /etc/rc*.d

Lish is very useful if your firewall locks you out :oops:


Top
   
 Post subject:
PostPosted: Wed Mar 30, 2005 2:51 am 
Offline
Linode Staff
User avatar

Joined: Fri Oct 17, 2003 12:38 am
Posts: 287
Location: Dr Wierd's Lab, South Jersey Shore
Here is a script based on the debian skeleton init.d script:

Code:
#! /bin/sh
#
# ssh-bruteforce
#
# Author:   Michael Greb <michael@thegrebs.com>.
#
# Version:      @(#)ssh-bruteforce  1.0  26-Mar-2005
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="iptables for ssh brute force mitigation"
NAME=ssh-bruteforce
SCRIPTNAME=/etc/init.d/$NAME


#
#       Function that starts the daemon/service.
#
d_start() {
    iptables -N SSH_WHITELIST
    iptables -A SSH_WHITELIST -s 70.187.46.105 -m recent --remove --name SSH -j ACCEPT
    iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH
    iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j SSH_WHITELIST
    iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update \
        --seconds 60 --hitcount 4 --rttl --name SSH -j ULOG --ulog-prefix SSH_brute_force
    iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update \
        --seconds 60 --hitcount 4 --rttl --name SSH -j DROP
}

case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;

  *)
        # echo "Usage: $SCRIPTNAME {start}" >&2
        echo "Usage: $SCRIPTNAME {start}" >&2
        exit 1
        ;;
esac

exit 0

This line:
Code:
iptables -A SSH_WHITELIST -s 70.187.46.105 -m recent --remove --name SSH -j ACCEPT

should be repeated as many times as you wish with the IP addresses you want whitelisted, or none if you don't wish to have any whitelisted. This script does not unload the iptables rules when asked


Last edited by mikegrb on Mon Jun 20, 2005 12:40 pm, edited 2 times in total.

Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: virneto and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group