Tightening SSH access

This is a discussion on Tightening SSH access within the Linux Security forums, part of the System Security and Security Related category; Hi, Is there a way to configure SSH + iptables such that it only accepts logins coming from our machines? Ideally, ...


Go Back   Usenet Forums > System Security and Security Related > Linux Security

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-08-2005
Carlos Moreno
 
Posts: n/a
Default Tightening SSH access


Hi,

Is there a way to configure SSH + iptables such that it only accepts
logins coming from our machines? Ideally, the access should require
password (i.e., a Unix login password) + public-key verification (only
our keys would be accepted by SSH) + verification (via MAC) that it
comes from our machines (our IP is not static, so using the source
IP to validate would be risky). Is it possible?

In the iptables tutorial I have, they mention that the MAC-based
match support is not quite solid. I'm not sure if that still holds.

I'm thinking of a rule like:

iptables -P INPUT DROP
.... (other rules)
iptables -A INPUT \
-p tcp --syn --dport 22 -m mac --mac-source <MAC> -j ACCEPT


Also from the sshd_config man pages, it looks to me like authentication
can be made based on public-key OR password-based, but not both; I'd
like SSH to verify that the connection comes from the owner of the
authorized key-pair but ALSO require the client to type in a login
name and password to allow access. Is it possible?

Thanks,

Carlos
--
Reply With Quote
  #2 (permalink)  
Old 07-08-2005
Keith Keller
 
Posts: n/a
Default Re: Tightening SSH access

On 2005-07-08, Carlos Moreno <moreno_at_mochima_dot_com@xx.xxx> wrote:
>
> Is there a way to configure SSH + iptables such that it only accepts
> logins coming from our machines? Ideally, the access should require
> password (i.e., a Unix login password) + public-key verification (only
> our keys would be accepted by SSH) + verification (via MAC) that it
> comes from our machines (our IP is not static, so using the source
> IP to validate would be risky). Is it possible?


I can't speak to all of your concerns, but MACs are spoofable, and in
theory anyone on the local network should be able to sniff your MAC.
That being said,

> In the iptables tutorial I have, they mention that the MAC-based
> match support is not quite solid. I'm not sure if that still holds.


I think MAC-based matching is reasonably good in recent kernels. I've
been using it for some of my boxes, and it seems to work fine.

--keith

--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information

Reply With Quote
  #3 (permalink)  
Old 07-08-2005
Sensei
 
Posts: n/a
Default Re: Tightening SSH access

Carlos Moreno wrote:
> In the iptables tutorial I have, they mention that the MAC-based
> match support is not quite solid. I'm not sure if that still holds.
>
> I'm thinking of a rule like:
>
> iptables -P INPUT DROP
> .... (other rules)
> iptables -A INPUT \
> -p tcp --syn --dport 22 -m mac --mac-source <MAC> -j ACCEPT


Yes, you can leave open the port 22 (ssh) rejecting all incoming traffic
except those MAC addresses that you know.

> Also from the sshd_config man pages, it looks to me like authentication
> can be made based on public-key OR password-based, but not both; I'd
> like SSH to verify that the connection comes from the owner of the
> authorized key-pair but ALSO require the client to type in a login
> name and password to allow access. Is it possible?


Use ssh/iptables, and you can do whatever you want, but be warned...
even MAC addresses are not 100% safe. Use the keys and use a non-blank
passphrase if you want user interaction.
Reply With Quote
  #4 (permalink)  
Old 07-09-2005
Carlos Moreno
 
Posts: n/a
Default Re: Tightening SSH access

Sensei wrote:

> Use ssh/iptables, and you can do whatever you want, but be warned...
> even MAC addresses are not 100% safe.


Thanks, Sensei and Keith for your messages.

Yes, I actually was aware that MACs are spoofable; but it still can
work for us (I think), as I suspect that the attacks I'm seeing in
the logs come from completely unrelated/remote sites.

The attacks I'm referring to are several hundred attempts to log in
(several hundreds each day -- today, for instance, I see 967 failed
attempts to log in through SSH -- most of them with user accounts
that do not exist on our servers; that makes me think that it is
a dictionary-like attack, as opposed to someone that may have
sniffed our network, in which case they might be able to do a more
precise attack)

Thanks!

Carlos
--
Reply With Quote
  #5 (permalink)  
Old 07-09-2005
Bill Marcum
 
Posts: n/a
Default Re: Tightening SSH access

On Fri, 08 Jul 2005 17:28:30 -0400, Carlos Moreno
<moreno_at_mochima_dot_com@xx.xxx> wrote:
>
>
> Also from the sshd_config man pages, it looks to me like authentication
> can be made based on public-key OR password-based, but not both; I'd
> like SSH to verify that the connection comes from the owner of the
> authorized key-pair but ALSO require the client to type in a login
> name and password to allow access. Is it possible?
>

Why not use public key with a passphrase?


--
Tonight you will pay the wages of sin; Don't forget to leave a tip.
Reply With Quote
  #6 (permalink)  
Old 07-09-2005
Tony Lawrence
 
Posts: n/a
Default Re: Tightening SSH access

Bill Marcum wrote:
> On Fri, 08 Jul 2005 17:28:30 -0400, Carlos Moreno
> <moreno_at_mochima_dot_com@xx.xxx> wrote:
>
>>
>>Also from the sshd_config man pages, it looks to me like authentication
>>can be made based on public-key OR password-based, but not both; I'd
>>like SSH to verify that the connection comes from the owner of the
>>authorized key-pair but ALSO require the client to type in a login
>>name and password to allow access. Is it possible?
>>

>
> Why not use public key with a passphrase?
>
>


Exactly. See http://aplawrence.com/Security/sshpassphrases.html for a
short guide to setting it up.

--
Tony Lawrence
Unix/Linux/Mac OS X resources: http://aplawrence.com
Reply With Quote
  #7 (permalink)  
Old 07-09-2005
Carlos Moreno
 
Posts: n/a
Default PermitRootLogin (was: Re: Tightening SSH access)


I just tried configuring one of the servers to disallow root login.

One problem/weakness I noticed is that even though the login is
ultimately refused, typing the correct password and typing an
incorrect password produce different behaviours.

This is indeed a weakness, I believe, as it discloses the fact that
you got the correct password (I know that guessing the root password
should be extremely unlikely, but these are the odds that they're
playing when brute-forcely attempting to login as root, right?)

IMHO, if the server must wait until the time to refuse login, then
it should refuse it in the exact same way. A better solution, of
course, would be that as soon as root is entered as user name, it
should immediately close the connection (without even saying
goodbye). This could be done for the special case of root (but
perhaps not for the other users, as that would allow attackers to
know when they got a correct username).

Comments? (time to write to the OpenSSH guys with this feature
request? Or has this been addressed in the past?)

Thanks! And thanks to all that have replied so far!

Carlos
--
Reply With Quote
  #8 (permalink)  
Old 07-09-2005
Stephen Webster
 
Posts: n/a
Default Re: PermitRootLogin

Carlos Moreno wrote:
>
> I just tried configuring one of the servers to disallow root login.
>
> One problem/weakness I noticed is that even though the login is
> ultimately refused, typing the correct password and typing an
> incorrect password produce different behaviours.
>


What version of ssh are you running? I have openssh v4.0p1 running on a
Fedora core 4 box and I get the same behaviour whether I use the correct
password or an incorrect password for root:

"Permission denied, please try again."

Regards,
Steve Webster
Reply With Quote
  #9 (permalink)  
Old 07-09-2005
Grant Coady
 
Posts: n/a
Default Re: PermitRootLogin (was: Re: Tightening SSH access)

On Sat, 09 Jul 2005 11:50:19 -0400, Carlos Moreno <moreno_at_mochima_dot_com@xx.xxx> wrote:
>
> Comments? (time to write to the OpenSSH guys with this feature
> request? Or has this been addressed in the past?)


1. Disable root ssh logins, login as user then 'su -' to root account,
this creates two hurdles for an attacker, likely to move on as soon
as they discover no root login permitted.

2. Restrict (if possible) ssh logins to known IP addresses.

Attackers look for easy targets, I don't see any ssh login attempts
logged from remotes as I use the second option. Casual ssh probes
are dropped at the firewall.

--Grant.

Reply With Quote
  #10 (permalink)  
Old 07-09-2005
Carlos Moreno
 
Posts: n/a
Default Re: PermitRootLogin

Stephen Webster wrote:
> Carlos Moreno wrote:
>
>>
>> I just tried configuring one of the servers to disallow root login.
>>
>> One problem/weakness I noticed is that even though the login is
>> ultimately refused, typing the correct password and typing an
>> incorrect password produce different behaviours.
>>

>
> What version of ssh are you running? I have openssh v4.0p1 running on a
> Fedora core 4 box and I get the same behaviour whether I use the correct
> password or an incorrect password for root:
>
> "Permission denied, please try again."


D'oh!! I think it's 3.5 -- it's the one that comes with RH9, with the
latest updates applied, but still an old version.

Glad to hear that this detail has been fixed!

Thanks,

Carlos
--
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:43 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0