By Jake Edge
October 24, 2007
Repeatedly trying to log in via ssh using multiple username/password
pairs, is a common attack against systems; it works often enough that
relatively unsophisticated attackers ("script kiddies") continue to try to
exploit it. As with most internet threats, this one, known as a brute
force ssh attack, rises and falls in popularity; it currently seems to be
on the upswing. There are a number of techniques that can be used to
reduce the effectiveness of this attack, starting with the most obvious:
pick good passwords.
These attacks cannot succeed, in any sensible length of time, if the passwords on all the accounts are
well-chosen, long, and contain a mix of numbers, upper and lower case, and
punctuation. Bruce Schneier has good
advice on choosing a password based on his research into passwords and
guessing algorithms. But it is difficult to ensure that all passwords on a
system conform or that some new guessing scheme doesn't happen to randomly hit
upon the same password a user chose. Because of that, other evasive measures
are often used.
One of the drawbacks to being subjected to a brute force attack is the
bandwidth and processing power needed to deal with the log in attempts, even if
unsuccessful. A simple way to avoid that, at least for most
unsophisticated attackers, is to simply run the ssh server at a port other
than 22. Legitimate users can be told what port to use, while unsophisticated attackers will
not find a server to connect to. An attacker using Nmap, or a similar port scanning
tool, will find the ssh server pretty quickly, though.
In a similar vein, port knocking hides
the server by only enabling it after getting a certain sequence of
connection requests. For example, a server could wait until it got a
connection to port 1037, followed by connections to 42 and 6666, in quick
succession from the same IP address, before it
would open up port 22 (or some other port to combine with the above) for ssh
traffic. After a timeout of a minute or so, the port would be closed down
again.
Both port knocking and changing the port rely on "security through
obscurity," which is no defense against a determined attacker, but may be just
fine to convince a script kiddie to move on to an easier target. Anyone who
has access to the traffic bound for the server, though, will be able to spot ssh to
a non-standard port as well as port knocking. To repel more sophisticated
attackers, who may be targeting specific hosts, rather than trawling, other
techniques can be used.
An effective countermeasure against repeated connections is to ban the
offending IP address for some period of time. There are several mechanisms
to do this, one of the most straightforward is to use iptables to
limit the number of ssh connections per minute to some small number. If a host
exceeds that limit, its IP address is not allowed to make ssh connections
for another minute. This slows down the traffic rather severely, but does
have some drawbacks: iptables cannot distinguish between
successful and unsuccessful log ins, so a fourth log in attempt would fail
even if the previous three had been successful.
Other tools, such as Fail2ban, monitor
the ssh server log file to determine if there are too many failures, based
on configurable criteria, from a given host and then modify firewall
or tcp_wrapper rules
to stop the offending host from connecting for some period of time. All of
the techniques that ban IP addresses are effective against hosts
that are used again and again. It is not inconceivable that a botnet could
be used to do a distributed brute force attack which, depending on how many
hosts were available and the timeouts on the server, might be very effective.
Perhaps the most secure solution of all is eliminating passwords entirely,
as long as the other endpoints are reasonably secured. The ssh server can
be configured to not allow password authentication, only accepting
connections from users that have their public key stored in the
authorized_keys file. An attacker that gets access to the
corresponding private key will have an easy entry to the host system, so
this technique must be used carefully.
Brute force attacks against ssh are more annoying than they are dangerous
generally, but they can lead to intrusions. An intrusion of even a regular
user account is only a privilege escalation bug away from being a complete
takeover of the system. It makes sense to monitor log files periodically to
determine if your host is being attacked and to take appropriate
countermeasures.
(For more details, see this article at the
samhain labs website.)
(
Log in to post comments)