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 11-03-2009, 03:55 AM   #1
ytd
Member
 
Registered: Jan 2009
Posts: 205

Rep: Reputation: 31
block access from iptables and / or ftp configuration ?!


Ok, so here's the thing. It's a bit complicated, I gues.

I have a http server and I have many connections (over 1000 connections per day) to it on port 80. Sometimes the http server dosen't work no more 'cause there are some IP's that access my server with more than 15 connections per second.

The chain INPUT has the default policy to accept any connection.

I did:

iptables -I INPUT -s bannedip -p tcp --dport 80 -j DROP

This works fine, I have banned 5 ip's so far and the http server is working fine now, it dosen't block no more. But I have another problem. On the same server which is running the http server I have a ftp server (vsftpd) and again, I have many connections to the ftp server (tons of connections) and it's like... unconfortable for me to ban them 'cause on ftp server there are other banned IP's than the banned http IP's and after a couple oh hours the ip is changing and when i'm not at home, I can't block any ip's no more, and the server is blocked.

I thought abnout having the chain INPUT policy deny / reject as default, but that can't be done 'cause then I will have to allow all ip's for http port (80) and then if I get over 15 connections per second from an IP I can't block it no more 'cause I already allowed 0/0 ip's on port 80.

So what can be done ?

I saw on the internet that some programs (i'm not sure about vsftpd) have on the *.conf this thing:

AuthName "Site Administration"
AuthUserFile /home/user/askapache.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from (my LAN IP)
Satisfy Any

Forgot to tell that I ONLY need ftp acces only from my LAN not WAN.

So, is there a way that I could deny some IP's for port 21 not from iptables but from the configuration of the vsftpd ?

Is that example good enough ? DOes it work if I write that information there ? OMG i'm so stupid... why do I have to ask, I can test that myself. rotfl...


Oh, well... in case it dosen't work, i'm like... waiting for an answer here, or something.
 
Old 11-03-2009, 04:05 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
You can limit the connections per IP with the connlimit module of iptables

Code:
iptables -A INPUT -p tcp --dport 80 -m connlimit --conlimit-above 2 -j DROP
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
This limits every ip to only 2 connections. Maybe a log line above might be useful.

If you need the ftp only from within why don't you just shut access from the wan?
Code:
iptables -A INPUT -i wan-interface -p tcp --dport 21 -j DROP
Or if you just have all the policies set to deny
Code:
iptables -A INPUT -i lan-interface -p tcp --dport 21 -j ACCEPT
 
Old 11-03-2009, 04:17 AM   #3
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
Hi,

The first command dosen't work.

[root@xxx ~]# iptables -I INPUT -p tcp --dport 80 -m connlimit --conlimit-above 2 -j DROP
iptables v1.2.11: Unknown arg `--conlimit-above'
Try `iptables -h' or 'iptables --help' for more information.
[root@xxx ~]#


The second command isn't possible 'cause it has one interface (one single ip) and I access the server from my LAN and the server is in DMZ.

PS: The deny from and allow from ip bla bla bal dosen't work in vsftpd configuration. After I change in configuration and after I restart the vsftpd the vsftpd sais that it cannot start.

PS2: I see that in your first command you spelled conn with double n and then with a single n. It dosen't work eitherway.
 
Old 11-03-2009, 04:26 AM   #4
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
rotfl i'm so fu*king smart =))

The server is in DMZ but i'm in LAN and there's a gateway between us. Look what I did:

[root@xxx ~]# iptables -I INPUT -i LAN GW -p tcp --dport 21 -j ACCEPT
[root@xxx ~]#
[root@xxx ~]#
[root@xxx ~]#
[root@xxx ~]# iptables -I INPUT -i WAN -p tcp --dport 21 -j DROP

rotfl it's working )

tyvm mate !
 
Old 11-03-2009, 04:51 AM   #5
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
There you go Just a punch in the right direction and your flying

I had a typo within the second --connlimit. It's with double n. I just wrote this from the man page so no clue if there are more typos. But for sure see if you have the needed modules loaded. Either with lsmod or inside the /proc/net directory

Cheers Zhjim
 
Old 11-03-2009, 05:10 AM   #6
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by zhjim View Post
There you go Just a punch in the right direction and your flying
Cheers Zhjim
rotflmao that was a good 1

Anyway, it dosen't work. After I added those rules, the iptables looks like this:

iptables -L

DROP tcp -- anywhere anywhere tcp dpt:ftp
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp


So it's obviously that id dosen't work. There are two rules that are contradicting themselves. What should I do, this su*ks.

PS: Should I create a virtual eth ?
 
Old 11-03-2009, 09:10 AM   #7
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
no need for a virtual device. The -i argument to iptables names the interface. Use --source (-s) to limit the source ip

Code:
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 21 -j ACCEPT
 
  


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 configuration for Passive FTP connection bk2008 Linux - Networking 10 04-08-2008 12:43 AM
FTP Access Through IPTABLES Firewall SlowCoder Linux - Security 1 04-12-2007 03:32 PM
by using iptables block mac address to restric user to access internet Farrukh Fida Linux - Networking 3 10-09-2006 07:59 AM
iptables question re FTP access rjeeves33 Linux - Networking 3 12-12-2005 06:55 PM
Iptables, FTP, access herc Linux - Security 1 01-08-2004 07:51 PM

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

All times are GMT -5. The time now is 09:33 PM.

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