LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 01-20-2006, 12:31 AM   #1
~=gr3p=~
Member
 
Registered: Feb 2005
Location: ~h3av3n~
Distribution: RHEL 4, Fedora Core 3,6,7 Centos 5, Ubuntu 7.04
Posts: 227

Rep: Reputation: 30
Ban IP's of certain countries


Everyday i get huge log file of some idiots trying to use random SSH username/password login on my server & probably a DoS attack. I have clients located in US who SFTP to my srever to download files.

I have setup SSH the following way:

1) chrooted SFTP login only
2) Allow authorized users only with " ALlowUsers" keyword in /etc/ssh/sshd_config
3) No root login
4) Protocol 2 only
5) Listen on 0.0.0.0

I only have to allow connection from outside to my SSH port 22 in my iptables other all other NEW connections are DROP in my firewall.

How do stop this. change port 22 to another port?

here is part of my log. Most of the source IP's are from China:

Quote:
Failed password for invalid user telnetd from 61.129.64.93 port 43254 ssh2
Invalid user telnetd from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user telnetd from 61.129.64.93 port 43271 ssh2
Invalid user toor from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user toor from 61.129.64.93 port 43293 ssh2
Invalid user toor from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user toor from 61.129.64.93 port 43317 ssh2
Invalid user toor from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user toor from 61.129.64.93 port 43338 ssh2
Invalid user toor from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user toor from 61.129.64.93 port 43363 ssh2
Invalid user toor from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user toor from 61.129.64.93 port 43380 ssh2
Invalid user toor from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user toor from 61.129.64.93 port 43402 ssh2
Invalid user toor from 61.129.64.93
error: Could not get shadow information for NOUSER
Failed password for invalid user toor from 61.129.64.93 port 43429 ssh2
error: Could not get shadow information for NOUSER
Failed password for invalid user username from 69.59.170.124 port 35292 ssh2
Invalid user user from 69.59.170.124
error: Could not get shadow information for NOUSER
Failed password for invalid user user from 69.59.170.124 port 35881 ssh2
User root not allowed because not listed in AllowUsers
error: Could not get shadow information for NOUSER
Failed password for invalid user root from 69.59.170.124 port 36382 ssh2
Invalid user admin from 69.59.170.124
error: Could not get shadow information for NOUSER
Failed password for invalid user admin from 69.59.170.124 port 36958 ssh2
User test not allowed because not listed in AllowUsers
error: Could not get shadow information for NOUSER
Failed password for invalid user test from 69.59.170.124 port 37467 ssh2
.
.
.

Last edited by ~=gr3p=~; 01-20-2006 at 12:34 AM.
 
Old 01-20-2006, 04:38 AM   #2
gwp
Newbie
 
Registered: Oct 2003
Location: South Africa
Distribution: Redhat, Fedora, Ubuntu
Posts: 27

Rep: Reputation: 15
Smile

Unfortunately the world is full of idiots.... just watch the news every day....

The best that you can do is monitor and start blocking the culprit IPs

Also read up on rate limiting... check a site like http://www.debian-administration.org/articles/187 ....

Good luck
 
Old 01-20-2006, 04:50 AM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Will your legitimate clients agree to using keys to login with instead of username/passwords? That's how we're set up here. All username/password attempts fail, only users who've got their public key in ~/.ssh on the ssh server can get in.
 
Old 01-20-2006, 05:29 PM   #4
damicatz
Member
 
Registered: May 2004
Distribution: FreeBSD 7, Debian "Squeeze", OpenBSD 4.5
Posts: 167

Rep: Reputation: 30
http://www.hakusan.tsg.ne.jp/tjkawa/...er/index-e.jsp
 
Old 01-20-2006, 06:14 PM   #5
silmaril8n
Member
 
Registered: May 2004
Posts: 123

Rep: Reputation: 15
Quote:
Originally Posted by gilead
Will your legitimate clients agree to using keys to login with instead of username/passwords? That's how we're set up here. All username/password attempts fail, only users who've got their public key in ~/.ssh on the ssh server can get in.
I just setup my own server in this way and I'm very happy with it! I finally feel at least somewhat safe running SSH. I also moved the service to an obscure port.
 
