All of lore.kernel.org
 help / color / mirror / Atom feed
* Differentiating direct, and redirected access?
@ 2004-10-18  2:19 J Kim
  2004-10-18 15:50 ` Aleksandar Milivojevic
  2004-10-18 18:14 ` Jose Maria Lopez
  0 siblings, 2 replies; 8+ messages in thread
From: J Kim @ 2004-10-18  2:19 UTC (permalink / raw)
  To: netfilter

Hello all,

I'm running a squid at port 3128 as a transparent proxy.

There are requests coming directly to 3128 port and 
those coming to 80 port and then redirected to 3128 by 
following rule:

-t nat -A PREROUTING -i eth0 -p tcp -m tcp \
   --dport 80 -j REDIRECT --to-ports 3128

What I want is block direct requests to 3128, allowing
redirected access (transparent proxy) only. How do I do it?

If I just set up a rule in filter chain like:

-t filter -A INPUT -i eth0 -p tcp -m tcp \\ 
   --dport 3128 -j DROP 

Those requests redirected from port 80 to 3128 are also
blocked by this rule. It seems that the redirected packets
come in to this chain once again with the new port number.

How can I differentiate these two different kinds of
request? Any clue will be greatly appreciated.

Jinsuk Kim



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Differentiating direct, and redirected access?
@ 2004-10-18 14:24 Jason Opperisano
  2004-10-18 17:34 ` Ложечник Александр
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Opperisano @ 2004-10-18 14:24 UTC (permalink / raw)
  To: netfilter

> Hello all,
>
> I'm running a squid at port 3128 as a transparent proxy.
>
> There are requests coming directly to 3128 port and
> those coming to 80 port and then redirected to 3128 by
> following rule:
>
> -t nat -A PREROUTING -i eth0 -p tcp -m tcp \
>    --dport 80 -j REDIRECT --to-ports 3128
>
> What I want is block direct requests to 3128, allowing
> redirected access (transparent proxy) only. How do I do it?
>
> If I just set up a rule in filter chain like:
>
> -t filter -A INPUT -i eth0 -p tcp -m tcp \\
>    --dport 3128 -j DROP
>
> Those requests redirected from port 80 to 3128 are also
> blocked by this rule. It seems that the redirected packets
> come in to this chain once again with the new port number.
>
> How can I differentiate these two different kinds of
> request? Any clue will be greatly appreciated.
>
> Jinsuk Kim

mark the packets that will get redirected, and only accept them if they
have the mark:

  # mark packets with dst port 80
  iptables -t mangle -A PREROUTING -i eth0 -p tcp --dport 80 \
    -j MARK --set-mark 1

  # redirect port 80 to 3128
  iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 \
    -j REDIRECT --to-ports 3128

  # accept packets to 3128 that have the mark
  iptables -A INPUT -i eth0 -p tcp --dport 3128 -m mark --mark 1 \
    -j ACCEPT

-j


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Differentiating direct, and redirected access?
@ 2004-10-18 14:40 Jason Opperisano
  2004-10-18 18:18 ` Ложечник Александр
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Opperisano @ 2004-10-18 14:40 UTC (permalink / raw)
  To: netfilter

> -t nat -A PREROUTING -i eth0 -d ! $INT_ROUTER_IP -p tcp --dport 80 -j
> REDIRECT --to-ports 3128
> -A INPUT -i eth0 -d $INT_ROUTER_IP -p tcp --dport 3128 -J REJECT
>
> TCP SYN have external ip dst_ip.

the TCP SYN to port 80 has the dst IP of the web server on the internet.

the redirected packet to TCP port 3128 has the dst IP of the redirected
interface (eth0 in this case).

your suggested REJECT rule will reject all redirected traffic to port
3128, and is essentially the issue the OP had already run into, and was
asking for a work-around.

-j


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Differentiating direct, and redirected access?
  2004-10-18  2:19 J Kim
@ 2004-10-18 15:50 ` Aleksandar Milivojevic
  2004-10-18 18:14 ` Jose Maria Lopez
  1 sibling, 0 replies; 8+ messages in thread
From: Aleksandar Milivojevic @ 2004-10-18 15:50 UTC (permalink / raw)
  To: netfilter

