Linux Netfilter discussions
 help / color / mirror / Atom feed
* Blocking all APNIC addresses vs. per-country list
@ 2010-04-26 14:09 Peter Zieseniss
  2010-04-26 14:19 ` Tim Evans
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Peter Zieseniss @ 2010-04-26 14:09 UTC (permalink / raw)
  To: netfilter

Hello All,

This is my first time posting; i am rather new to iptables, so please excuse the ignorance in my question.

My personal CentOS-based webhost is under constant ssh attack from an interminable list of different IP addresses (just to give you an idea, my latsb data file grows by ~100MB every week!!).
i've noticed that they all seem to come from East-Asia (mainly China, Taiwan, Malaysia, Korea--both).

i found this website which provides a list of IP addresses on a per-country basis:
http://ipinfodb.com/ip_country_block_iptables.php

it seems quite reliable, but the list, for just the countries above, is about 3700 lines long..
on the other hand, i found a list of just 40 lines for *all* of the APNIC countries (http://bgp.potaroo.net/ipv4-stats/allocated-apnic.html).

i'd rather use a per-country list so as to not block non-offending countries like Japan and Australia. Indeed, my Mom, Dad, and i use this webhost for our small businesses, and although we've never had interlocutors from APNIC countries, i'd rather not block Australia outright, just in case someone has their webhost there and tries to send us email...

My question, therefore, is this:
Is it wise to use a 4000-line long block-list for iptables? Or will doing so bring my server to a crawl (which it already is because of these darn brute-force ssh attacks) because for each TCP packet it has to spend 5 minutes going through the entire list?
Should i just forget about Australia and Japan, and block all APNIC countries with just a 40-line list instead?


Again, i apologize for the long, and probably lame question, but i would *greatly* appreciate any help you might provide..

Thank you in advance!
Be Well,
Peter




--

"My candle burns at both ends;
It will not last the night;
But ah, my foes, and oh, my friends
It gives a lovely light!"
 — Edna St. Vincent Millay

-- 

Peter Zieseniss
Principal
http://www.zconsulting.net
peter@zconsulting.net


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:09 Blocking all APNIC addresses vs. per-country list Peter Zieseniss
@ 2010-04-26 14:19 ` Tim Evans
  2010-04-26 14:19 ` Richard Horton
  2010-04-26 14:46 ` Покотиленко Костик
  2 siblings, 0 replies; 10+ messages in thread
From: Tim Evans @ 2010-04-26 14:19 UTC (permalink / raw)
  To: Peter Zieseniss; +Cc: netfilter


Peter Zieseniss wrote:

> My question, therefore, is this:
> Is it wise to use a 4000-line long block-list for iptables? Or will doing
> so bring my server to a crawl (which it already is because of these darn
> brute-force ssh attacks) because for each TCP packet it has to spend 5
> minutes going through the entire list?
> Should i just forget about Australia and Japan, and block all APNIC
> countries with just a 40-line list instead?

Why not use denyhosts? http://denyhosts.sourceforge.net/

Works with tcp wrapper; auto-updates /etc/hosts.deny; sends and accepts
new bad hosts back to the mothership.
-- 
Tim Evans, TKEvans.com, Inc.    |   5 Chestnut Court
UNIX System Admin Consulting    |   Owings Mills, MD 21117
http://www.tkevans.com/         |   443-394-3864
http://www.come-here.com/News/  |   tkevans@tkevans.com



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:09 Blocking all APNIC addresses vs. per-country list Peter Zieseniss
  2010-04-26 14:19 ` Tim Evans
@ 2010-04-26 14:19 ` Richard Horton
  2010-04-26 14:34   ` Pascal Hambourg
  2010-04-26 14:46 ` Покотиленко Костик
  2 siblings, 1 reply; 10+ messages in thread
From: Richard Horton @ 2010-04-26 14:19 UTC (permalink / raw)
  To: Peter Zieseniss; +Cc: netfilter

On 26 April 2010 15:09, Peter Zieseniss <peter@zconsulting.net> wrote:
> Hello All,
>
> This is my first time posting; i am rather new to iptables, so please excuse the ignorance in my question.
>
> My personal CentOS-based webhost is under constant ssh attack from an interminable list of different IP addresses (just to give you an idea, my latsb data file grows by ~100MB every week!!).
> i've noticed that they all seem to come from East-Asia (mainly China, Taiwan, Malaysia, Korea--both).
>

A better option would be to drop ssh connections if the number of
attempts from a single ip address exceedes an acceptable limit (say
1/min - can't see many legit uses for ssh where you you connect and
disconnect multiple times within a 1 minute window)

This can be done using either hashlimit or the recent matches...

Would put an example in but need to go give my presentation at work
soon so will send one if you need it.
-- 
Richard Horton
Users are like a virus: Each causing a thousand tiny crises until the
host finally dies.
http://www.pbase.com/arimus - My online photogallery
http://www.topcashback.co.uk/ref/rhorton

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:19 ` Richard Horton
@ 2010-04-26 14:34   ` Pascal Hambourg
  2010-04-26 14:51     ` Roman Fiedler
  2010-04-26 15:09     ` Покотиленко Костик
  0 siblings, 2 replies; 10+ messages in thread
From: Pascal Hambourg @ 2010-04-26 14:34 UTC (permalink / raw)
  To: netfilter

Hello,

Richard Horton a écrit :
> 
> A better option would be to drop ssh connections if the number of
> attempts from a single ip address exceedes an acceptable limit

Preferably the number of *failed* attempts. That's what fail2ban and the
like do.

> can't see many legit uses for ssh where you you connect and
> disconnect multiple times within a 1 minute window)

What about scp ?

> This can be done using either hashlimit or the recent matches...

They don't know about failed attemps.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:09 Blocking all APNIC addresses vs. per-country list Peter Zieseniss
  2010-04-26 14:19 ` Tim Evans
  2010-04-26 14:19 ` Richard Horton
@ 2010-04-26 14:46 ` Покотиленко Костик
  2010-04-26 15:54   ` Jan Engelhardt
  2 siblings, 1 reply; 10+ messages in thread
From: Покотиленко Костик @ 2010-04-26 14:46 UTC (permalink / raw)
  To: Peter Zieseniss; +Cc: netfilter

