Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

repetitive ssh logins by bots - any way to stop these?

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
14 posts • Page 1 of 1
Author
Message
dilbot
Apprentice
Apprentice
User avatar
Posts: 153
Joined: Fri Feb 06, 2004 1:53 am
Location: Canada

repetitive ssh logins by bots - any way to stop these?

  • Quote

Post by dilbot » Thu Aug 10, 2006 8:09 pm

I've noticed bots trying to repetitively ssh into my mail/web server, hundreds of times. Mostly from Asia. Is there a way to get these IP's locked out automatically after say 10 or 20 trys?
Top
schwicky
n00b
n00b
User avatar
Posts: 27
Joined: Fri Aug 13, 2004 2:41 pm
Location: Langnau im Emmental
Contact:
Contact schwicky
Website

  • Quote

Post by schwicky » Thu Aug 10, 2006 8:25 pm

Have a look at fail2ban. It allows you to specify iptables rules to block abusive ssh/apache/ftp/... failed logins
Nothing's impossible... Everything's relative!
Top
kilianh
n00b
n00b
Posts: 27
Joined: Fri Oct 08, 2004 9:12 am
Location: Cape Town, South Africa

  • Quote

Post by kilianh » Thu Aug 10, 2006 9:07 pm

To make ssh itself less prone to attacks like this I always use one or more of the following three techniques:
  • Use key based logins and disable password logins. Very secure and fairly simple to set up
  • Use iptables to allow ssh access from only a select few ip addresses (or only a single one). Very secure
  • Run ssh on a different port. Security by obscurity
Haven't looked at fail2ban yet but I highly recommend the first option
Top
svancouw
n00b
n00b
Posts: 57
Joined: Sun Feb 05, 2006 2:47 am
Location: California
Contact:
Contact svancouw
Website

  • Quote

Post by svancouw » Thu Aug 10, 2006 11:13 pm

We just noticed yesterday at 1 a.m. that my servers were getting hit pretty hard with that from Romania, and we installed denyhosts. That allows you to set how many attempts are made before they are banned, and for how long. Then, if they do it again, they are banned permenently. All IPs and hostnames are blocked by user hosts.deny.

This is a very effective means of stopping this sort of activity. It does use /var/log/messages to set up the banned IPs, so you might want to clear that log first, or else it will accidentally ban valid IPs. That is, for example, if you forgot your password and couldn't log in via ssh three times in a row, it would add your source IP to the banned list.

Our settings are three attempts, banned for a week. After that week, three more attempts, banned permanently. If you want to re-enable someone, just delete their IP or hostname from hosts.deny.

Hope this helps!

Sean
Top
phatscum
n00b
n00b
Posts: 34
Joined: Mon Mar 20, 2006 4:03 pm
Location: Down the sewers

  • Quote

Post by phatscum » Thu Aug 10, 2006 11:21 pm

I'll second fail2ban. Very easy and effective.
Computer games don't affect kids, I mean, if pacman affected us as kids we'd all run around in a darkened room munching pills and listening to repetitive music.
Top
dilbot
Apprentice
Apprentice
User avatar
Posts: 153
Joined: Fri Feb 06, 2004 1:53 am
Location: Canada

  • Quote

Post by dilbot » Fri Aug 11, 2006 3:31 am

All excellent suggestions - I've started looking at each package. Thanks for your help!
Top
James Wells
n00b
n00b
User avatar
Posts: 57
Joined: Fri Sep 10, 2004 4:26 pm

  • Quote

Post by James Wells » Wed Aug 16, 2006 2:24 am

Greetings,

If you already have IP tables installed, a simple solution is to modify your /etc/ssh/sshd_config file, changing MaxAuthTries to 2. This will tell sshd to only allow two attempts per connect. Then you simply add the following to your iptables rules;

Code: Select all

iptables -A SSHD -p tcp -m state --state NEW -m recent --update --seconds 86400 --hitcount 3 --rttl -j DROPLOG
iptables -A SSHD -p tcp -m state --state NEW -m recent --set -j ACCEPT

iptables -A DROPLOG -m limit --limit 3/minute --limit-burst 10 -j LOG --log-prefix 'iptables Droplog: '
iptables -A DROPLOG -j DROP
The first line says that if a site attempts to connect to SSH more than 3 times, within 24 hours, send that site to the table called DROPLOG. Droplog then generates a syslog entry and drops the connection and all future attempts for the next 24 hours.

I have found that this system works very well for me. YMMV of course.
Top
mahuani
n00b
n00b
User avatar
Posts: 31
Joined: Sat Jun 11, 2005 10:13 pm
Location: New Orleans, LA
Contact:
Contact mahuani
Website

  • Quote

Post by mahuani » Sat Aug 19, 2006 5:27 am

Another option might be denyhosts. It gives loads of configuration options and the ability to sync w/ a central server that keeps a list of ips know to be attacking.

Code: Select all

emerge app-admin/denyhosts
Top
kamagurka
Veteran
Veteran
User avatar
Posts: 1026
Joined: Sun Jan 25, 2004 1:55 am
Location: /germany/munich
Contact:
Contact kamagurka
Website

  • Quote

Post by kamagurka » Sun Aug 20, 2006 6:23 pm

I found that using a really strange portnumber for ssh works fine. If that fails, a big cardboard "no bots alowed here" sign on the workstation does wonders, too =D
If you loved me, you'd all kill yourselves today.
--Spider Jerusalem, the Word
Top
.:chrome:.
Advocate
Advocate
User avatar
Posts: 4588
Joined: Sat Feb 19, 2005 7:19 pm
Location: Brescia, Italy

  • Quote

Post by .:chrome:. » Sun Aug 20, 2006 6:35 pm

kamagurka wrote:I found that using a really strange portnumber for ssh works fine. If that fails, a big cardboard "no bots alowed here" sign on the workstation does wonders, too =D
this can't solve the problem.
a portscan can found the new port number, and this method doesn't work with firewalls

the right solution is using tools such portsentry, denyhosts, or knockd
Top
kamagurka
Veteran
Veteran
User avatar
Posts: 1026
Joined: Sun Jan 25, 2004 1:55 am
Location: /germany/munich
Contact:
Contact kamagurka
Website

  • Quote

Post by kamagurka » Sun Aug 20, 2006 6:47 pm

You are, of course, right. But doesn't choosing a very high non-standard portnumber protect you from portscans?
If you loved me, you'd all kill yourselves today.
--Spider Jerusalem, the Word
Top
.:chrome:.
Advocate
Advocate
User avatar
Posts: 4588
Joined: Sat Feb 19, 2005 7:19 pm
Location: Brescia, Italy

  • Quote

Post by .:chrome:. » Sun Aug 20, 2006 9:00 pm

kamagurka wrote:You are, of course, right. But doesn't choosing a very high non-standard portnumber protect you from portscans?
this is true... but in this manner you can connect to your SSH server if you are over a firewall that (correctly) opens just port 22 and not others
Top
kamagurka
Veteran
Veteran
User avatar
Posts: 1026
Joined: Sun Jan 25, 2004 1:55 am
Location: /germany/munich
Contact:
Contact kamagurka
Website

  • Quote

Post by kamagurka » Sun Aug 20, 2006 10:21 pm

k.gothmog wrote:
kamagurka wrote:You are, of course, right. But doesn't choosing a very high non-standard portnumber protect you from portscans?
this is true... but in this manner you can connect to your SSH server if you are over a firewall that (correctly) opens just port 22 and not others
I don't know how you do it, but I just forwarded the port. Or do you mean when you're behind a firewall that you don't control?
If you loved me, you'd all kill yourselves today.
--Spider Jerusalem, the Word
Top
James Wells
n00b
n00b
User avatar
Posts: 57
Joined: Fri Sep 10, 2004 4:26 pm

  • Quote

Post by James Wells » Sun Aug 20, 2006 10:26 pm

kamagurka wrote:You are, of course, right. But doesn't choosing a very high non-standard portnumber protect you from portscans?
Yes and No. This will protect you from most script kiddie tools, however, those tools generally only scan standard ports. Sadly, most of the bot / zombie nets are using tools vastly superior to what script kiddies use, tools that specifically scan ports in the 56K - 64K range specifically to look for these types of openings. That's actually the reason I have given up on hiding ports, and instead have opted to simply use abuse blockers, like the IP tables piece I did above.
Top
Post Reply

14 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic