From: "Покотиленко Костик" <casper@meteor.dp.ua>
To: Peter Zieseniss <peter@zconsulting.net>
Cc: netfilter@vger.kernel.org
Subject: Re: Blocking all APNIC addresses vs. per-country list
Date: Mon, 26 Apr 2010 17:46:58 +0300 [thread overview]
Message-ID: <1272293218.3750.15.camel@casper.meteor.dp.ua> (raw)
In-Reply-To: <0414A4FA-32F4-4D94-92E0-FC5CC9B4D646@zconsulting.net>
В Пнд, 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>
next prev parent reply other threads:[~2010-04-26 14:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Покотиленко Костик [this message]
2010-04-26 15:54 ` Jan Engelhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1272293218.3750.15.camel@casper.meteor.dp.ua \
--to=casper@meteor.dp.ua \
--cc=netfilter@vger.kernel.org \
--cc=peter@zconsulting.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox