LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-29-2009, 05:29 PM   #1
LinuxIsGR8
LQ Newbie
 
Registered: Jun 2006
Location: San Jose, Ca
Distribution: openSuSE 10.3 & openSuSE 11.1
Posts: 8

Rep: Reputation: 0
Question Another iptables rule set not working


I would like to block brute force attacks. I've added the following iptables rules and yet, the attacks are not blocked. I've tried similar rules with the same results. The attacks persist for about 8 or so minutes. Why is this not working?
Walt

iptables -N SSH_KILLER
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j SSH_KILLER
iptables -A SSH_KILLER -m recent --set --name SSH
iptables -A SSH_KILLER -m recent --update --seconds 60 --hitcount 4 --name SSH -j DROP
 
Old 01-29-2009, 05:41 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
seems ok to me
iptables => is the path correct?

what is the output of
Code:
iptables -L | grep SSH
 
Old 01-30-2009, 06:56 AM   #3
LinuxIsGR8
LQ Newbie
 
Registered: Jun 2006
Location: San Jose, Ca
Distribution: openSuSE 10.3 & openSuSE 11.1
Posts: 8

Original Poster
Rep: Reputation: 0
SSH_KILLER tcp -- anywhere anywhere tcp dpt:22 state NEW
Chain SSH_KILLER (1 references)
all -- anywhere anywhere recent: SET name: SSH side: source
DROP all -- anywhere anywhere recent: UPDATE seconds: 60 hit_count: 4 name: SSH side: source


Thanks for looking at this...Walt
 
Old 01-30-2009, 09:28 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
should work.
can you test from a remote computer?
 
Old 02-03-2009, 09:37 AM   #5
LinuxIsGR8
LQ Newbie
 
Registered: Jun 2006
Location: San Jose, Ca
Distribution: openSuSE 10.3 & openSuSE 11.1
Posts: 8

Original Poster
Rep: Reputation: 0
I opened 6 putty windows and then attempted to login with 6 bogus id's. When the 6th one was entered, I received a connection refused. So, I guess that tells me it is working. But then, why do I see this in /var/log/messages?

BTW, I'm running openSUSE 10.3 on this machine.

Walt

Feb 2 21:19:06 spock sshd[4803]: Did not receive identification string from 210.82.89.139
Feb 2 21:22:49 spock sshd[4807]: User root from 210.82.89.139 not allowed because listed in DenyUsers
Feb 2 21:22:51 spock sshd[4813]: Invalid user usuario from 210.82.89.139
Feb 2 21:22:53 spock sshd[4818]: Invalid user irina from 210.82.89.139
Feb 2 21:22:56 spock sshd[4823]: Invalid user karin from 210.82.89.139
Feb 2 21:22:58 spock sshd[4828]: Invalid user cvs from 210.82.89.139
Feb 2 21:23:01 spock sshd[4833]: Invalid user cvsroot from 210.82.89.139
Feb 2 21:23:03 spock sshd[4838]: Invalid user paper from 210.82.89.139
Feb 2 21:23:06 spock sshd[4843]: Invalid user a from 210.82.89.139
Feb 2 21:23:08 spock sshd[4848]: Invalid user carter from 210.82.89.139
Feb 2 21:23:11 spock sshd[4853]: Invalid user paul from 210.82.89.139
Feb 2 21:23:13 spock sshd[4858]: Invalid user julie from 210.82.89.139
Feb 2 21:23:16 spock sshd[4863]: Invalid user tomato from 210.82.89.139
Feb 2 21:23:18 spock sshd[4868]: Invalid user dev from 210.82.89.139
Feb 2 21:23:21 spock sshd[4873]: Invalid user eric from 210.82.89.139
Feb 2 21:23:23 spock sshd[4878]: Invalid user morgan from 210.82.89.139
Feb 2 21:23:25 spock sshd[4883]: Invalid user jackson from 210.82.89.139

======================== SNIP =======================================

Feb 2 21:31:13 spock sshd[5810]: Invalid user ftpuser from 210.82.89.139
Feb 2 21:31:16 spock sshd[5815]: Invalid user master from 210.82.89.139
Feb 2 21:31:18 spock sshd[5820]: Invalid user oleg from 210.82.89.139
Feb 2 21:31:20 spock sshd[5825]: Invalid user eugene from 210.82.89.139
Feb 2 21:31:23 spock sshd[5830]: Invalid user max from 210.82.89.139
Feb 2 21:31:25 spock sshd[5835]: Invalid user java from 210.82.89.139
Feb 2 21:31:28 spock sshd[5840]: Invalid user rick from 210.82.89.139
Feb 2 21:31:30 spock sshd[5845]: Invalid user ruth from 210.82.89.139
Feb 2 21:31:33 spock sshd[5850]: Invalid user resin from 210.82.89.139
Feb 2 21:31:35 spock sshd[5855]: Invalid user delgado from 210.82.89.139
Feb 2 21:31:38 spock sshd[5860]: Invalid user sara from 210.82.89.139
Feb 2 21:31:40 spock sshd[5865]: Invalid user amanda from 210.82.89.139
Feb 2 21:31:42 spock sshd[5870]: Invalid user stan from 210.82.89.139
Feb 2 21:31:45 spock sshd[5875]: Invalid user denis from 210.82.89.139
Feb 2 21:31:47 spock sshd[5880]: Invalid user dennis from 210.82.89.139
Feb 2 21:31:50 spock sshd[5885]: Invalid user vivian from 210.82.89.139
Feb 2 21:31:52 spock sshd[5890]: Invalid user viviane from 210.82.89.139
Feb 2 21:31:55 spock sshd[5895]: Invalid user jacob from 210.82.89.139

Last edited by LinuxIsGR8; 02-03-2009 at 09:39 AM.
 
Old 02-03-2009, 10:51 AM   #6
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
iptables -N SSH_KILLER
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j SSH_KILLER
iptables -A SSH_KILLER -m recent --set --name SSH
iptables -A SSH_KILLER -m recent --update --seconds 60 --hitcount 4 --name SSH -j LOG
iptables -A SSH_KILLER -m recent --update --seconds 60 --hitcount 4 --name SSH -j DROP

I'm no whiz at Netfilter, but I believe that's what you want.
 
Old 02-03-2009, 01:23 PM   #7
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by LinuxIsGR8 View Post
I would like to block brute force attacks. I've added the following iptables rules and yet, the attacks are not blocked. I've tried similar rules with the same results. The attacks persist for about 8 or so minutes. Why is this not working?
Walt

iptables -N SSH_KILLER
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j SSH_KILLER
iptables -A SSH_KILLER -m recent --set --name SSH
iptables -A SSH_KILLER -m recent --update --seconds 60 --hitcount 4 --name SSH -j DROP
I use a similar rule... and I know it does work.

Code:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 360 --hitcount 3 --name SSHATTEMPTS --rsource -j DROP
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name SSHATTEMPTS --rsource
Ymmv.
 
Old 02-03-2009, 01:25 PM   #8
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
As a temporary thing i'd be inclined to:-
Code:
iptables -A INPUT -s 210.82.89.139 -j LOG #Optional if you want to log
iptables -A INPUT -s 210.82.89.139 -j DROP
Just so to make sure at least temporarily unless they then start using another IP, that they will get no-where with their brute attack. Then is there a specific reason your creating a new chain, it will work just as well:-
Code:
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
Shouldn't be any problems with that, althought can't say i see an issue with what you've got either.

Last edited by helptonewbie; 02-03-2009 at 01:32 PM.
 
Old 02-04-2009, 03:21 PM   #9
LinuxIsGR8
LQ Newbie
 
Registered: Jun 2006
Location: San Jose, Ca
Distribution: openSuSE 10.3 & openSuSE 11.1
Posts: 8

Original Poster
Rep: Reputation: 0
Ok,
I put the following rules in:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 360 --hitcount 3 --name SSHATTEMPTS --rsource -j DROP
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name SSHATTEMPTS --rsource

I thought that since it specifically pointed to eth0 that maybe that would work. Not so, I had to shut down the ssh daemon in the middle of an attack.

Will try the one form the last posting.
Walt

Feb 4 13:12:41 spock sshd[21647]: Invalid user admin65 from 221.139.3.36
Feb 4 13:12:43 spock sshd[21652]: Invalid user admin from 221.139.3.36
Feb 4 13:12:44 spock sshd[21657]: Invalid user admin from 221.139.3.36
Feb 4 13:12:46 spock sshd[21662]: Invalid user admin from 221.139.3.36
Feb 4 13:12:48 spock sshd[21667]: Invalid user admin from 221.139.3.36
Feb 4 13:12:49 spock sshd[21672]: Invalid user admin from 221.139.3.36
Feb 4 13:12:51 spock sshd[21677]: Invalid user admin from 221.139.3.36
Feb 4 13:12:52 spock sshd[21682]: Invalid user admin from 221.139.3.36
Feb 4 13:12:54 spock sshd[21687]: Invalid user admin from 221.139.3.36
Feb 4 13:12:55 spock sshd[21692]: Invalid user admin from 221.139.3.36
Feb 4 13:12:57 spock sshd[21697]: Invalid user admin from 221.139.3.36
Feb 4 13:12:59 spock sshd[21702]: Invalid user admin from 221.139.3.36
Feb 4 13:13:00 spock sshd[21707]: Invalid user admin from 221.139.3.36
Feb 4 13:13:02 spock sshd[21712]: Invalid user admin from 221.139.3.36
Feb 4 13:13:03 spock sshd[21717]: Invalid user admin from 221.139.3.36
Feb 4 13:13:05 spock sshd[21722]: Invalid user admin from 221.139.3.36
Feb 4 13:13:06 spock sshd[21727]: Invalid user admin from 221.139.3.36
Feb 4 13:13:08 spock sshd[21733]: Invalid user admin from 221.139.3.36
Feb 4 13:13:10 spock sshd[21739]: Invalid user admin from 221.139.3.36
 
