python - Malformed DNS packet scapy -
i have small python script acts proxy. seems working fine script except dns requests. when dns request received script preform request , forward response original user made dns request. when 1 originating dns request gets response it's considered malformed. know there dns issues older versions of scapy, updated scapy 2.3.1 still have problems.
#!/usr/bin/env python tornado.websocket import websockethandler tornado.httpserver import httpserver tornado.web import application tornado.ioloop import ioloop collections import defaultdict scapy.all import * import threading # warning: not thread-safe. # dictionary mapping (outbound.dst, outbound.dport) -> count of ip packets awaiting reply outbound_packets = defaultdict(int) outbound_udp = defaultdict(int) connection = none class packetsniffer(threading.thread): def __init__(self): threading.thread.__init__(self) def run(self): global connection while (true): pkt = sniff(iface="eth0", count=1) if pkt[0].haslayer(ip): pkt = pkt[0][ip] if outbound_packets[(pkt.src, pkt.sport)] > 0: outbound_packets[(pkt.src, pkt.sport)] -= 1 if pkt[0].haslayer(udp): # modify destination address address of tun on host. pkt.dst = "10.0.0.1" try: del pkt[udp].chksum del pkt[ip].chksum pkt.show2() # force recompute checksum except indexerror: print "error deleting" if connection: connection.write_message(str(pkt).encode('base64')) elif pkt[0].haslayer(tcp): print "tcp packet" # modify destination address address of tun on host. pkt.dst = "10.0.0.1" try: del pkt[tcp].chksum del pkt[ip].chksum pkt.show2() # force recompute checksum except indexerror: print "error deleting" if connection: connection.write_message(str(pkt).encode('base64'))
i'm no dns expert can tell response has answer rrs: 2
looking @ actual dns answers see 1 entry. safe assume answer rrs value should match number of actual answers? if case, idea how/why answers being removed dns entry?
scapy issue 913 , issue 5105 discuss problem , led me pull request 18 , pull request 91 fixed problem.
when applied these scapy 2.2.0 (not 2.3.1) line numbers didn't entirely match obvious things went. found , entered 18 first, 91 may enough fix problem.
Comments
Post a Comment