internal static void ProcessDNSRequest(byte[] data, string clientIP, int clientPort, string sourceIP, int sourcePort) { DNSPacket packet = new DNSPacket(data) { Host = Program.argDNSHost, TTL = uint.Parse(Program.argDNSTTL) }; DNSListener listener = new DNSListener(UInt32.Parse(Program.argDNSTTL)); if (!packet.Header.IsDynamicUpdateRequest()) { if (packet.Header.IsQuery()) { if (listener.Check(packet.Question.Name, packet.Question.Type, clientIP, out string message)) { byte[] buffer = packet.GetBytes(UInt32.Parse(Program.argDNSTTL), Program.dnsSerial, Program.argSpooferIP, Program.argSpooferIPv6); if (!Utilities.ArrayIsNullOrEmpty(buffer)) { UDPSocket.SendTo(clientIP, clientPort, sourceIP, sourcePort, buffer, false); } } Output.SpooferOutput("DNS", packet.Question.Type, packet.Question.Name, clientIP, message); } } else { byte[] flags = new byte[2] { 0xa8, 0x05 }; byte[] dnsPayload = new byte[data.Length - 2]; System.Buffer.BlockCopy(data, 2, dnsPayload, 0, dnsPayload.Length); MemoryStream dnsMemoryStream = new MemoryStream(); dnsMemoryStream.Write(data, 0, data.Length); dnsMemoryStream.Position = 2; dnsMemoryStream.Write(flags, 0, 2); UDPSocket.SendTo(clientIP, clientPort, sourceIP, sourcePort, dnsMemoryStream.ToArray(), false); } }
protected virtual void ProcessRequest(byte[] data, UDPListener udpListener, IPEndPoint ipEndPoint, string replyIP, string replyIPv6) { string clientIP = ipEndPoint.Address.ToString(); DNSPacket packet = new DNSPacket(data) { Host = this.Host, TTL = this.TTL }; if (packet.Header.IsQuery()) { if (!packet.Header.IsDynamicUpdateRequest()) { if (Check(packet.Question.Name, packet.Question.Type, clientIP, out string message)) { byte[] buffer; buffer = packet.GetBytes(this.TTL, this.Serial, replyIP, replyIPv6); SendTo(buffer, udpListener, ipEndPoint); } Output("DNS", clientIP, packet.Question.Name, packet.Question.Type, message); } else { byte[] flags = new byte[2] { 0xa8, 0x05 }; byte[] dnsPayload = new byte[data.Length - 2]; System.Buffer.BlockCopy(data, 2, dnsPayload, 0, dnsPayload.Length); MemoryStream dnsMemoryStream = new MemoryStream(); dnsMemoryStream.Write(data, 0, data.Length); dnsMemoryStream.Position = 2; dnsMemoryStream.Write(flags, 0, 2); SendTo(dnsMemoryStream.ToArray(), udpListener, ipEndPoint); } } }