Old 02-04-2009, 03:23 PM   #10
LinuxIsGR8
LQ Newbie
 
Registered: Jun 2006
Location: San Jose, Ca
Distribution: openSuSE 10.3 & openSuSE 11.1
Posts: 8

Original Poster
Rep: Reputation: 0
Is there a way of deleting iptables rules without having to re-boot the system and add new replacement iptables rules?
Thanks,
Walt
 
Old 02-04-2009, 03:34 PM   #11
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by LinuxIsGR8 View Post
Is there a way of deleting iptables rules without having to re-boot the system and add new replacement iptables rules?
Thanks,
Walt
Yes, just change the -A or -I which you used to a -D.
 
Old 02-04-2009, 04:53 PM   #12
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
I'm curious how '--update --seconds N' works. Does it wake up every N seconds and check how many matches there have been since the last interval? If so, lowering the value of N should see improvement in how quickly an IP gets blocked.
 
Old 02-05-2009, 03:41 PM   #13
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by LinuxIsGR8 View Post
Ok,

Feb 4 13:12:41 spock sshd[21647]: Invalid user admin65 from 221.139.3.36
Feb 4 13:12:43 spock sshd[21652]: Invalid user admin from 221.139.3.36
Feb 4 13:12:44 spock sshd[21657]: Invalid user admin from 221.139.3.36
Feb 4 13:12:46 spock sshd[21662]: Invalid user admin from 221.139.3.36
Feb 4 13:12:48 spock sshd[21667]: Invalid user admin from 221.139.3.36
Feb 4 13:12:49 spock sshd[21672]: Invalid user admin from 221.139.3.36
Feb 4 13:12:51 spock sshd[21677]: Invalid user admin from 221.139.3.36
Feb 4 13:12:52 spock sshd[21682]: Invalid user admin from 221.139.3.36
Feb 4 13:12:54 spock sshd[21687]: Invalid user admin from 221.139.3.36
Feb 4 13:12:55 spock sshd[21692]: Invalid user admin from 221.139.3.36
Feb 4 13:12:57 spock sshd[21697]: Invalid user admin from 221.139.3.36
Feb 4 13:12:59 spock sshd[21702]: Invalid user admin from 221.139.3.36
Feb 4 13:13:00 spock sshd[21707]: Invalid user admin from 221.139.3.36
Feb 4 13:13:02 spock sshd[21712]: Invalid user admin from 221.139.3.36
Feb 4 13:13:03 spock sshd[21717]: Invalid user admin from 221.139.3.36
Feb 4 13:13:05 spock sshd[21722]: Invalid user admin from 221.139.3.36
Feb 4 13:13:06 spock sshd[21727]: Invalid user admin from 221.139.3.36
Feb 4 13:13:08 spock sshd[21733]: Invalid user admin from 221.139.3.36
Feb 4 13:13:10 spock sshd[21739]: Invalid user admin from 221.139.3.36
One thing to remember... it's not number of attempts. It's number of connects. If your sshd lets them take 20 attempts per connect... it'll take 60 attempts before it gets rid of them.

I think the sshd_config options you want to look at is strictmode (should be yes), maxauthtries (your call, mines 2), and logingracetime (I use 30s).
 
Old 02-05-2009, 03:42 PM   #14
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by win32sux View Post
Yes, just change the -A or -I which you used to a -D.
or if you want to dump them all "iptables -F"
 
Old 02-06-2009, 01:42 PM   #15
LinuxIsGR8
LQ Newbie
 
Registered: Jun 2006
Location: San Jose, Ca
Distribution: openSuSE 10.3 & openSuSE 11.1
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks. No one is getting in, just seeing the attempts in the /var/log/messages log is annoying.
Walt
 
  


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
iptables nat port forwarding rule set crowhurst01 Linux - Networking 2 02-13-2012 03:39 AM
iptables: rule with RETURN target just after a rule with ACCEPT target Nerox Linux - Networking 6 09-04-2011 03:33 PM
iptables rule bkcreddy17 Linux - Security 2 01-20-2009 06:38 AM
iptables rule DJ29Joesph Linux - Security 4 11-04-2008 12:55 AM
IPTables "Best Practice" default rule set robinBones Linux - Networking 2 01-09-2008 08:11 AM

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

All times are GMT -5. The time now is 08:46 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