Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Jason Opperisano <opie@817west.com>
To: netfilter@lists.netfilter.org
Subject: RE: How to block only MX query made to DNS server
Date: Tue, 30 Nov 2004 08:17:50 -0500	[thread overview]
Message-ID: <1101820669.2881.11.camel@hubcap.ljm.dom> (raw)
In-Reply-To: <20041130072636.72194.qmail@web12308.mail.yahoo.com>

On Tue, 2004-11-30 at 02:26, pravin rane wrote:
> Dear Hudson,
> 
> We are in to the Linux Solution provider.
> 
> One of our client has taken SILVER PLAN from XXX ISP
> According to this plan the client can only use ports
> TCP, UDP. 53,25,110,143,80,81 and ports above 1024 for
> out side.
> Here client can only make normal DNS queries. MX type
> of queries get response like "name server can not be
> reached" .
> 
> We have installed an Internal Mail-server (Sendmail).
> Since ISP have blocked MX query to any DNS server
> Out-side sendmail is not able to send mails out-side. 
> 
> I know I can tell sendmail not to use DNS. But before
> implementing this new setup at client I want to test
> it in my LABS. I want to create the same scenario as
> that ISP have done.
> 
> Seeking Urgent help form Netfilter Experts.
> 
> Bye 
> Pravin

you could also do this (since it's a lab scenario):

1)  make sure your firewall points to whatever DNS server you wish and
can resolve whatever RR types you wish.

2)  use these rules to redirect DNS traffic to what we will call a
"lightweight" DNS proxy on the firewall:

    iptables -t nat -A PREROUTING -i $INSIDE_IF -p udp --dport 53 \
      -j REDIRECT --to-ports 5353

    iptables -A INPUT -i $INSIDE_IF -p udp --dport 5353 -j ACCEPT

3)  grab the Net::DNS perl module and run the following script which
should resolve any query but MX:

--- BEGIN PERL SCRIPT ---
#!/usr/bin/perl

use strict;
use Net::DNS;
use Net::DNS::Nameserver;
use Net::DNS::Resolver;

my $listenip = "127.0.0.1";
my $listenport = "5353";
my $verbose = 1;

my $ns = Net::DNS::Nameserver->new(
       LocalAddr        => $listenip,
       LocalPort        => $listenport,
       ReplyHandler     => \&reply_handler,
       Verbose          => $verbose
);

sub reply_handler {
  my ($qname, $qclass, $qtype, $peerhost) = @_;
  my ($rcode, @ans, @auth, @add);

  if ($qtype eq "MX") {
    $rcode = "NXDOMAIN";
    return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
  } else {
    my $res   = Net::DNS::Resolver->new;
    my $query = $res->search("$qname", "$qtype", "$qclass");
    if ($query) {
      foreach my $rr ($query->answer) {
        next if $rr->type eq "CNAME";
        push @ans, Net::DNS::RR->new($rr->string);
        $rcode = "NOERROR";
        return ($rcode, \@ans, \@auth, \@add);
      }
    }
  }
}

$ns->main_loop;
---  END PERL SCRIPT  ---

  $ dig yahoo.com mx

should return a list of mail servers; whereas,

  $ dig @127.0.0.1 -p 5353 yahoo.com mx

should not.

i do not believe in the string match.

-j

--
"I'm not a bad guy! I work hard, and I love my kids. So why should
 I spend half my Sunday hearing about how I'm going to Hell?"
	--The Simpsons



  reply	other threads:[~2004-11-30 13:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-29 18:27 How to block only MX query made to DNS server Hudson Delbert J Contr 61 CS/SCBN
2004-11-30  7:26 ` pravin rane
2004-11-30 13:17   ` Jason Opperisano [this message]
2004-11-30 14:28     ` Jason Opperisano
  -- strict thread matches above, loose matches on Subject: below --
2004-11-30 10:36 hclfm
2004-11-30 11:46 ` Leonardo Rodrigues Magalhães
2004-11-30 11:50 ` pravin rane
     [not found] <OFF16F8905.C3905D39-ON65256F5C.002D9EA6@pricol.co.in>
2004-11-30  8:53 ` pravin rane
2004-11-30 12:35   ` a.ledvinka
2004-11-27 21:23 Daniel Chemko
2004-11-28  4:17 ` pravin rane
2004-11-28  6:21   ` Jason Opperisano
2004-11-27  9:51 pravin rane
2004-11-28  7:40 ` Tom Marshall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1101820669.2881.11.camel@hubcap.ljm.dom \
    --to=opie@817west.com \
    --cc=netfilter@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox