UDP DNS Response

239 views
Skip to first unread message

Burak Özalp

unread,
Aug 20, 2015, 2:50:21 AM8/20/15
to dnspython-users
Assume that i am a firewall between client and server. If client send an UDP DNS query, I should response this query with set the truncated flag=1. As a result, client will be forced to use TCP instead of UDP.

Is it possible to generate such UDP responses with DNS.python?


Anand Buddhdev

unread,
Aug 20, 2015, 3:44:34 AM8/20/15
to Burak Özalp, dnspython-users
On 20/08/15 08:50, Burak Özalp wrote:

Hi Burak,
I don't like your idea of intercepting DNS packets and messing around
with them. But... it should be possible.

Assuming you have already received a query and it is stored in the
variable q, then you can do:

r = dns.message.make_response(q, our_payload=512)
r.flags += dns.flags.TC

This will give you an empty response message with the TC flag set. Now
you can send it to the client.

Regards,
Anand

Burak Özalp

unread,
Aug 21, 2015, 7:27:33 AM8/21/15
to dnspython-users


I wrote the following code( http://codepad.org/Y7R8R5dw)  to listen o UDP port like a server, and response the client with changed the Truncated Bit=1. But i have two problems;

1) The program doesn't terminate and stuck on the line "  response=dns.query.udp(r,UDP_IP,port=UDP_PORT)"
2) I manage the response the request query but i couldn't manage to change destination and source ports, the destination port still same both on request and response.

Could anyone has a solution ?

Thanks,
Best Regards
Burak Ozalp

Anand Buddhdev

unread,
Aug 21, 2015, 7:35:00 AM8/21/15
to Burak Özalp, dnspython-users
On 21/08/15 13:27, Burak Özalp wrote:

Hi Burak,

> I wrote the following code( http://codepad.org/Y7R8R5dw) to listen o UDP
> port like a server, and response the client with changed the Truncated
> Bit=1. But i have two problems;
>
>
> 1) The program doesn't terminate and stuck on the line "
> response=dns.query.udp(r,UDP_IP,port=UDP_PORT)"

The dns.query.udp function is ONLY for SENDING queries, not for
receiving anything from the network.

In order to write a server for listening to the network, and receiving
DNS queries, you'll have to use something like the SocketServer module.
The dnspython module does not contain any server code.

Regards,
Anand

Burak Özalp

unread,
Aug 21, 2015, 8:30:33 AM8/21/15
to dnspython-users
Dear Anand,

As you can see from the code, i use socket module to receive from network, and i use pythondns only for sending response.

Best Regards
Burak Ozalp



 Hi Burak, 

Bob Halley

unread,
Aug 22, 2015, 8:40:07 AM8/22/15
to dnspython-users


On Friday, August 21, 2015 at 5:30:33 AM UTC-7, Burak Özalp wrote:

As you can see from the code, i use socket module to receive from network, and i use pythondns only for sending response.


dns.query.udp() is used for making queries and waiting for a response.  You're sending a response, so it's not appropriate.

You want to do

wire = r.to_wire()
sock.sendto(wire, addr) 
Reply all
Reply to author
Forward
0 new messages