Old 01-20-2006, 06:35 PM   #6
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
You can also look at setting up some rules through iptables to limit the amount of new connections to the port you are now running on if you have the `recent` module built into the kernel. just type at the prompt:

modprobe ipt_recent

If you don't get an error, you have the module installed, you can start limiting the amount of connections in a certain time period before blocking. The `recent` module creates a list and adds ip-addresses to the list, after the time limit specified has expired the ip-address can connect again. some example rules would look like this:

# $IPTABLES -A INPUT -p tcp -i eth0 --dport 22 -m state --state NEW -m recent --name sshprobe --set -j ACCEPT
# $IPTABLES -A INPUT -p tcp -i eth0 --dport 22 -m state --state NEW -m recent --name sshprobe --update --seconds 60 --hitcount 3 -j DENY
 
Old 01-20-2006, 11:41 PM   #7
~=gr3p=~
Member
 
Registered: Feb 2005
Location: ~h3av3n~
Distribution: RHEL 4, Fedora Core 3,6,7 Centos 5, Ubuntu 7.04
Posts: 227

Original Poster
Rep: Reputation: 30
hey kool learned nice tricks here thnks. currently i have changed my port to someting else now i will try above tricks
 
Old 01-21-2006, 06:45 AM   #8
Intimidator
Member
 
Registered: Mar 2005
Distribution: FC4
Posts: 83

Rep: Reputation: 15
http://www.linuxquestions.org/questi...d.php?t=360119
 
Old 01-21-2006, 09:00 PM   #9
~=gr3p=~
Member
 
Registered: Feb 2005
Location: ~h3av3n~
Distribution: RHEL 4, Fedora Core 3,6,7 Centos 5, Ubuntu 7.04
Posts: 227

Original Poster
Rep: Reputation: 30
this site rox n linux rox

amazing knowledge thnxa ton
 
Old 01-22-2006, 05:02 PM   #10
tkedwards
Senior Member
 
Registered: Aug 2004
Location: Munich, Germany
Distribution: Opensuse 11.2
Posts: 1,549

Rep: Reputation: 52
You can change ssh to another port quite easily and it does stop the attacks but a better solution would be something like http://denyhosts.sourceforge.net/
 
Old 01-23-2006, 05:07 AM   #11
~=gr3p=~
Member
 
Registered: Feb 2005
Location: ~h3av3n~
Distribution: RHEL 4, Fedora Core 3,6,7 Centos 5, Ubuntu 7.04
Posts: 227

Original Poster
Rep: Reputation: 30
^^ thats an excellent utility thnx
 
Old 01-24-2006, 02:28 PM   #12
lucktsm
Member
 
Registered: May 2004
Location: Atlanta, GA USA
Distribution: Redhat ES4, FC4, FC5, slax, ubuntu, knoppix
Posts: 155

Rep: Reputation: 30
Something to consider also, the log indicates a few ip addresses. Thes attackers are most likely using an automated brute force program. A way to defeat it is to listen on a different port than 22. I changed my defaul SSH port to another lesser known port and the attacks you're seeing have gone away.

The programs that scan are wanting to get the "low hanging fruit" so to speak. They are going after defaults and looking for ssh v1 etc.. By changing the port you can save yourself the headache of the idiots.

G'luck
 
  


Reply



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 On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
webalizer resolving ip countries? bruno buys Linux - Networking 3 04-27-2011 12:09 AM
IPTables - Multiple Public IP's to private IP's matneyc Linux - Security 8 05-27-2005 12:23 PM
Webalizer - countries - a different issue nickd63 Linux - Networking 0 12-10-2004 01:39 PM
Webalizer and resolving countries wolftechmn Linux - General 6 06-17-2004 02:59 PM
Exporting Linux to other countries from US elzmaddy Linux - General 7 05-25-2003 11:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 05:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration