DNS抓包分析--wireshark

本文详细介绍了如何使用Wireshark抓包工具定位DNS查询,包括递归和迭代查询的区别,以及DNS报文格式解析。通过实例演示了DNS查询过程,并展示了如何通过dig命令触发DNS查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DNS抓包分析–wireshark

DNS-(Domain Name System,域名系统),是因特网上作为余名和IP地址相互映射的一个分布式数据库,能够使用户更加方便地访问互联网,而不是去记住能够被机器直接读取的IP数串。通过主机名,从而得到主机名对应的IP地址的过程叫做余名解析或者主机名解析。DNS运行在UDP协议之上,使用端口号53。

这里主要说明DNS如何使用wireshark抓包定位的,关于什么是DNS可以结合百度百科看下,已经写的很详细了。简单的来说域名就是你家地址浙江杭州滨江…,要把邮件寄到你家但是电脑不能直接识别地址就需要转换成东经多少北纬多少的IP地址,这个转换工作由DNS完成,DNS根服务器,其他的镜像服务器根据根服务器来进行地址转换.

DNS有称为IP翻译官,其具体工作流程如下:

                 Local Host                        |  Foreign
                                                   |
    +---------+               +----------+         |  +--------+
    |         | user queries  |          |queries  |  |        |
    |  User   |-------------->|          |---------|->|Foreign |
    | Program |               | Resolver |         |  |  Name  |
    |         |<--------------|          |<--------|--| Server |
    |         | user responses|          |responses|  |        |
    +---------+               +----------+         |  +--------+
                                |     A            |
                cache additions |     | references |
                                V     |            |
                              +----------+         |
                              |  cache   |         |
                              +----------+         |

举例:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-EQpctwOR-1601910970815)(picture/image-20201005170645695.png)]

DNS的两种查询方式

  • 递归查询,主机向本地域名服务器的查询一般都是采用递归查询,如果主机所询问的本地域名服务器不指定被查询的域名的IP地址,那么本地域名服务器就以客户的身份,向其他根域名服务器继续发出查询请求报文。
  • 迭代查询,本地域名服务器向根域名服务器的查询通常采用迭代查询,当根域名服务器收到本地域名服务器的查询请求报文时,要么给出要查询的IP地址,要么告诉本地域名服务器下一步向那个域名服务器进行查询,然后让本地域名服务器进行后续的查询。

DNS常用问题类型

DNS查询和相应中所使用的类型域,指明了这个查询或者响应的资源记录类型。

类型描述
1AIPv4主机地址
2NS权威域名服务器
5CNAME规范别名,定义主机正式名字的别名
12PTR指针,把IP地址转换为域名
15MX邮件交换记录,用于电子邮件系统发送
邮件根据收件人的地址后缀
定位邮件服务器
16TXT文本字符串
28AAAAIPv6主机地址
251IXFR增量区域传送
252AXFR完整区域传送

捕获DNS数据

开启wireshark开始抓包,然后使用dig触发一个DNS查询

dig www.baidu.com

命令dig的常用方式和说明

dig
DNS Lookup utility.

 - Lookup the IP(s) associated with a hostname (A records):
   dig +short {{example.com}}

 - Lookup the mail server(s) associated with a given domain name (MX record):
   dig +short {{example.com}} MX

 - Get all types of records for a given domain name:
   dig {{example.com}} ANY

 - Specify an alternate DNS server to query:
   dig @{{8.8.8.8}} {{example.com}}

 - Perform a reverse DNS lookup on an IP address (PTR record):
   dig -x {{8.8.8.8}}

 - Find authoritative name servers for the zone and display SOA records:
   dig +nssearch {{example.com}}

 - Perform iterative queries and display the entire trace path to resolve a domain name:
   dig +trace {{example.com}}

DNS报文格式解析

                                    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 ID号:用来对应DNS查询和DNS响应
  • 查询/响应(Query/Response):用来指明这个报文是DNS查询还是响应,占1比特位,1表示是响应,0表示是查询
  • 操作代码OpCode: 用来定义消息中请求的类型,占4比特位
  • AA: 权威应答,如果设置了这个位,这说明这个响应是由权威域名服务器发出的,占1比特位。
  • TC:截断,由于响应时间太长,无法接入报文而被截断。该标志为1时说明响应已经超过512字节并已被截断
  • 期望递归(Recursion Desired,RD):请求中设定了这个值,说明DNS客户端在目标域名服务器不含有所请求信息的情况下,要求进行递归查询。
  • RA: 可用递归,当设置了这个值,说明域名服务器支持递归查询。
  • 保留Z: 全部设置为0,但是有时候会作为RCODE位的扩展
  • RCODE: Response Code 响应代码,在DNS响应中,用来指明错误,占4个比特位。 含义如下:
    1. 0表示没有错误
    2. 1表示个数错误
    3. 2表示域名服务器上存在问题
    4. 3表示域参数问题
    5. 4表示类型不支持
    6. 5表示管理上被禁止
    7. 6-15表示保留
  • QDCOUNT:问题计数,在问题区段中的条目数
  • ANCOUNT: 在回答区段中的条目数
  • NSCOUNT: 域名服务器计数,在权威区段的域名资源记录数
  • ARCOUNT: 再额外信息区段中的其他资源记录数

报文说明

Domain Name System (query)
    Transaction ID: 0x9ad0                              #事务ID
    Flags: 0x0000 Standard query                        #报文中的标志字段
        0... .... .... .... = Response: Message is a query
                                                        #QR字段, 值为0, 因为是一个请求包
        .000 0... .... .... = Opcode: Standard query (0)
                                                        #Opcode字段, 值为0, 因为是标准查询
        .... ..0. .... .... = Truncated: Message is not truncated
                                                        #TC字段
        .... ...0 .... .... = Recursion desired: Don't do query recursively 
                                                        #RD字段
        .... .... .0.. .... = Z: reserved (0)           #保留字段, 值为0
        .... .... ...0 .... = Non-authenticated data: Unacceptable   
                                                        #保留字段, 值为0
    Questions: 1                                        #问题计数, 这里有1个问题
    Answer RRs: 0                                       #回答资源记录数
    Authority RRs: 0                                    #权威名称服务器计数
    Additional RRs: 0                                   #附加资源记录数

协议交互过程报文

Frame 5: 87 bytes on wire (696 bits), 87 bytes captured (696 bits) on interface wlp4s0, id 0
Ethernet II, Src: Chongqin_e1:18:a9 (40:23:43:e1:18:a9), Dst: HIWIFI_65:b0:40 (d4:ee:07:65:b0:40)
Internet Protocol Version 4, Src: 192.168.199.235, Dst: 192.168.199.1
User Datagram Protocol, Src Port: 36025, Dst Port: 53
Domain Name System (query)  # DNS协议
    Transaction ID: 0x9f1c  # 事务ID编号
    Flags: 0x0100 Standard query
        0... .... .... .... = Response: Message is a query # DNS查询
        .000 0... .... .... = Opcode: Standard query (0) #操作代码
        .... ..0. .... .... = Truncated: Message is not truncated #截断
        .... ...1 .... .... = Recursion desired: Do query recursively #期望递归
        .... .... .0.. .... = Z: reserved (0)
        .... .... ...0 .... = Non-authenticated data: Unacceptable
    Questions: 1
    Answer RRs: 0
    Authority RRs: 0
    Additional RRs: 1
    Queries
        www.a.shifen.com: type A, class IN
            Name: www.a.shifen.com
            [Name Length: 16]
            [Label Count: 4]
            Type: A (Host Address) (1)
            Class: IN (0x0001)
    Additional records
        <Root>: type OPT
    [Response In: 6]

No.     Time           Source                Destination           Protocol Length Info
      6 0.013373576    192.168.199.1         192.168.199.235       DNS      289    Standard query response 0x9f1c A www.a.shifen.com A 180.101.49.12 A 180.101.49.11 NS ns3.a.shifen.com NS ns4.a.shifen.com NS ns5.a.shifen.com NS ns1.a.shifen.com NS ns2.a.shifen.com A 61.135.165.224 A 220.181.33.32 A 112.80.255.253 A 14.215.177.229 A 180.76.76.95 OPT

Frame 6: 289 bytes on wire (2312 bits), 289 bytes captured (2312 bits) on interface wlp4s0, id 0
Ethernet II, Src: HIWIFI_65:b0:40 (d4:ee:07:65:b0:40), Dst: Chongqin_e1:18:a9 (40:23:43:e1:18:a9)
Internet Protocol Version 4, Src: 192.168.199.1, Dst: 192.168.199.235
User Datagram Protocol, Src Port: 53, Dst Port: 36025
Domain Name System (response)
    Transaction ID: 0x9f1c
    Flags: 0x8180 Standard query response, No error
        1... .... .... .... = Response: Message is a response  #DNS回复
        .000 0... .... .... = Opcode: Standard query (0)
        .... .0.. .... .... = Authoritative: Server is not an authority for domain # 非权威应答
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... 1... .... = Recursion available: Server can do recursive queries #服务支持递归查询
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 1
    Answer RRs: 2
    Authority RRs: 5
    Additional RRs: 6
    Queries
        www.a.shifen.com: type A, class IN
            Name: www.a.shifen.com
            [Name Length: 16]
            [Label Count: 4]
            Type: A (Host Address) (1)
            Class: IN (0x0001)
    Answers
        www.a.shifen.com: type A, class IN, addr 180.101.49.12
        www.a.shifen.com: type A, class IN, addr 180.101.49.11
    Authoritative nameservers
        a.shifen.com: type NS, class IN, ns ns3.a.shifen.com
        a.shifen.com: type NS, class IN, ns ns4.a.shifen.com
        a.shifen.com: type NS, class IN, ns ns5.a.shifen.com
        a.shifen.com: type NS, class IN, ns ns1.a.shifen.com
        a.shifen.com: type NS, class IN, ns ns2.a.shifen.com
    Additional records
        ns1.a.shifen.com: type A, class IN, addr 61.135.165.224
        ns2.a.shifen.com: type A, class IN, addr 220.181.33.32
        ns3.a.shifen.com: type A, class IN, addr 112.80.255.253
        ns4.a.shifen.com: type A, class IN, addr 14.215.177.229
        ns5.a.shifen.com: type A, class IN, addr 180.76.76.95
        <Root>: type OPT
    [Request In: 5]
    [Time: 0.013373576 seconds]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Achilles.Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值