LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   How to block IP range of China Russia and other countries. (https://www.linuxquestions.org/questions/linux-security-4/how-to-block-ip-range-of-china-russia-and-other-countries-816189/)

rahilmaknojia 06-24-2010 03:11 PM

How to block IP range of China Russia and other countries.
 
My server was attacked by china, russia, and from other countries via ssh. I use ssh from other part of the network like internet to access my home server. I just want to know how to add ip range of other country in hosts.deny file.

mpapet 06-24-2010 03:49 PM

Think Again.
 
Does "attack" mean successfully logged into your server? Or, does it mean script kiddies banging away at ssh with a dictionary attack and never getting in. If it's the latter, it never ends.

If you really want to block IP's then the firewall is the better place to implement this. Iptables has everything you need.

Maybe you should consider switching to PKI authentication for ssh? 'Easier' solutions are changing the port ssh listens on and using strong passwords.

unixfool 06-24-2010 04:13 PM

Quote:

Originally Posted by mpapet (Post 4013992)
Does "attack" mean successfully logged into your server? Or, does it mean script kiddies banging away at ssh with a dictionary attack and never getting in. If it's the latter, it never ends.

If you really want to block IP's then the firewall is the better place to implement this. Iptables has everything you need.

Maybe you should consider switching to PKI authentication for ssh? 'Easier' solutions are changing the port ssh listens on and using strong passwords.

The OP should elaborate but it seems like he's hinting at brute force attempts, which is NOT scanning, no matter how automated it is and no matter if its script-kiddie-ish. They key words you used were "dictionary attack".

Scanning is one thing. Attacking is another. We all interpret things differently, but those bruteforce attempts are actual login attempts (and nothing like nmap scanning [not saying that that's condoned, either])...

He can block this via the sshd config file, use denyhosts or any other host-level autoblocking tool, or even use a local (or network) firewall. All of this and more is covered in the "SSH" sticky thread at the top of the security forums.

win32sux 06-24-2010 05:14 PM

Quote:

Originally Posted by rahilmaknojia (Post 4013958)
My server was attacked by china, russia, and from other countries via ssh. I use ssh from other part of the network like internet to access my home server. I just want to know how to add ip range of other country in hosts.deny file.

Also, if you're willing to consider using iptables instead, I posted one possible approach here. If you still want to use hosts.deny, tweaking my instructions should be a snap. Personally, I'd stick to iptables, as it ensures that your SSH daemon never sees any packets from those IPs – at all.

Noway2 06-24-2010 08:06 PM

This page may be of interest to the OP and contains a list of IP ranges for the regions with the highest level of malicious traffic. http://www.countryipblocks.net/

Personally, I think that blocking such ranges in an attempt to gain security is a futile effort at best. While you may cut down on some of the noise traffic, the only thing you will accomplish is to guarantee is that whoever gains access to your system either originates from or proxies through a different region.

You efforts would be MUCH better spent securing your system against ALL attacks. The previous posts in this thread have already given you the tools on how to do this.

win32sux 06-24-2010 08:33 PM

Quote:

Originally Posted by Noway2 (Post 4014203)
You efforts would be MUCH better spent securing your system against ALL attacks.

Excellent point. Of course, blocking IP ranges which you know you'll never be accessing from (and from which you're seeing attacks) is still a good idea, and shouldn't be discarded (whether it's part of a broader approach or not). Hopefully when the OP replies we'll get a feel for how much effort he is willing to dedicate into hardening his SSH daemon. I'm also looking forward to his responses to the requests for clarification he received here, as this could possibly be a compromised machine we're dealing with, which would change everything.

rahilmaknojia 06-25-2010 08:13 AM

Quote:

Originally Posted by unixfool (Post 4014014)
The OP should elaborate but it seems like he's hinting at brute force attempts, which is NOT scanning, no matter how automated it is and no matter if its script-kiddie-ish. They key words you used were "dictionary attack".

Scanning is one thing. Attacking is another. We all interpret things differently, but those bruteforce attempts are actual login attempts (and nothing like nmap scanning [not saying that that's condoned, either])...

He can block this via the sshd config file, use denyhosts or any other host-level autoblocking tool, or even use a local (or network) firewall. All of this and more is covered in the "SSH" sticky thread at the top of the security forums.

Unixfool, I am also using denyhosts to block login attempt more then 3 time. But I didn't block ssh in denyhosts file because it blocks all the ip addresses. I don't want to block ip address from where I work. Last time it my server at home blocked ip address of my company where I work, and I wasn't able to get in until I stop denyhost service and remove that ip address from hosts.deny file.

Guys, I also configured iptable as it was shown on this discussion and let see how it works. One more question how to check if iptables drops the packet to responed incoming attack?

unixfool 06-25-2010 08:38 AM

Quote:

Originally Posted by rahilmaknojia (Post 4014713)
Last time it my server at home blocked ip address of my company where I work, and I wasn't able to get in until I stop denyhost service and remove that ip address from hosts.deny file.

There is a whitelist option that you can use to prevent this.

Quote:

Originally Posted by rahilmaknojia (Post 4014713)
Guys, I also configured iptable as it was shown on this discussion and let see how it works. One more question how to check if iptables drops the packet to responed incoming attack?

I haven't seen the iptables config (yet) but you can configure the firewall to log THEN drop. It should record the logs in your syslog (or where ever you're telling it to log).

rahilmaknojia 06-25-2010 09:08 AM

Quote:

Originally Posted by unixfool (Post 4014745)
There is a whitelist option that you can use to prevent this.

What is white list?

unixfool 06-25-2010 09:19 AM

It is a listing of IPs that should not be blocked by denyhosts.

rahilmaknojia 06-25-2010 09:28 AM

Quote:

Originally Posted by unixfool (Post 4014776)
It is a listing of IPs that should not be blocked by denyhosts.

Okay, and how do I set that up?

unixfool 06-25-2010 10:53 AM

Quote:

Originally Posted by rahilmaknojia (Post 4014784)
Okay, and how do I set that up?

http://denyhosts.sourceforge.net/faq.html#3_7

rahilmaknojia 06-25-2010 12:51 PM

Quote:

Originally Posted by unixfool (Post 4014851)

Okay, I created file in /use/share/denyhosts/data/allowed.hosts and I added some ip addresses to allow. But I want to know if I have to do anything else in denyhosts configuration file?

unixfool 07-29-2010 09:46 AM

Quote:

Originally Posted by rahilmaknojia (Post 4014979)
Okay, I created file in /use/share/denyhosts/data/allowed.hosts and I added some ip addresses to allow. But I want to know if I have to do anything else in denyhosts configuration file?

Just seeing this now.

I suggest reading the whole FAQ, then maybe googling denyhosts to determine how others are using it and how others are configuring it....visiting the denyhosts webpage should be enough, though.

wertum 08-03-2010 03:39 AM

Quote:

Originally Posted by rahilmaknojia (Post 4013958)
My server was attacked by china, russia, and from other countries via ssh. I use ssh from other part of the network like internet to access my home server. I just want to know how to add ip range of other country in hosts.deny file.

FULL ANSWER :
linux .opennet .ru /tips /info/ 1969.shtml

GO TO TRANSLATE.GOOGLE.COM


All times are GMT -5. The time now is 04:14 PM.