LinuxQuestions.org
Visit Jeremy's Blog.
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-08-2011, 02:27 AM   #1
hermouche
Member
 
Registered: Nov 2004
Location: Algeria
Posts: 111

Rep: Reputation: 15
Smile Dropping a host with iptables!


Hy everybody everywhere,

We've a gateway with two NIC's:
eth0: 192.168.1.2 <-----> connected to modem/router -----> WAN
eth1: 192.168.0.0/24 ----------> LAN

Actually, as far as my understanding:
  1. if a packet is destined to the gateway, it goes right to the INPUT chain and so on....
  2. if a packet is destinet to the LAN, the route changes and the packet follows the FORWARD chain and so on ....

So now, if i want to stop a host which is on the LAN (192.168.0.10), i've done the following:

Quote:
iptables -I INPUT -m mac --mac-source 00:1E:58:9E:E4:E8 -j DROP
The host (192.168.0.10) stopped surfing, which is great, but i thought that we should apply the rule within the FORWARD chain instead since this host is on LAN and is not the gateway !!!

any suggestion please

Thanks for the reply
red

Last edited by hermouche; 11-08-2011 at 02:28 AM.
 
Old 11-08-2011, 02:42 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Quote:
Originally Posted by hermouche View Post
  1. if a packet is destined to the gateway, it goes right to the INPUT chain and so on....
  2. if a packet is destinet to the LAN, the route changes and the packet follows the FORWARD chain and so on ....
Correct. http://www.linuxhomenetworking.com/w...t_Flow_Diagram

Quote:
Originally Posted by hermouche View Post
The host (192.168.0.10) stopped surfing, which is great, but i thought that we should apply the rule within the FORWARD chain instead since this host is on LAN and is not the gateway !!!
Is the gateway running DNS for the LAN?
If so, the DNS requests will go to the gateway, via INPUT, and dropping them will prevent DNS requests from resolving.
If this is the case, can the host connect using an IP instead of DNS?

A transparent proxy redirection rule could have the same result.
 
1 members found this post helpful.
Old 11-08-2011, 02:56 AM   #3
hermouche
Member
 
Registered: Nov 2004
Location: Algeria
Posts: 111

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by fukawi1 View Post
Correct. http://www.linuxhomenetworking.com/w...t_Flow_Diagram



Is the gateway running DNS for the LAN?
If so, the DNS requests will go to the gateway, via INPUT, and dropping them will prevent DNS requests from resolving.
If this is the case, can the host connect using an IP instead of DNS?

A transparent proxy redirection rule could have the same result.
Thanks for the reply fukawil,


Well we have got both:
- hosts on LAN are using the Gateway as a DNS server (192.168.0.1) via the DHCPD, and
- we have got a transparent proxy
Quote:
iptables -t nat -A PREROUTING -i $INTERNAL_INT -p tcp --dport 80 -j REDIRECT --to-port 3128
Please fukawil, what do you mean by:

Quote:
If this is the case, can the host connect using an IP instead of DNS?
Thanks again
red
 
Old 11-08-2011, 03:14 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
If the gateway is handling DNS, then trying to connect/browse etc by using a IP address in the hosts browser, rather than domain name ie:
Code:
http://74.125.237.82
instead of
Code:
http://google.com
would most likely work..
So you would need to add the same rule to the FORWARD chain..
 
Old 11-08-2011, 03:40 AM   #5
hermouche
Member
 
Registered: Nov 2004
Location: Algeria
Posts: 111

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by fukawi1 View Post
If the gateway is handling DNS, then trying to connect/browse etc by using a IP address in the hosts browser, rather than domain name ie:
Code:
http://74.125.237.82
instead of
Code:
http://google.com
would most likely work..
So you would need to add the same rule to the FORWARD chain..
Oh yes, i see now
Well it works in both ways, yes.
either as you said "using an IP address or domain name" .
Thanks.

Just to be clear, i'm little confused:
The packet initially should traverse the FORWARD chain. Since the same packet needs the DNS which is located on the Gateway, so all the packet is just changing his way and is traversing the INPUT chain !!!!

is it right, i'm not sure about it ?

In other words, why i can not stop the host (192.168.0.10) just by saying:
Quote:
iptables -I FORWARD -s 192.168.0.10 -j DROP
or

Quote:
iptables -I FORWARD -d 192.168.0.10 -j DROP
red

Last edited by hermouche; 11-08-2011 at 03:52 AM.
 
Old 11-08-2011, 04:14 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Check out the picture in the link I posted above. It shows a flowchart of when a packet passes through each table/chain..

Because the transparent proxy rule you have, is intercepting the packets destined for the internet in nat/PREROUTING
the packet passes through the filter/INPUT chain to squid, BEFORE it gets to the filter/FORWARD chain, squid then sends the requests out to the internet..
So you need the filter/INPUT rule.

As I understand it, (and I stand to be corrected).
host sends a some packets asking the gateway to resolve google.com (filter/INPUT)
the gateway looks locally to resolve the name, if it cant, it asks nameservers in /etc/resolv (filter/OUTPUT)
once the gateway has obtained an answer it responds to the host with 74.125.237.82 (filter/OUTPUT)

the host then initiates a connection with 74.125.237.82.. which goes to the gateway (nat/PREROUTING)
these packets then hit the squid intercept rule, and get sent to squid running locally, (filter/INPUT)
it then gets processed by squid. and gets sent to its destination of 74.125.237.82


As I said though, I stand to be corrected on that..

Last edited by fukawi1; 11-08-2011 at 04:18 AM.
 
Old 11-08-2011, 04:55 AM   #7
hermouche
Member
 
Registered: Nov 2004
Location: Algeria
Posts: 111

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by fukawi1 View Post
Check out the picture in the link I posted above. It shows a flowchart of when a packet passes through each table/chain..

Because the transparent proxy rule you have, is intercepting the packets destined for the internet in nat/PREROUTING
the packet passes through the filter/INPUT chain to squid, BEFORE it gets to the filter/FORWARD chain, squid then sends the requests out to the internet..
So you need the filter/INPUT rule.

As I understand it, (and I stand to be corrected).
host sends a some packets asking the gateway to resolve google.com (filter/INPUT)
the gateway looks locally to resolve the name, if it cant, it asks nameservers in /etc/resolv (filter/OUTPUT)
once the gateway has obtained an answer it responds to the host with 74.125.237.82 (filter/OUTPUT)

the host then initiates a connection with 74.125.237.82.. which goes to the gateway (nat/PREROUTING)
these packets then hit the squid intercept rule, and get sent to squid running locally, (filter/INPUT)
it then gets processed by squid. and gets sent to its destination of 74.125.237.82


As I said though, I stand to be corrected on that..
Thank you very much, i am getting better now

According to the linked picture and if i follow your reasonning:
1) Network B >>> data for the firewall>>>filter INPUT (looking for DNS(resolving)
2) if the resolving is done
3) Network B >>>>>Network A however the NAT PREROUTING stops the packet (squid) and the packet will follows the other way:
Data for the firewall>>>>>>filter INPUT>>>>Network A

I think it make sence and is logic.
It is not obvious at all for some one who tries to learn (Netfilter) as an indepent follow (needs help).

Even if some one reads a lot of books, i think still an expert is needed (a least in the beginning) right !!

Thanks a lot for your patience

red
 
Old 11-08-2011, 05:01 AM   #8
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
I am a welder by trade, and I figured it out. Largely from that link I keep referring people to.
If I can do it, anyone can..

Another handy note, when working on something remotely, (a VPS for example), before I load a new set of rules, or substantially change things. I always set up a cron/at job to load a very basic default set of rules, in the event I have one of those facepalm moments and DROP ssh without leaving it open to my IP, or something equally as stupid..
 
  


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 dropping established packet ? zitak Linux - Security 2 02-01-2011 02:31 AM
[SOLVED] iptables not dropping ip zamorac Linux - Security 5 05-01-2010 08:39 AM
iptables not dropping packets? Petro P Linux - Networking 0 07-03-2008 11:21 PM
iptables - dropping an ip *range* chibi Linux - Security 6 12-17-2005 08:22 PM

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

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