В Пнд, 26/04/2010 в 16:09 +0200, Peter Zieseniss пишет:
> Hello All,
> 
> This is my first time posting; i am rather new to iptables, so please excuse the ignorance in my question.
> 
> My personal CentOS-based webhost is under constant ssh attack from an interminable list of different IP addresses (just to give you an idea, my latsb data file grows by ~100MB every week!!).
> i've noticed that they all seem to come from East-Asia (mainly China, Taiwan, Malaysia, Korea--both).
> 
> i found this website which provides a list of IP addresses on a per-country basis:
> http://ipinfodb.com/ip_country_block_iptables.php
> 
> it seems quite reliable, but the list, for just the countries above, is about 3700 lines long..
> on the other hand, i found a list of just 40 lines for *all* of the APNIC countries (http://bgp.potaroo.net/ipv4-stats/allocated-apnic.html).
> 
> i'd rather use a per-country list so as to not block non-offending countries like Japan and Australia. Indeed, my Mom, Dad, and i use this webhost for our small businesses, and although we've never had interlocutors from APNIC countries, i'd rather not block Australia outright, just in case someone has their webhost there and tries to send us email...
> 
> My question, therefore, is this:
> Is it wise to use a 4000-line long block-list for iptables? Or will doing so bring my server to a crawl (which it already is because of these darn brute-force ssh attacks) because for each TCP packet it has to spend 5 minutes going through the entire list?
> Should i just forget about Australia and Japan, and block all APNIC countries with just a 40-line list instead?
> 
> 
> Again, i apologize for the long, and probably lame question, but i would *greatly* appreciate any help you might provide..

Regarding big number of iptables rules, it is better to use ipset to
this kind of rules because it uses hashing. And this is in case you
really need such big number of rules.

Regarding ssh and Brute-force attacks to other services, there is better
way to avoid that wothout using huge number of rules.

Personally I limit POP and IMAP to only allow 2 connections from
particular IP. This is not good idea for SSH, because you should be able
to have as many sessions open as you want. So I limit number of new SSH
connection to 5 per minute. This way I can open 5 connection imediatelly
and then 1/minute. This is acceptable to me, but not for brute-force.

This is my rules:

# Blocking Brute-force attacks on Cyrus POP and IMAP by limiting number
of connections to 2
-p tcp --dport 110 -m state --state NEW -m connlimit --connlimit-above 2
-j DROP
-p tcp --dport 143 -m state --state NEW -m connlimit --connlimit-above 2
-j DROP

# Blocking Brute-force SSH attacks, limiting connection speed to 5 per
minute
-p tcp --dport 22 -m state --state NEW -m hashlimit --hashlimit-mode
srcip --hashlimit-name LIM_SSH --hashlimit-above 5/minute -j DROP

Brute-forces try to open as many connection as they can, and when they
get very slow because of those rules they give up.

-- 
Покотиленко Костик <casper@meteor.dp.ua>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:34   ` Pascal Hambourg
@ 2010-04-26 14:51     ` Roman Fiedler
  2010-04-26 15:10       ` Покотиленко Костик
  2010-04-26 15:09     ` Покотиленко Костик
  1 sibling, 1 reply; 10+ messages in thread
From: Roman Fiedler @ 2010-04-26 14:51 UTC (permalink / raw)
  To: Pascal Hambourg; +Cc: netfilter

Hello list,

Besides connection limits, shouldn't it be possible to place the various
subnet rules in a sort of balanced/optimized tree to decrease the access
time? Are there tools available for that, that use e.g. the DROP log
entries from an unbalanced list to optimize the tree (like
huffman-encoding for data streams)? Can ipset do that?

Roman

-- 
Roman Fiedler
Safety & Security Department
Information Management & eHealth

AIT Austrian Institute of Technology GmbH
Reininghausstrafle 13/1  |  8020 Graz  |  Austria
T +43(0) 316 586570-63  |  M +43(0) 664 8251194  |  F +43(0) 316 586570-12
roman.fiedler@ait.ac.at <mailto:roman.fiedler@ait.ac.at> |
http://www.ait.ac.at <http://www.ait.ac.at/>
http://www.ait.ac.at/eHealth/ <http://www.ait.ac.at/eHealth/>

FN: 115980 i HG Wien  |  UID: ATU14703506
This email and any attachments thereto, is intended only for use by the
addressee(s) named herein and may contain legally privileged and/or
confidential information. If you are not the intended recipient, please
notify the sender by return e-mail or by telephone and delete this
message from your system and any printout thereof. Any unauthorized use,
reproduction, or dissemination of this message is strictly prohibited.
Please note that e-mails are susceptible to change. AIT Austrian
Institute of Technology GmbH shall not be liable for the improper or
incomplete transmission of the information contained in this
communication, nor shall it be liable for any delay in its receipt.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:34   ` Pascal Hambourg
  2010-04-26 14:51     ` Roman Fiedler
@ 2010-04-26 15:09     ` Покотиленко Костик
  2010-04-26 16:14       ` Jan Engelhardt
  1 sibling, 1 reply; 10+ messages in thread
From: Покотиленко Костик @ 2010-04-26 15:09 UTC (permalink / raw)
  To: netfilter

В Пнд, 26/04/2010 в 16:34 +0200, Pascal Hambourg пишет:
> Hello,
> 
> Richard Horton a écrit :
> > 
> > A better option would be to drop ssh connections if the number of
> > attempts from a single ip address exceedes an acceptable limit
> 
> Preferably the number of *failed* attempts. That's what fail2ban and the
> like do.
> 
> > can't see many legit uses for ssh where you you connect and
> > disconnect multiple times within a 1 minute window)
> 
> What about scp ?

Regarding my rules multiple sequential scp attempt will get slow, but
sftp won't.

> > This can be done using either hashlimit or the recent matches...
> 
> They don't know about failed attemps.

And this might be not needed. Fail2ban is more specific solution but
also is more complex and heavy. In my enviroment I haven't been feeling
iptables is insuficient and I need fail2ban, nevertheless, it should be
considered in other enviroments.

-- 
Покотиленко Костик <casper@meteor.dp.ua>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:51     ` Roman Fiedler
@ 2010-04-26 15:10       ` Покотиленко Костик
  0 siblings, 0 replies; 10+ messages in thread
From: Покотиленко Костик @ 2010-04-26 15:10 UTC (permalink / raw)
  To: netfilter

В Пнд, 26/04/2010 в 16:51 +0200, Roman Fiedler пишет:
> Hello list,
> 
> Besides connection limits, shouldn't it be possible to place the various
> subnet rules in a sort of balanced/optimized tree to decrease the access
> time? Are there tools available for that, that use e.g. the DROP log
> entries from an unbalanced list to optimize the tree (like
> huffman-encoding for data streams)? Can ipset do that?

http://ipset.netfilter.org/features.html

I'm not familiar with huffman-encoding, but it seems ipset can store IPs
in hashes and trees (with timeout), but NETs are only possible in hash.

Not to say that there is an automatic tool for that, but you can make
any kind of tree with just iptables' user defined CHAINs. It could
probably be slow on insert/delete but definitelly fast on lookup.

If the performance is the point and hight number of rules is the need
one can also look at hipac, didn't tried it myself.

-- 
Покотиленко Костик <casper@meteor.dp.ua>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 14:46 ` Покотиленко Костик
@ 2010-04-26 15:54   ` Jan Engelhardt
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Engelhardt @ 2010-04-26 15:54 UTC (permalink / raw)
  To: Покотиленко Костик
  Cc: Peter Zieseniss, netfilter


On Monday 2010-04-26 16:46, Покотиленко Костик wrote:
>В Пнд, 26/04/2010 в 16:09 +0200, Peter Zieseniss пишет:
>> Hello All,
>> 
>> This is my first time posting; i am rather new to iptables, so please excuse the ignorance in my question.
>> 
>> My personal CentOS-based webhost is under constant ssh attack from an interminable list of different IP addresses (just to give you an idea, my latsb data file grows by ~100MB every week!!).
>> i've noticed that they all seem to come from East-Asia (mainly China, Taiwan, Malaysia, Korea--both).
>> 
>> i found this website which provides a list of IP addresses on a per-country basis:
>> http://ipinfodb.com/ip_country_block_iptables.php\

Easier to use xt_geoip from xtables-addons. It's also just one rule;
though not a hashmap, it's a bisecting search, which is reasonably
fast (13 compare-steps for the IP-heaviest country like USA).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Blocking all APNIC addresses vs. per-country list
  2010-04-26 15:09     ` Покотиленко Костик
@ 2010-04-26 16:14       ` Jan Engelhardt
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Engelhardt @ 2010-04-26 16:14 UTC (permalink / raw)
  To: Покотиленко Костик
  Cc: netfilter


On Monday 2010-04-26 17:09, Покотиленко Костик wrote:
>В Пнд, 26/04/2010 в 16:34 +0200, Pascal Hambourg пишет:
>> Hello,
>> 
>> Richard Horton a écrit :
>> > 
>> > A better option would be to drop ssh connections if the number of
>> > attempts from a single ip address exceedes an acceptable limit
>> 
>> Preferably the number of *failed* attempts. That's what fail2ban and the
>> like do.
>> 
>> > can't see many legit uses for ssh where you you connect and
>> > disconnect multiple times within a 1 minute window)
>> 
>> What about scp ?
>
>Regarding my rules multiple sequential scp attempt will get slow, but
>sftp won't.

scp is a little slow itself, nor does it copy attributes well. Use rsync
where available.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-04-26 16:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-26 14:09 Blocking all APNIC addresses vs. per-country list Peter Zieseniss
2010-04-26 14:19 ` Tim Evans
2010-04-26 14:19 ` Richard Horton
2010-04-26 14:34   ` Pascal Hambourg
2010-04-26 14:51     ` Roman Fiedler
2010-04-26 15:10       ` Покотиленко Костик
2010-04-26 15:09     ` Покотиленко Костик
2010-04-26 16:14       ` Jan Engelhardt
2010-04-26 14:46 ` Покотиленко Костик
2010-04-26 15:54   ` Jan Engelhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox