端口 53 上的 DNS 中继 UDP

发布于 2024-09-27 10:23:23 字数 1692 浏览 2 评论 0原文

我注意到 BT Home 从他们的 DNS 服务器发回虚假的 DNS 结果,这允许网站绕过我在防火墙中阻止的 IP 地址,因此我希望创建自己的 DNS 中继/服务器。

到目前为止,我可以在 UDP 端口 53 上接收请求,并将它们发送到 DNS 服务器并获得有效的 byte[] 流结果,然后使用发出请求的远程客户端端口发送回浏览器,但浏览器只是发送再次请求返回。

我已经从套接字测试了代码,结果工作正常,但由于某种原因 IE/FF 根本不会排除结果。

    public void Listen()
    {
        receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp );
        receiveEndPoint = new IPEndPoint(IPAddress.Any, receivePort); receiveSocket.Bind(receiveEndPoint); 
        receivePort = (receiveSocket.LocalEndPoint as IPEndPoint).Port; 
        receiveBuffer = new byte[BufferSize]; 
        receiveAsyncResult = receiveSocket.BeginReceiveFrom(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ref receiveEndPoint, new AsyncCallback(NetworkMessageReceivedCallback), receiveSocket);
    }


    public void NetworkMessageReceivedCallback(IAsyncResult asyncResult)
    {
        EndPoint remoteEndPoint = null;            
        byte[] bytes = null;                        
        remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); //Will contain the clients port                
        int bytesRead = receiveSocket.EndReceiveFrom(asyncResult, ref remoteEndPoint);                                              
        bytes = new Byte[bytesRead];                
        Buffer.BlockCopy(receiveBuffer, 0, bytes, 0, bytesRead);
       //string ip = "208.67.222.222";
       string ip = "192.168.1.254";
       IPAddress dnsServer = IPAddress.Parse(ip);
       Response R = Resolver.Lookup(bytes, dnsServer);
       receiveSocket.SendTo(R.Message , remoteEndPoint);//127.0.0.1
       receiveSocket.Close();
       Listen();
    }

I noticed that BT Home are sending back fake DNS results from their DNS servers and this allows sites to bypass the IP addresses i have blocked in the firewall so i was looking to create my own DNS relay/server.

So far i can receive request on UDP port 53 and send them off to the DNS server and get a valid byte[] stream result and i then send back to the browser using the remote client port the request was made on but the browser just sends the request back again.

I've tested the code from a socket and the results work OK but for some reason IE/FF simply will not except the results.

    public void Listen()
    {
        receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp );
        receiveEndPoint = new IPEndPoint(IPAddress.Any, receivePort); receiveSocket.Bind(receiveEndPoint); 
        receivePort = (receiveSocket.LocalEndPoint as IPEndPoint).Port; 
        receiveBuffer = new byte[BufferSize]; 
        receiveAsyncResult = receiveSocket.BeginReceiveFrom(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ref receiveEndPoint, new AsyncCallback(NetworkMessageReceivedCallback), receiveSocket);
    }


    public void NetworkMessageReceivedCallback(IAsyncResult asyncResult)
    {
        EndPoint remoteEndPoint = null;            
        byte[] bytes = null;                        
        remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); //Will contain the clients port                
        int bytesRead = receiveSocket.EndReceiveFrom(asyncResult, ref remoteEndPoint);                                              
        bytes = new Byte[bytesRead];                
        Buffer.BlockCopy(receiveBuffer, 0, bytes, 0, bytesRead);
       //string ip = "208.67.222.222";
       string ip = "192.168.1.254";
       IPAddress dnsServer = IPAddress.Parse(ip);
       Response R = Resolver.Lookup(bytes, dnsServer);
       receiveSocket.SendTo(R.Message , remoteEndPoint);//127.0.0.1
       receiveSocket.Close();
       Listen();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2024-10-04 10:23:23

我从未处理过 C# 中的原始 DNS,但看起来您正试图解析从客户端收到的字节,而不是将它们中继到 DNS 服务器。

您从 UDP 套接字读取的消息包含 DNS 查询,而不仅仅是主机名。查看 RFC 2929 了解其中的内容。

您可能对这个小而伟大的 DNS 过滤器感兴趣 - adsuck - 由 Marco Peereboom 开发(尽管它适用于 Unix) ,而不是 Windows)。

I never dealt with raw DNS from C# but it looks like you are trying to resolve the bytes you received from the client, instead of just relaying them to the DNS server.

The message you read off the UDP socket contains a DNS query, not just a host name. Take a look at the RFC 2929 for what goes in there.

You might be interested in this little but great DNS filter - adsuck - by Marco Peereboom (though it's for Unix, not Windows).

盗梦空间 2024-10-04 10:23:23

另外,您不应该尝试监听 UDP 和 TCP。我认为UDP主要用于权威DNS查询。

Also, shouldn't your try and listen to UDP and TCP. I think UDP is used mostly for authoritative DNS queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文