Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sun Nov 27, 2011 5:32 pm 
Offline
Senior Newbie

Joined: Sat Nov 19, 2011 11:58 pm
Posts: 5
Came across the following in my iptables Fail2ban SSH chain:

Code:
 
pkts bytes target     prot opt in     out     source               destination
   18  1180 DROP       all  --  any    any     .                    anywhere


And the log that triggered it:

Code:
Nov 27 12:07:54 ex sshd[29759]: reverse mapping checking getaddrinfo for . [31.210.109.31] failed - POSSIBLE BREAK-IN ATTEMPT!
Nov 27 12:07:54 ex sshd[29759]: User root from 31.210.109.31 not allowed because not listed in AllowUsers
Nov 27 12:07:54 ex sshd[29760]: input_userauth_request: invalid user root
Nov 27 12:07:54 ex sshd[29760]: Received disconnect from 31.210.109.31: 11: Bye Bye


I'm curious as to whether Fail2ban could lock me out of SSH completely if someone were to put "ANY" instead of "." in the above entry, or are there safeguards against this in Fail2ban to handle particular types of injection. I'm running on the default installation of Fail2ban outside of changes in detection time and number of attempts.


Top
   
 Post subject:
PostPosted: Sun Nov 27, 2011 6:38 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
No, the IP must be resolved as valid before sshd or any higher level protocol (higher than TCP three-way connection handshake) would log invalid attempts and thus reach fail2ban.

Then again YOU yourself could lock yourself out rather easily if you're not careful and have very strict banning rules. :)


Top
   
 Post subject:
PostPosted: Sun Nov 27, 2011 7:23 pm 
Offline
Senior Newbie

Joined: Sat Nov 19, 2011 11:58 pm
Posts: 5
Azathoth wrote:
No, the IP must be resolved as valid before sshd or any higher level protocol (higher than TCP three-way connection handshake) would log invalid attempts and thus reach fail2ban.

Then again YOU yourself could lock yourself out rather easily if you're not careful and have very strict banning rules. :)


Thanks for the quick reply and info! Maybe I'm not understanding it correctly, but the entries above are from my Linode in iptables and the log file, so wouldn't that mean the request is successfully getting through?

It seems like the attacker could alter whatever is being used to produce a log entry as follows:

Code:
Nov 27 12:07:54 ex sshd[29759]: reverse mapping checking getaddrinfo for anywhere [31.210.109.31] failed - POSSIBLE BREAK-IN ATTEMPT!
Nov 27 12:07:54 ex sshd[29759]: User root from 31.210.109.31 not allowed because not listed in AllowUsers
Nov 27 12:07:54 ex sshd[29760]: input_userauth_request: invalid user root
Nov 27 12:07:54 ex sshd[29760]: Received disconnect from 31.210.109.31: 11: Bye Bye


Assuming Fail2ban behaves as expected, it would produce an iptables entry as follows:

Code:
pkts bytes target     prot opt in     out     source               destination
   18  1180 DROP       all  --  any    any     anywhere               anywhere


Which would effectively block SSH access from everywhere, correct?


Top
   
 Post subject:
PostPosted: Sun Nov 27, 2011 8:16 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
Tayne wrote:
It seems like the attacker could alter whatever is being used to produce a log entry as follows:


Where did you get that idea? The remote IP address comes from your network stack, it is part of teh TCP packet, and at this point (after three-way handshake of the TCP, after established connection to ssh and username sent to it) it cannot be spoofed.

So no, the "attacker" cannot alter whatever is being used to produce the logs.


Quote:
Which would effectively block SSH access from everywhere, correct?


Incorrect. The "any" is just what you see with iptables -L. The actual chain rule, the one given by fail2ban, includes the IP address fail2ban reads from teh logs, using a regex meaning it has to be a valid IP address.


Top
   
 Post subject:
PostPosted: Sun Nov 27, 2011 9:09 pm 
Offline
Senior Newbie

Joined: Sat Nov 19, 2011 11:58 pm
Posts: 5
Makes sense now! I was under the impression that the iptables rule was dropping traffic from what's listed under the 'source' column when using iptables -L, but that command doesn't reveal all the information available. Thanks for the help!


Top
   
 Post subject:
PostPosted: Mon Nov 28, 2011 5:25 am 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
Tayne wrote:
I was under the impression that the iptables rule was dropping traffic from what's listed under the 'source' column when using iptables -L


But it is, and shows "any" if no specific host is set.

Except you can't tell iptables to drop from "anywhere" (or "any") by that word in place of -s flag for remote IP. I mean, you can but iptables would think that's a host name, not "anywhere" as in "any source".

Code:
#> iptables -A INPUT -s anywhere -j DROP
iptables v1.4.10: host/network `anywhere' not found
Try `iptables -h' or 'iptables --help' for more information.

#> iptables -A INPUT -s any -j DROP
iptables v1.4.10: host/network `any' not found
Try `iptables -h' or 'iptables --help' for more information.


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


Who is online

Users browsing this forum: No registered users 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