J Kim wrote:
> Hello all,
> 
> I'm running a squid at port 3128 as a transparent proxy.
> 
> There are requests coming directly to 3128 port and 
> those coming to 80 port and then redirected to 3128 by 
> following rule:
> 
> -t nat -A PREROUTING -i eth0 -p tcp -m tcp \
>    --dport 80 -j REDIRECT --to-ports 3128
> 
> What I want is block direct requests to 3128, allowing
> redirected access (transparent proxy) only. How do I do it?
> 
> If I just set up a rule in filter chain like:
> 
> -t filter -A INPUT -i eth0 -p tcp -m tcp \\ 
>    --dport 3128 -j DROP 
> 
> Those requests redirected from port 80 to 3128 are also
> blocked by this rule. It seems that the redirected packets
> come in to this chain once again with the new port number.

This is because PREROUTING chain is done before INPUT chain, so dst port 
of packets was already modified to 3128.  You need to drop packets in 
PREROUTING chain, before REDIRECT rule:

   -t nat -A PREROUTING ..... --dport 3128 -j DROP
   -t nat -A PREROUTING ..... --dport 80 -j REDIRECT ....

BTW, question for smarter than me, if there are rules in both nat and 
mangle PREROUTING chains, which are traversed first?  If mangle is done 
before nat, than one solution could also be:

   -t mangle -A PREROUTING .....  --dport 3128 -j MARK --set-mark 1
   -t nat -A PREROUTING ..... --dport 80 -j REDIRECT .....
   -t filter -A INPUT .... -m mark --mark 1 -j DROP

Suboptimal (more work), but should work if for whatever reason somebody 
wants to keep all filtering to filter table (if mangle table is done 
before nat table, of course).

It would be ideal (and most optimal) if the match was possible in filter 
table based on original value of dst port.  Kind of vaugly remember 
reading about such an extension, but I might be wrong (it might not exist).

-- 
Aleksandar Milivojevic <amilivojevic@pbl.ca>    Pollard Banknote Limited
Systems Administrator                           1499 Buffalo Place
Tel: (204) 474-2323 ext 276                     Winnipeg, MB  R3T 1L7


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Differentiating direct, and redirected access?
  2004-10-18 14:24 Differentiating direct, and redirected access? Jason Opperisano
@ 2004-10-18 17:34 ` Ложечник Александр
  0 siblings, 0 replies; 8+ messages in thread
From: Ложечник Александр @ 2004-10-18 17:34 UTC (permalink / raw)
  To: netfilter


>>Hello all,
>>
>>I'm running a squid at port 3128 as a transparent proxy.
>>
>>There are requests coming directly to 3128 port and
>>those coming to 80 port and then redirected to 3128 by
>>following rule:
>>
>>-t nat -A PREROUTING -i eth0 -p tcp -m tcp \
>>   --dport 80 -j REDIRECT --to-ports 3128
>>
>>What I want is block direct requests to 3128, allowing
>>redirected access (transparent proxy) only. How do I do it?
>>
>>If I just set up a rule in filter chain like:
>>
>>-t filter -A INPUT -i eth0 -p tcp -m tcp \\
>>   --dport 3128 -j DROP
>>
>>Those requests redirected from port 80 to 3128 are also
>>blocked by this rule. It seems that the redirected packets
>>come in to this chain once again with the new port number.
>>
>>How can I differentiate these two different kinds of
>>request? Any clue will be greatly appreciated.
>>
>>Jinsuk Kim
>>    
>>
-t nat -A PREROUTING -i eth0 -d ! $INT_ROUTER_IP -p tcp --dport 80 -j 
REDIRECT --to-ports 3128
-A INPUT -i eth0 -d $INT_ROUTER_IP -p tcp --dport 3128 -J REJECT

TCP SYN have external ip dst_ip.

-- 
wbr, Logechnik Alexandr

In God we trust, but something 
else must have X.509 certificate



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Differentiating direct, and redirected access?
  2004-10-18  2:19 J Kim
  2004-10-18 15:50 ` Aleksandar Milivojevic
@ 2004-10-18 18:14 ` Jose Maria Lopez
  1 sibling, 0 replies; 8+ messages in thread
From: Jose Maria Lopez @ 2004-10-18 18:14 UTC (permalink / raw)
  To: netfilter@lists.netfilter.org

bl	 -El lun, 18 de 10 de 2004 a las 04:19, J Kim escribió:
> Hello all,
> 
> I'm running a squid at port 3128 as a transparent proxy.
> 
> There are requests coming directly to 3128 port and 
> those coming to 80 port and then redirected to 3128 by 
> following rule:
> 
> -t nat -A PREROUTING -i eth0 -p tcp -m tcp \
>    --dport 80 -j REDIRECT --to-ports 3128
> 
> What I want is block direct requests to 3128, allowing
> redirected access (transparent proxy) only. How do I do it?
> 
> If I just set up a rule in filter chain like:
> 
> -t filter -A INPUT -i eth0 -p tcp -m tcp \\ 
>    --dport 3128 -j DROP 
> 
> Those requests redirected from port 80 to 3128 are also
> blocked by this rule. It seems that the redirected packets
> come in to this chain once again with the new port number.
> 
> How can I differentiate these two different kinds of
> request? Any clue will be greatly appreciated.
> 
> Jinsuk Kim

Insert your DROP rule in the nat table, in the
PREROUTING chain before the rule that does the
redirect.

-- 
Jose Maria Lopez Hernandez
Director Tecnico de bgSEC
jkerouac@bgsec.com
bgSEC Seguridad y Consultoria de Sistemas Informaticos
http://www.bgsec.com
ESPAÑA

The only people for me are the mad ones -- the ones who are mad to live,
mad to talk, mad to be saved, desirous of everything at the same time,
the ones who never yawn or say a commonplace thing, but burn, burn, burn
like fabulous yellow Roman candles.
                -- Jack Kerouac, "On the Road"



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Differentiating direct, and redirected access?
  2004-10-18 14:40 Jason Opperisano
@ 2004-10-18 18:18 ` Ложечник Александр
  0 siblings, 0 replies; 8+ messages in thread
From: Ложечник Александр @ 2004-10-18 18:18 UTC (permalink / raw)
  To: netfilter

Jason Opperisano wrote:

>>-t nat -A PREROUTING -i eth0 -d ! $INT_ROUTER_IP -p tcp --dport 80 -j
>>REDIRECT --to-ports 3128
>>-A INPUT -i eth0 -d $INT_ROUTER_IP -p tcp --dport 3128 -J REJECT
>>
>>TCP SYN have external ip dst_ip.
>>    
>>
>
>the TCP SYN to port 80 has the dst IP of the web server on the internet.
>
>the redirected packet to TCP port 3128 has the dst IP of the redirected
>interface (eth0 in this case).
>
>your suggested REJECT rule will reject all redirected traffic to port
>3128, and is essentially the issue the OP had already run into, and was
>asking for a work-around.
>
>-j
>
Hmm. Your right. So, fw-mark is great idea.

 
wbr, Logechnik Alexandr

In God we trust, but something 
else must have X.509 certificate



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Differentiating direct, and redirected access?
@ 2004-10-19  2:15 J Kim
  0 siblings, 0 replies; 8+ messages in thread
From: J Kim @ 2004-10-19  2:15 UTC (permalink / raw)
  To: netfilter

Thank you very much Jason, Jose, Aleksandar, and
&#1051;&#1086;&#1078;&#1077;&#1095;&#1085;&#1080;&#1082; for all the replies. I
chose the simplest suggestion (putting drop rule before redirect in nat
prerouting chain), and now it works perfect. You guys are great.

Jinsuk Kim


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-10-19  2:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-18 14:24 Differentiating direct, and redirected access? Jason Opperisano
2004-10-18 17:34 ` Ложечник Александр
  -- strict thread matches above, loose matches on Subject: below --
2004-10-19  2:15 J Kim
2004-10-18 14:40 Jason Opperisano
2004-10-18 18:18 ` Ложечник Александр
2004-10-18  2:19 J Kim
2004-10-18 15:50 ` Aleksandar Milivojevic
2004-10-18 18:14 ` Jose Maria Lopez

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.