拦截DNS请求-推导QR,操作码,AA,TC等

时间:2018-06-28 05:27:18

标签: python python-3.x dns

试图通过旋转小型udp服务器来拦截传入的DNS请求,并最终尝试https://stackoverflow.com/a/16981944/9488865

Telegram

要推断QR,操作码,AA,TC等,我们正在做:

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR|   Opcode  |AA|TC|RD|RA|   Z    |   RCODE   |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

尽管Scapy使一切变得非常简单(https://stackoverflow.com/a/6732956/9488865),但我想借此机会在这里学到更多。

我如何找出使用0x8000、0x7800、0x0400 .. 0x70、0xF等来进行这些AND的操作?我们如何找到并锁定这些值?

1 个答案:

答案 0 :(得分:1)

DNS连线格式在https://www.rfc-editor.org/rfc/rfc1035.txt

中定义

例如,您有以下内容:

4.1.1. Header section format

The header contains the following fields:

                                    1  1  1  1  1  1
      0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                      ID                       |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |QR|   Opcode  |AA|TC|RD|RA|   Z    |   RCODE   |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    QDCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ANCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    NSCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ARCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

您在顶部看到的是字节,因此将显示为获取每个特定部分而必需的偏移量。

您还可以研究当前的DNS解析器/生成器库如何做到这一点,例如在Python中:https://github.com/rthalley/dnspython/blob/master/dns/message.py#L732