<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>NotionNext BLOG</title>
        <link>https://hexo.fridaylab.top/</link>
        <description>这是一个由NotionNext生成的站点</description>
        <lastBuildDate>Mon, 22 Apr 2024 03:15:23 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2024, Ryan Wu</copyright>
        <item>
            <title><![CDATA[为什么压力测试QPS总是上不去]]></title>
            <link>https://hexo.fridaylab.top/article/b4a0374c-5ebd-47da-998f-f368889a354e</link>
            <guid>https://hexo.fridaylab.top/article/b4a0374c-5ebd-47da-998f-f368889a354e</guid>
            <pubDate>Mon, 22 Apr 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-b4a0374c5ebd47da998ff368889a354e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><blockquote class="notion-quote notion-block-4df448eb51cb46a4a3fd2659dd034bba"><div>基于对DOT/DOH进行性能测试过程中遇到的几个问题进行总结</div></blockquote><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6ba6f928e1d447cd827d01b76798250f" data-id="6ba6f928e1d447cd827d01b76798250f"><span><div id="6ba6f928e1d447cd827d01b76798250f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6ba6f928e1d447cd827d01b76798250f" title="背景"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">背景</span></span></h2><div class="notion-text notion-block-87885fcd3d82481393cf5d0842d1fe22">每一个版本都会对dnproxy代理服务进行一次性能测试，主要的测试指标为：</div><ol start="1" class="notion-list notion-list-numbered notion-block-74528577ee2e47c6a9935ee0112588aa"><li>使用长链接时，doh、httpdns的QPS</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-aa7830cc7fea4697910dfc4a9104f0e0"><li>使用短链接时，doh、httpdns的QPS</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-7d1fa2851ed04d5ebf752ff6e2f0ee42"><li>开启缓存与未开缓存时，doh、httpdns的QPS</li></ol><div class="notion-text notion-block-0deb316d2eb54de48c59ec5846c0a113">测试使用的打压工具为：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/wg/wrk">wrk</a></div><div class="notion-text notion-block-95ff08d78e4c4795ae9c529cdcfbf71e">使用的命令如下：</div><div class="notion-text notion-block-6b629d18072b4a1587e0767d1fee089b">相关参数：
-t8：指定wrk使用的线程数为8
-c4000：指定建立的TCP连接数为4000个
-d 20: 指定打压的持续时间为20s
-H &quot;Connection: close&quot;： 加上该header表示使用短链接，否则默认wrk使用长链接
打压结束后会输出如下信息：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-420bee6ddd964b1d94a29ea9928a7035"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F321fc5ca-ab60-44f8-903a-408347205cf7%2FUntitled.png?table=block&amp;id=420bee6d-dd96-4b1d-94a2-9ea9928a7035&amp;t=420bee6d-dd96-4b1d-94a2-9ea9928a7035&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-588cc81b5152460593a7e64195723e77">其中最重要的指标就是Requests/sec即qps。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-067b499966eb40acad6fb4d685b22d7b" data-id="067b499966eb40acad6fb4d685b22d7b"><span><div id="067b499966eb40acad6fb4d685b22d7b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#067b499966eb40acad6fb4d685b22d7b" title="问题一：新机器测QPS上不去"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">问题一：新机器测QPS上不去</span></span></h2><div class="notion-text notion-block-e876d2b1ce2640f78580c60b7e5e8e2d">当时测试反馈使用dnsproxy在新物理机（16核）进行打压时QPS处于2w且CPU占用只有130%不到，不应该只有这么低的表现。由于dnsproxy这个程序并未进行任何代码的改动，之前是能够到达15w左右的QPS，所以先排除是代码修改引入的性能不佳问题，那么初步猜测可能是网络层面出现了什么问题。</div><div class="notion-text notion-block-c58cda9acddf4a90928816cb1ee015f8">在TCP进行三次握手的时候，linux内核会维护两个队列，分别是：</div><ul class="notion-list notion-list-disc notion-block-df7ab95aa43a4bd7ab93a20d3a738312"><li>半连接队列，也称 SYN 队列；</li></ul><ul class="notion-list notion-list-disc notion-block-79240de3a99844f29a66cbc1a5b84dfb"><li>全连接队列，也称 accept 队列；</li></ul><div class="notion-text notion-block-f76147ef9fd74abe8aff1f1735315dac">服务端收到客户端发起的 SYN 请求后，内核会把该连接存储到半连接队列，并向客户端响应 SYN+ACK，接着客户端会返回 ACK，服务端收到第三次握手的 ACK 后，内核会把连接从半连接队列移除，然后创建新的完全的连接，并将其添加到 accept 队列，等待进程调用 accept 函数时把连接取出来。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-6a54128d120c4d5fac9a85aece2bdccb"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=YzBjYjkwMDFkMThlYmJlOTNmZjA4YTZlMTJkYzQ5ZTFfT3FzQk9VUmxEemZJRk9valk3MHlsUXVHQ1c3MlZRcWlfVG9rZW46TERJTmJMb0JJb3dRSm54R0lVU2NMMlBSblpmXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=6a54128d-120c-4d5f-ac9a-85aece2bdccb" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-24bcef4c0faf4a629acb209307a6beb2">其中这两个队列在linux的系统参数中有对应的默认值，分别为：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-498b401adfaa44a5b5745f52442f0d02"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=NTMzZDViNTc3NzgxNzY2NjA0MmY4NGVjYjg2Y2NkMzhfSzBRMEpaUWhNNGg5WHM4SUFmZ0FyUUgxWndjZGJHdTNfVG9rZW46REtOdmI3OVV6bzlSNXh4Y2RpRWNQZjdTbnhmXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=498b401a-dfaa-44a5-b574-5f52442f0d02" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-78b4a67a7382403ebb25c236a8ce2ce4"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=MDdkMzNmZjlkNWY5ZWQ1ODFmNjNhYTU1ZGJhNTNlZWRfODFMdmJ0NTFsZ0tZSldYTWNrdlhVM2J5SG5JT0FJTURfVG9rZW46VEt0dGJROGo0bzA1dm94RUxJYWNMck1jbk1JXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=78b4a67a-7382-403e-bb25-c236a8ce2ce4" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-0a326706dccd4d21abe1b6d554c15545">全连接的的最大值由<code class="notion-inline-code">somaxconn</code>决定</div><div class="notion-text notion-block-a4cd8f798b8d4a00bff21191181c47ea">半连接的最大值由上面两个参数共同决定，计算方式和条件比较多感兴趣可自己查询</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-bb07b3cdf34147b88a092641d3bd256b" data-id="bb07b3cdf34147b88a092641d3bd256b"><span><div id="bb07b3cdf34147b88a092641d3bd256b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bb07b3cdf34147b88a092641d3bd256b" title="会不会是队列设置的太小导致的打压时很多tcp连接溢出后被丢弃了？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">会不会是队列设置的太小导致的打压时很多tcp连接溢出后被丢弃了？</span></span></h3><div class="notion-text notion-block-92d5975357ff4ee0bb3e80fbe5d0ec46">为了验证猜想，我们首先在服务端查看dnsproxy服务实际使用到的全连接队列是多少,使用<code class="notion-inline-code">ss -lnt</code>查看处于LISTEN状态的对应端口的Recv-Q及Send-Q。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-ee70993599c34c3497019f385e82f40f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=M2MyNjM1MGU2M2RkODgwMGY4YjkwOWYzOTJiMTlhNzlfN3BnbDZ2R0NSMEtzTjFlWnAxdFYwUzdMbUhZUUVERk9fVG9rZW46V25lNWJhYlk1b2c5VmN4RVltcmNUU29Lbm5oXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=ee709935-99c3-4c34-9701-9f385e82f40f" alt="notion image" loading="lazy" decoding="async"/></div></figure><ul class="notion-list notion-list-disc notion-block-25d274e1d99c41a39fc592cad8f677b4"><li>Recv-Q：当前全连接队列的大小，也就是当前已完成三次握手并等待服务端 <code class="notion-inline-code">accept()</code> 的 TCP 连接；</li></ul><ul class="notion-list notion-list-disc notion-block-2721ffb6cba64157ae87f5555c03d0a4"><li>Send-Q：当前全连接最大队列长度，下面的输出结果说明监听5353端口的 TCP 服务，最大全连接长度为4096；</li></ul><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-e71c23bbd3224ed29a80e65e3c34e9b3"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=ZDlmYTFiNWFjY2I2YjNiYWEzNDgyZjk4ZjgwZTQzY2NfVEN3aDc5b0xyMTJuY0tnaGQ2QUc1c3lKRFZXbW00b2VfVG9rZW46Tml3MGJmMEtQb2xTZGp4UlFWbWNtQmJCbjhkXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=e71c23bb-d322-4ed2-9a80-e65e3c34e9b3" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-8d6e0245b2584e15924c77d385788e4a">进行wrk持续打压发现，receive值一直没有超过其最大值</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-613c6bb573a14cf6838a045bc7bbdb86"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=OTFhMTk4NTI2ODEwNzE2NDQzYTkzYzFmYzFhMjdhYjZfSEpNQVUzTERDeHAzUnc5Z1kwS28zY2syejA2YU44QTVfVG9rZW46UHk0ZmJyWFdCb044TUJ4VVBuTGNFMVJWbmRlXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=613c6bb5-73a1-4cf6-838a-045bc7bbdb86" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-261d53a2a5594f47af1b84a5bf0aa3e0">查看是否存在队列溢出丢弃的情况，使用<code class="notion-inline-code">nestat -s |grep &#x27;overflowed&#x27;</code>发现并没有持续的正常，所以排除服务端连接队列参数过小导致的问题</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-639cfce1850948afbcd369310feb86d5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=MDE0ZDY5Y2EzMmZiOWZhOTZiZjA0ZGQ1MWE2MjhiMThfQjdKZmFvQllwSVRtMFFUdnlMTGpFUzRqbjdOUkFhZlpfVG9rZW46UTJvNmJIbEppb0VGMFZ4Nmd1cGNaWVd6bnhjXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=639cfce1-8509-48af-bcd3-69310feb86d5" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0d071422c1074da293f7f52e679fe034" data-id="0d071422c1074da293f7f52e679fe034"><span><div id="0d071422c1074da293f7f52e679fe034" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0d071422c1074da293f7f52e679fe034" title="会不会是客户端就没有建立那么多连接数？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">会不会是客户端就没有建立那么多连接数？</span></span></h3><div class="notion-text notion-block-3646e5ed8ff84f66b4bc436fd99944d9">使用ss -s 查看客户端和服务端的TCP连接数发现，和wrk设置的2000连接数相差不大，排除客户端的问题。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-e7eb2c1f17f34cc7bde824f13f12250e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=ODMzOWU2YzM3MjJjMDkwMThlOTUxZThlY2JkNWY5YThfdU0xWjZrRVZrdkNTbFMwYUdwTzFjcTI1OEJlRUlWbnhfVG9rZW46UHdvZGJtY3BvbzNhTzB4bzBHcWM1Wkc1bnNiXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=e7eb2c1f-17f3-4cc7-bde8-24f13f12250e" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1f8d9cd3efa04305a74d614f92c20e9a" data-id="1f8d9cd3efa04305a74d614f92c20e9a"><span><div id="1f8d9cd3efa04305a74d614f92c20e9a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1f8d9cd3efa04305a74d614f92c20e9a" title="会不会是网卡收包量或者路由器的问题？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">会不会是网卡收包量或者路由器的问题？</span></span></h3><div class="notion-text notion-block-586f17c73bae40c1a783608e44a0ad53">首先使用<code class="notion-inline-code">tcpdump - i zeth0 port 5353 -w dnsproxy.pcap</code>进行抓包，然后使用wireshark打开进行分析，这里分享几个技巧：</div><ol start="1" class="notion-list notion-list-numbered notion-block-6ffe1994f3b847419a7e1392f381ef19"><li>点击左下角的小圆点，wireshark会快速分析列出可能存在的问题，此时主要关注warning部分，如下面图所示可以看出存在两个需要关注的问题：</li><ol class="notion-list notion-list-numbered notion-block-6ffe1994f3b847419a7e1392f381ef19"><li>This frame is a (suspected) out-of-order segment</li><li>D-SACK Sequence</li></ol></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-c182ec453d454f109a7502ba8c45f5d9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=NWQxZTliZDI2NzEyMDJkMGMzZjU4MmVlZjViZmU1ZmJfSDI3dWc2QW9DVGFST3BFRVRDOFo2NXpTcG8ydEV6NHpfVG9rZW46WFNSR2JHSjJ6b1ZFWUt4VVhGamMxR0VXbmpkXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=c182ec45-3d45-4f10-9a75-02ba8c45f5d9" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-5450e8bbece54b2488788fece6d84405">展开起列表点击其中一条我们就定位到对应的行，发现存在大量的Retransmission以及Dup ACK说明出现了包大量重传的问题，那就可能出现了网络拥塞。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-f1a3962ffdc3493b9ee8abef754c03da"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=Y2U1ZWNiMDkzY2FjMDc4ZWEwZTNhMzA1ZDMxYmVhNzhfYXJ6RTNBM0NROWFLNUJmOFUxMXVHdUJEMkI1cmljUHVfVG9rZW46VlJPMWJCNWNOb0l0SjV4dFhmSGNqclM4bkdvXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=f1a3962f-fdc3-493b-9ee8-abef754c03da" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-8b9e453a198b4eeaac54ebcacb6f6874">我们进一步去验证起网卡收包流量情况，使用<code class="notion-inline-code">sar -n dev 1 100 |grep zeth0 </code>统计网卡的发送及接受流量。</div><div class="notion-text notion-block-a12677d85f734c5ca8c0fef80803dd8c">使用能够正常打压上去的物理机和有问题的机器进行对比，发现有问题的机器收包流量只有2m/s，是存在问题的。于是尝试使用换一个网卡直连的方式进行测试，发现流量正常了，QPS也上去了。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-8e0f92d1de1e461cba66d4e64db305e9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=ZTg1NzBmYTI2ODcyZmUzMmNiMDQxMGYyNjJlZTRjMjRfN2RORVdURFhLSkc3YnZ6cEhQMnJmM1dnZDZUWU5FcDdfVG9rZW46VU5HWWJPaTJ3bzlsZ1N4UTZHbWN1bThubllkXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=8e0f92d1-de1e-461c-ba66-d4e64db305e9" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1f0ba981db3745499ed0450ffe086b1a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=Y2YyY2NhYjRhNmM2NjViZGQ2MTgwOWM4ZmZlNGM0M2NfOXFYUTFidGs3ek1ueWxKbmdFT0F0N2NQS1VCSG1WeWtfVG9rZW46T2RTRGJNVW1Mb3dlcjR4RFpYSmNmUTVCbjJaXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=1f0ba981-db37-4549-9ed0-450ffe086b1a" alt="notion image" loading="lazy" decoding="async"/></div></figure><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-67621626219f49bea799054c03224f59" data-id="67621626219f49bea799054c03224f59"><span><div id="67621626219f49bea799054c03224f59" class="notion-header-anchor"></div><a class="notion-hash-link" href="#67621626219f49bea799054c03224f59" title="问题二： 长连接QPS上得去，短连接QPS上不去"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">问题二： 长连接QPS上得去，短连接QPS上不去</span></span></h2><div class="notion-text notion-block-8010ba71a1d34218a08d326afe075c8f">测试在使用<code class="notion-inline-code">-H &quot;Connection: close&quot;</code>进行短连接测试发现QPS又比之前的值差了不少，使用的压力机和测试机都和测试长连接使用的是相同的，所以排除上面我们说的网卡、队列的问题影响，会不会是长短连接机制引起？</div><div class="notion-text notion-block-2ed728b3043648c7ad85338473f7d5a2">因为使用短连接，那么每一次请求就会有3次握手和4次挥手的流程。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-ee0bdb96ca0542938e7cdc6679758f4d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=MjI3MjVhZjE3MzczNDJmYjkzNjkxYmI4Yjk3NTM2NWFfdGZIRDFBbXJ0dEVDSjR6RjJuYk1ueGR3aXJHcGgwYVNfVG9rZW46S05iWWJxVDlXb0ZkbkN4Q2RKUWN5WElQblhnXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=ee0bdb96-ca05-4293-8e7c-dc6679758f4d" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4f48e367bdff49cf8c63ed3086ad0432">为了找出具体的问题，我又尝试用另一条机器对测试机进行打压测试，发现该机器使用wrk进行打压的数据就比较正常，那问题就确定是压力机侧引起的。</div><div class="notion-text notion-block-8c8a93b62010405980f800c8c9e37a43">我们都知道<b>TCP 连接是基于五元组的，</b>那么对于客户端来说，源 IP、目的 IP、目的端口、 协议，这四个元素都不会变化，<b>唯一会变的就是自己的源端口</b>了</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-299df5e3247a48869c3a5c039beffa29" data-id="299df5e3247a48869c3a5c039beffa29"><span><div id="299df5e3247a48869c3a5c039beffa29" class="notion-header-anchor"></div><a class="notion-hash-link" href="#299df5e3247a48869c3a5c039beffa29" title="会不会是端口范围太小导致的？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">会不会是端口范围太小导致的？</span></span></h3><div class="notion-text notion-block-2232f748dcfa4ec1aeb175bf1ca7b62e">查看系统设置的端口范围</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-26e59baa6b2b4381aa20be4b5035d19e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=Y2YyNGM0NGExYjRkMGU5OWFhNWFmYjcxZTRhMjYxODVfWG9WeWkwZkQ5d1Z2V3VIYUx4aFdkYUV1d3dYSWJzRGdfVG9rZW46QVdBZmJpbW5qb3VBU2F4YkN4NmNzbFdkbjFmXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=26e59baa-6b2b-4381-aa20-be4b5035d19e" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-0fdb31df0c0847a9bb0e93a1b4c91da3">发现端口范围也挺大的，那台能够正常打压上去的压力机也是这个范围，所以应该不是这个参数的问题。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-04ac5fc4a8604dd990d7c098505688a1" data-id="04ac5fc4a8604dd990d7c098505688a1"><span><div id="04ac5fc4a8604dd990d7c098505688a1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#04ac5fc4a8604dd990d7c098505688a1" title="会不会是连接状态的问题"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">会不会是连接状态的问题</span></span></h3><div class="notion-text notion-block-9e8c8dbcaf184e2a8084882008ff986d">在查看一下压力机连接数处于各个状态的数量</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-5493f507f29745b39198e118e6969cb8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=OGI5YjhiYzBlZDJmMzFmZTVjNmU1NTdiNjhmNTdjZjBfbHNOazVwNEdSVEdHakswN0FjVGJhcG1YdVBtenF1UDhfVG9rZW46QmsxYmJ4cEJJb1RNU1R4R0Z2NWNHbkw3bjh0XzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=5493f507-f297-45b3-9198-e118e6969cb8" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-03fa344ea2334cd3a63e5985e50676ed">在筛选出5353端口使用的连接数</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-f19f35e49f8149f1ab7d657903655be0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=MWRhMWZlMWIyYWRkNGFiMjY3N2VmNzJlZGYwNTEwZjhfRHdYelUyWTJWUFgyNldqV0NZV2MwNk1sT08zY09ZUmlfVG9rZW46SlM4RmJOOFpYb2dKR3d4anBtcGNXdkVBbnRjXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=f19f35e4-9f81-49f1-ab7d-657903655be0" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-032cd71e86284d10bb78bc852d9121a9">发现处于异常的机器有2.8w个连接是处于TIME-WAIT状态，并且一直没有释放掉，而正常的机器会只有1w不到的TIME-WAIT也不会随着打压一致变高，于是在对两个机器配置进行对比。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-d0f30377d1d34ec0b46d4addccc09011"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=YmI1NGY0NTZkYTJjNDVjNjYzMjQwZDNiNDkzNDBkZGNfaUdxT2F0S3BicXNWRzlzVFRPeHJWODBLZVJtSjF1a2RfVG9rZW46VW55d2JJYWZ5bzZscEd4cTBvSWM1b3d1bmdmXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=d0f30377-d1d3-4ec0-b46d-4addccc09011" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-84a2ffec9f1e47e2a782947c2dc8ca47">发现在有问题的机器上<code class="notion-inline-code">net.ipv4.tcp_tw_recycle = 1</code>这个参数没有被设置，</div><div class="notion-text notion-block-d5fe7ae69dd44284bffb9e0348abde0a">先解释一下这两个参数的含义</div><ul class="notion-list notion-list-disc notion-block-73a8fcde53f3409ca81cd1946d2d6284"><li>net.ipv4.tcp_tw_reuse = 0 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接，默认为0，表示关闭</li></ul><ul class="notion-list notion-list-disc notion-block-d3bfcf6bc213440c9d80c974de9aac57"><li>net.ipv4.tcp_tw_recycle = 0 表示开启TCP连接中TIME-WAIT sockets的快速回收，默认为0，表示关闭</li></ul><div class="notion-text notion-block-ebbb1c5187d74c32be46737416318801">从字面意思分析可能就是因为处于TIME-WAIT连接数太多且没有快速回收导致端口不够用，短连接进行建连上不去。于是在新环境添加上该参数后，结果报错了...</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2b21dc30ef1c40ad9990c11242d2fb23"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=ZjNmOGM3MDNhOTc2OTBiNGM4ZTY5ZjM5NDc3NzhmZjRfeWlzenVBakZvd2NCN3FnYnkzaEdIRWlNMm9tZXZDbEtfVG9rZW46WUhIV2I1ODZDb0pVbHV4UnhleWNUUnZEblZjXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=2b21dc30-ef1c-40ad-9990-c11242d2fb23" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-f099f0a02e714f96983dd0fc527e6b4c">该配置参数竟然无法使用，</div><div class="notion-text notion-block-d6e6da84b4924475baf5719f4bc1f94d">查看了一下linux的版本内核</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-cc721f690f794f939fcf5a15607b7c3e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=ODg2ODM2ZDEyYTJjYzllMzE1YWNhYjQ2ZGFhOGQ3ZTdfeU5VMGswNHZhWWNXcGhFYVduTWFiOUROSTdtbFdpZkRfVG9rZW46TVdZMmJEUWN2b3hId3V4MTd4amM2REhLbjdkXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=cc721f69-0f79-4f93-9fcf-5a15607b7c3e" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a3f741c3e76e407db4d6fe16cc4040ab"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://udfb86xk4a.feishu.cn/space/api/box/stream/download/asynccode/?code=NmUxM2IyM2M5NzhiZDA2YzczYjVhM2M0MTkxMzg3YzJfVE91aVowNGdmQVR6NE9aeTdIR3R4eE0zOE1LTlF0Q2NfVG9rZW46QzNBRmJyVndpb0FiTkR4VElHM2NvNDNjbjNkXzE3MTM3NTM1MDg6MTcxMzc1NzEwOF9WNA&amp;t=a3f741c3-e76e-407d-b4d6-fe16cc4040ab" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-c6f2d7a43a1146238996d4ec9c917af6">发现这两台机器版本差异比较大，查看相关资料才得知Linux 从4.12内核版本开始移除了该参数设置，感兴趣的可以自行去查看具体的原因。那无法使用这个参数，有没有其他参数可以控制处于TIME-WAIT的连接数最大值呢？果然，linux提供了相关的设置参数，那就是：<code class="notion-inline-code">net.ipv4.tcp_max_tw_buckets</code></div><div class="notion-text notion-block-c68a489dfa5f4b709fc2c008a14652a1">将该参数设置为一个比较小的值进行测试</div><div class="notion-text notion-block-40ac59ceb98d4d1f91689e81076ecc28">进行测试后发现QPS就正常了，同时处于TIME-WAIT的连接数也不到1000，终于解决了这个问题！</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[无懈可击的DNSSEC]]></title>
            <link>https://hexo.fridaylab.top/article/4138273b-8177-4d6f-ac9c-951a584340b1</link>
            <guid>https://hexo.fridaylab.top/article/4138273b-8177-4d6f-ac9c-951a584340b1</guid>
            <pubDate>Mon, 22 Apr 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-4138273b81774d6fac9c951a584340b1"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-2eb37c47c92346ad8c2471b827ea6864" data-id="2eb37c47c92346ad8c2471b827ea6864"><span><div id="2eb37c47c92346ad8c2471b827ea6864" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2eb37c47c92346ad8c2471b827ea6864" title="什么是DNSSEC"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是DNSSEC</span></span></h2><div class="notion-text notion-block-e23511f38c804622832eb7f08a98fe63">DNSSEC(Domain Name System Security Extensions)中文名称为DNS安全扩展，它是由IETF提供的一系列DNS安全认证机制，通过向现有DNS记录添加加密签名，解析器可以验证来自于权威域名服务器请求的信息，从而保证域名系统的安全性。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-548d4c55ca19442c9835b7704de973df"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:690px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Faa8994b9-948c-4b72-ad9e-dd89ed9e4151%2F%25E6%2588%25AA%25E5%25B1%258F2024-04-22_09.34.25.png?table=block&amp;id=548d4c55-ca19-442c-9835-b7704de973df&amp;t=548d4c55-ca19-442c-9835-b7704de973df&amp;width=690&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-b21422b41753427eb7f0bc70325fafc5">发起一次域名查询的流程如上图所示，客户端需要访问www.baidu.com，会通过域名解析服务器发起递归查询，我们经常配置的114.114.114.114就是一个递归服务器。如果递归服务器存在记录缓存，那么就会直接将www.baidu.com的A记录直接返回给客户端；如果不存在就需要通过根服务器、顶级域名服务器、权威服务器、二级域名服务器迭代查询。</div><div class="notion-text notion-block-36b3c0cbf2a14cd5a2fba3c60cb4183b">由于DNS解析使用的是UDP协议，UDP 是一种无连接的、不可靠的传输层协议，所以攻击者就能很容易通过假冒域名服务器（根、顶级、权威服务器）给客户端发送伪造的响应，响应的IP可能是无效地址或者是欺诈网站地址，从而达到网络钓鱼、提供非法广告、监控 Web 流量以及阻止对特定域的访问等。同时由于解析服务器有缓存的功能，这些记录就会在服务器中保存一段时间才会失效，这就是常见的DNS欺骗攻击和缓存污染。</div><div class="notion-text notion-block-e01a492444f94b5f9443312396a67276">DNSSEC设计目的就是为了解决DNS欺骗攻击和缓存污染，它使用数字签名技术保证DNS的真实性和完整性，这些数字签名会与A、CNAME等常见记录类型一起存储在DNS域名服务器中。解析服务器可以对响应进行校验来确保所请求的DNS记录是否来自权威服务器，并且没有被篡改或者注入虚假的信息。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-805858883fce4b0d972eb0da069650eb" data-id="805858883fce4b0d972eb0da069650eb"><span><div id="805858883fce4b0d972eb0da069650eb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#805858883fce4b0d972eb0da069650eb" title="DNSEC是如何设计和运行"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>DNSEC是如何设计和运行</b></span></span></h2><div class="notion-text notion-block-b47c878dd3bd4d4aba416561815cef8c">为了保证签名、分发、验签整个过程的可信可靠，DNSSEC添加了新的DNS记录类型：</div><ul class="notion-list notion-list-disc notion-block-f16ab6bb797c44debc1405d21caf98ea"><li>RRSIG：用于存放资源记录签名</li></ul><ul class="notion-list notion-list-disc notion-block-aa3f14d325794f20a4044b86e23e4774"><li>DNSKEY：用于存放公共签名密钥</li></ul><ul class="notion-list notion-list-disc notion-block-2428a0e330454c208e1ac0f9481bfc57"><li>DS： 用于存放公钥哈希</li></ul><ul class="notion-list notion-list-disc notion-block-fe9defce8561478f8a713925995f4d16"><li>NSEC、NSEC3：用于表示DNS记录不存在</li></ul><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3d54252105b84427b6c511f2043df239" data-id="3d54252105b84427b6c511f2043df239"><span><div id="3d54252105b84427b6c511f2043df239" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3d54252105b84427b6c511f2043df239" title="RRset"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">RRset</span></span></h4><div class="notion-text notion-block-12e566edae5647b2973656ae59b20c6a">RRset是一组资源记录集合，这个集合包含相同类型的记录。例如区记录里面存在www.baidu.com的多个A记录，那么它们就会全部归到一个A RRset中去。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2a0d2a3289194acc930937c09457047f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:510px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F4c868aa8-7c73-4d49-be7f-fb389a873cfb%2F%25E6%2588%25AA%25E5%25B1%258F2024-04-22_09.35.15.png?table=block&amp;id=2a0d2a32-8919-4acc-9309-37c09457047f&amp;t=2a0d2a32-8919-4acc-9309-37c09457047f&amp;width=510&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1d97be7d8a4f4d22aad859af9c0bb10a" data-id="1d97be7d8a4f4d22aad859af9c0bb10a"><span><div id="1d97be7d8a4f4d22aad859af9c0bb10a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1d97be7d8a4f4d22aad859af9c0bb10a" title="ZSK"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">ZSK</span></span></h4><div class="notion-text notion-block-b45fa1d88eaf4dccbb994208a99e5d26">DNSSEC针对每一个区都有一对签名密钥ZSK（Zone Signature Key），ZSK的私钥用来对RRset进行数字签名，公钥用于验证签名，并将其哈希添加到DNSKEY记录中，方便递归服务器来查询。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-10d39dbec0dc417884813e5053b9dd53"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:648px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F10a52edd-6e22-4d09-b294-2f53856622cd%2F%25E6%2588%25AA%25E5%25B1%258F2024-04-22_09.36.00.png?table=block&amp;id=10d39dbe-c0dc-4178-8481-3e5053b9dd53&amp;t=10d39dbe-c0dc-4178-8481-3e5053b9dd53&amp;width=648&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-367e4ec5c339488fb96d89fbfb9b9fa3">递归服务器为了校验响应结果是否可信，他需要获取RRset、RRSIG和DNSKEY一同进行验证，使用DNSKEY对RRSIG进行解密，然后再与RRset哈希进行对比。如果DNSKEY是被信任的，那么如果验证通过，所有的记录就是可信任的。但是，DNSKEY泄漏或者被伪装那么还是不能保证数据的可靠，所以还需要有一种机制来验证ZSK是否正确可靠（套娃开始🪆）。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-0794690f4e504334bf715cc0bbb06166" data-id="0794690f4e504334bf715cc0bbb06166"><span><div id="0794690f4e504334bf715cc0bbb06166" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0794690f4e504334bf715cc0bbb06166" title="KSK"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">KSK</span></span></h4><div class="notion-text notion-block-3cae8bc4e54e4d8f8c84a77527b8586f">KSK(Key Signature Key)用来对ZSK进行签名和验证，使用KSK的私钥对ZSK公钥的DNSKEY记录进行签名，得到的数字签名也是一个RRSIG记录，为了能够对该RRSIG进行验签，将KSK的公钥存在在另一个DNSKEY记录中。此时就产生了两个DNSKEY，分别是：</div><ul class="notion-list notion-list-disc notion-block-7f68f123262c4bf4b5210b2bff9b1d14"><li>ZSK的DNSKEY：用于存放ZSK公钥和使用KSK进行签名的RRSIG记录</li></ul><ul class="notion-list notion-list-disc notion-block-14b8f2903f0740e79d658a9595517db6"><li>KSK的DNSKEY：用于存放KSK公钥</li></ul><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-8b6a418509e548b399de7ca00203b849"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F2a88b36a-3b1a-402d-98d6-8da96ee59339%2F%25E6%2588%25AA%25E5%25B1%258F2024-04-22_09.36.39.png?table=block&amp;id=8b6a4185-09e5-48b3-99de-7ca00203b849&amp;t=8b6a4185-09e5-48b3-99de-7ca00203b849&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-eeda3c7c06ab4209a50bf3558f2e54c8">此时，验证流程变得复杂起来，在ZSK流程的基础上，解析服务器向域名服务器请求ZSK公钥，返回了ZSK公钥的DNSKEY记录和对应的RRSIG记录（使用KSK签名的），为了校验ZSK的DNSKEY记录是否正确，解析服务器又需要向域名服务器请求KSK公钥，返回了KSK公钥的DNSKEY记录就可以验证ZSK的DNSKEY是否可被信任了。那么问题又来了，又该如何确保KSK的有效性呢？不会再设计出个KKSK来吧？</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-d7607904780c46b0be2be6f4fb4d3084" data-id="d7607904780c46b0be2be6f4fb4d3084"><span><div id="d7607904780c46b0be2be6f4fb4d3084" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d7607904780c46b0be2be6f4fb4d3084" title="DS"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">DS</span></span></h4><div class="notion-text notion-block-4a8b39ede31b4957bf56c67fd9dab3c8">为了验证KSK公钥的有效性，DNSSEC添加DS记录，该记录包含KSK公钥的DNSKEY的哈希，并由父区保存</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4527ecd2ce2b48faaf7471884a90aafa"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F22cb46b9-4743-4163-aa6d-8beb8625e337%2F%25E6%2588%25AA%25E5%25B1%258F2024-04-22_09.37.15.png?table=block&amp;id=4527ecd2-ce2b-48fa-af74-71884a90aafa&amp;t=4527ecd2-ce2b-48fa-af74-71884a90aafa&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-3674fcf4227a4cb8b16f9480b82b6b0d">于是整个校验过程又多了一步，解析服务器通过权威服务器B获取了KSK和ZSK后，还需要向他的父区顶级域名服务器A获取DS的记录，通过对比DS记录和KSK的哈希值来判断记录数据的有效可靠。这种设计使得子区的信任需要由父区来保证，父区的信任也需要由更上级保证，这样也就形成了一个完整的信任链。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-ea9f4a4de28d4dfea3dc7224e81e53b4" data-id="ea9f4a4de28d4dfea3dc7224e81e53b4"><span><div id="ea9f4a4de28d4dfea3dc7224e81e53b4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ea9f4a4de28d4dfea3dc7224e81e53b4" title="信任链"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">信任链</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2bb5404fafa64a4aa0c509f051f8ba0b"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Ffb3c976f-f201-41b8-80ed-10729a5b1e06%2F%25E6%2588%25AA%25E5%25B1%258F2024-04-22_09.37.45.png?table=block&amp;id=2bb5404f-afa6-4a4a-a0c5-09f051f8ba0b&amp;t=2bb5404f-afa6-4a4a-a0c5-09f051f8ba0b&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-1f1078e5cf834bfcb8ac8e871ef929de">每个区都有父区进行签名背书，如果信任父区，则子区所有记录在验证正确的情况就可以认定为是可信可靠的。根区的签名则是在“根区签名仪式”，由来自世界各地的特定的几人已公开且经严格审核的方式签署根DNSKEY RRset，并产生一条RRSIG记录，该记录用于校验根域名服务器的公共KSK和ZSK。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4dd1c7c4c4e34026ae5404d45a38eeff" data-id="4dd1c7c4c4e34026ae5404d45a38eeff"><span><div id="4dd1c7c4c4e34026ae5404d45a38eeff" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4dd1c7c4c4e34026ae5404d45a38eeff" title="DNSSEC配置实践"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">DNSSEC配置实践</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1bc521170b4d4bd4ac31f62a07b697ee" data-id="1bc521170b4d4bd4ac31f62a07b697ee"><span><div id="1bc521170b4d4bd4ac31f62a07b697ee" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1bc521170b4d4bd4ac31f62a07b697ee" title="配置"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">配置</span></span></h3><div class="notion-text notion-block-a3edac0fd68541b5b5260bacced354cb"><b>权威服务器A配置</b></div><ul class="notion-list notion-list-disc notion-block-ffecd66a05764b8d8ca0404c2c3ed398"><li>首先创建一个<code class="notion-inline-code">aaa.com</code>的区，然后再添加一条<code class="notion-inline-code">www.aaa.com</code>的A记录。</li></ul><ul class="notion-list notion-list-disc notion-block-95aa043c66b54ebd922ad56f5ca4704a"><li>得到区记录文件aaa.com.txt：</li><ul class="notion-list notion-list-disc notion-block-95aa043c66b54ebd922ad56f5ca4704a"></ul></ul><ul class="notion-list notion-list-disc notion-block-e2fce1dc283b40c3acdb7bc6700549f6"><li>使用dnssec-keygen生成该区的KSK</li><ul class="notion-list notion-list-disc notion-block-e2fce1dc283b40c3acdb7bc6700549f6"><div class="notion-text notion-block-6a3ce94804054cf1b9032fb030b5100d"><code class="notion-inline-code">dnssec-keygen -f KSK -a RSASHA1 -b 512 -n ZONE aaa.com.</code></div></ul></ul><ul class="notion-list notion-list-disc notion-block-35c917acbdd1461fb8eb37ad25d807e1"><li>使用dnssec-keygen生成该区的ZSK</li><ul class="notion-list notion-list-disc notion-block-35c917acbdd1461fb8eb37ad25d807e1"><div class="notion-text notion-block-a1d77764705148e79fe6d23e9e827147"><code class="notion-inline-code">dnssec-keygen -a RSASHA1 -b 512 -n ZONE aaa.com.</code></div></ul></ul><ul class="notion-list notion-list-disc notion-block-ae8ebe52c8e243c190fe061121567927"><li>生成两对公私钥对</li><ul class="notion-list notion-list-disc notion-block-ae8ebe52c8e243c190fe061121567927"><li>Kaaa.com.+005+29191.key Kaaa.com.+005+29191.private</li><li>Kaaa.com.+005+50076.key Kaaa.com.+005+50076.private</li></ul></ul><ul class="notion-list notion-list-disc notion-block-df77faccf17d4f58a9ed3b416493a5e2"><li>编辑aaa.com.txt文件,将KSK和ZSK的key添加进去</li><ul class="notion-list notion-list-disc notion-block-df77faccf17d4f58a9ed3b416493a5e2"></ul></ul><ul class="notion-list notion-list-disc notion-block-4b7585f6e76e47c5b423610979b6a9e6"><li>对区记录进行签名，得到aaa.com.txt.signed文件</li><ul class="notion-list notion-list-disc notion-block-4b7585f6e76e47c5b423610979b6a9e6"><div class="notion-text notion-block-3b94b157bee4408ca9d002e44323927e"><code class="notion-inline-code">dnssec-signzone -o aaa.com. aaa.com.txt</code></div></ul></ul><ul class="notion-list notion-list-disc notion-block-59cb4c65ea69402fb2eabc5b2efe953d"><li>使用aaa.com.txt.signed替换aaa.com.txt，重启Bind</li></ul><div class="notion-text notion-block-d087d92c23184d6dab7314d361be4bf7"><b>权威服务器B配置</b></div><ul class="notion-list notion-list-disc notion-block-baff5b911a60450499bc398c02e78505"><li>创建一个<code class="notion-inline-code">com</code>的区，然后再添加一条<code class="notion-inline-code">aaa.com</code>的NS记录。</li></ul><ul class="notion-list notion-list-disc notion-block-bfd7b7a41dc84effbf4726b7d7f82ac9"><li>得到区记录文件com.txt：</li><ul class="notion-list notion-list-disc notion-block-bfd7b7a41dc84effbf4726b7d7f82ac9"></ul></ul><ul class="notion-list notion-list-disc notion-block-41ac658dd1124ee18bab7ba83a8c4670"><li>使用dnssec-keygen生成该区的KSK</li><ul class="notion-list notion-list-disc notion-block-41ac658dd1124ee18bab7ba83a8c4670"><div class="notion-text notion-block-6eaa1516bd8a433ca2c194b0db6dc9cc"><code class="notion-inline-code">dnssec-keygen -f KSK -a RSASHA1 -b 512 -n ZONE com.</code></div></ul></ul><ul class="notion-list notion-list-disc notion-block-d20a826c745f4459b8040fe2be8ae48d"><li>使用dnssec-keygen生成该区的ZSK</li><ul class="notion-list notion-list-disc notion-block-d20a826c745f4459b8040fe2be8ae48d"><div class="notion-text notion-block-f5ec62294b9442deb2dd98d5ccd24cce"><code class="notion-inline-code">dnssec-keygen -a RSASHA1 -b 512 -n ZONE com.</code></div></ul></ul><ul class="notion-list notion-list-disc notion-block-6206eee367d7408d955f271d6d0a7b1c"><li>生成两对公私钥对</li><ul class="notion-list notion-list-disc notion-block-6206eee367d7408d955f271d6d0a7b1c"><li>Kaaa.com.+005+29191.key Kaaa.com.+005+29191.private</li><li>Kaaa.com.+005+50076.key Kaaa.com.+005+50076.private</li></ul></ul><ul class="notion-list notion-list-disc notion-block-8553dbe1848447268f9449ee5a5b0502"><li>编辑aaa.com.txt文件,将KSK和ZSK的key添加进去，并将授权的子区aaa.com.的DS记录添加进来</li><ul class="notion-list notion-list-disc notion-block-8553dbe1848447268f9449ee5a5b0502"></ul></ul><ul class="notion-list notion-list-disc notion-block-3991fe48b3ca40a6bb861c4e478fff06"><li>对区记录进行签名，得到com.txt.signed文件</li><ul class="notion-list notion-list-disc notion-block-3991fe48b3ca40a6bb861c4e478fff06"><div class="notion-text notion-block-09648397a69a43b6852c8dce87719686"><code class="notion-inline-code">dnssec-signzone -o com. com.txt</code></div></ul></ul><ul class="notion-list notion-list-disc notion-block-4a4e67314c3b4dcf99efc26ceb83e2d2"><li>使用com.txt.signed替换com.txt，重启Bind</li></ul><div class="notion-text notion-block-51f56bcfcba64016addf0e6fbb106529"><b>递归服务器验证</b></div><div class="notion-text notion-block-f4ae04d5469e4a1c91f51db4ad63d860">将递归服务器的根区指向权威服务器A</div><ul class="notion-list notion-list-disc notion-block-e9ab67a211a042dc8deb0109ede27e51"><li>使用dig命令：<code class="notion-inline-code"> dig @递归服务器 www.aaa.com. +dnssec</code></li></ul><ul class="notion-list notion-list-disc notion-block-8eea46783da6408fb47654ca4a605861"><li>如果配置的没有问题返回结果为：</li><ul class="notion-list notion-list-disc notion-block-8eea46783da6408fb47654ca4a605861"></ul></ul><ul class="notion-list notion-list-disc notion-block-db4eafceaeaf411182c207b90645aca8"><li>进行抓包得到</li><ul class="notion-list notion-list-disc notion-block-db4eafceaeaf411182c207b90645aca8"><div class="notion-file notion-block-519a2605878a43d4ae85c70d0aa7db5c"><a target="_blank" rel="noopener noreferrer" class="notion-file-link" href="https://notion.so/signed/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F54288aa8-d69a-4109-afc6-94a98a2ac494%2Fdnssec.cap?table=block&amp;id=519a2605-878a-43d4-ae85-c70d0aa7db5c"><svg class="notion-file-icon" viewBox="0 0 30 30"><path d="M22,8v12c0,3.866-3.134,7-7,7s-7-3.134-7-7V8c0-2.762,2.238-5,5-5s5,2.238,5,5v12c0,1.657-1.343,3-3,3s-3-1.343-3-3V8h-2v12c0,2.762,2.238,5,5,5s5-2.238,5-5V8c0-3.866-3.134-7-7-7S6,4.134,6,8v12c0,4.971,4.029,9,9,9s9-4.029,9-9V8H22z"></path></svg><div class="notion-file-info"><div class="notion-file-title">dnssec.cap</div><div class="notion-file-size">3.2KB</div></div></a></div><h3 class="notion-h notion-h2 notion-block-8cc2dec76cba4d56a7b7b5732dbe074d" data-id="8cc2dec76cba4d56a7b7b5732dbe074d"><span><div id="8cc2dec76cba4d56a7b7b5732dbe074d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8cc2dec76cba4d56a7b7b5732dbe074d" title="分析"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">分析</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-00874be4776c4cdfac8a1e068c0fe534"><li>递归服务器向112这台权威服务器请求<code class="notion-inline-code">www.aaa.com.</code>,112权威服务器返回<code class="notion-inline-code">aaa.com.</code>的子域所指的服务器给递归服务器，假定为113权威服务器。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-c5347ea6e50d4b5fab387ff9626370ae"><li>递归服务器收到后又向113权威服务器请求<code class="notion-inline-code">www.aaa.com.</code>,113权威服务器的区里有DNS记录并同时还会返回对应的RRSig（数字签名）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-e8ebfc4c703248cfb74ddfe74c58ebca"><li>递归服务器收到结果，需要根据RRSig来判断这条DNS响应是否是113这台权威服务器发出的，这时递归服务器就会向113权威服务器请求ZSK公钥</li><ol class="notion-list notion-list-numbered notion-block-e8ebfc4c703248cfb74ddfe74c58ebca"></ol></ol><ol start="4" class="notion-list notion-list-numbered notion-block-811a8d9cca124427a5c5b0ea7dec370d"><li>113权威服务器收到请求后就会返回ZSK、KSK的DNSKEY记录及对应的RRSig</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-777f703bf3d4409e935ff5c6e2160cb1"><li>递归服务器收到包含KSK公钥的DNSKEY记录后，向112权威服务器查询DS记录</li><ol class="notion-list notion-list-numbered notion-block-777f703bf3d4409e935ff5c6e2160cb1"></ol></ol><ol start="6" class="notion-list notion-list-numbered notion-block-88e68a10dd91448193085311da989ed1"><li>递归服务器收到DS记录后，就可以对KSK公钥进行哈希，比较两个值是否匹配。</li></ol><div class="notion-text notion-block-b9b4736c11d542e2b0c7c21c525d1876">由于整个过程是从根出发的，所以为了不从根再获取DS，就可以配置信任锚，将com.的DNSKEY添加到递归服务器里，这样就不会再根服务器去请求了。</div><div class="notion-text notion-block-b4f39c3ca9b9466b82c0e371a71a450b">在递归服务器的配置里添加Trust Anchors , 需要填写的就是com. 的DNSKEY 的记录值</div><h2 class="notion-h notion-h1 notion-block-8d786d8a605a4eebb3925a05cc45e5a0" data-id="8d786d8a605a4eebb3925a05cc45e5a0"><span><div id="8d786d8a605a4eebb3925a05cc45e5a0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8d786d8a605a4eebb3925a05cc45e5a0" title="总结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">总结</span></span></h2><div class="notion-text notion-block-265661d7675547d38a71c82796f180f3">DNSSEC在并不安全的协议之上，添加了一个身份验证的安全层来确保记录的可信防篡改，类似HTTPS。通过使用DNSSEC，借助可靠的信任链就能有效地解决DNS欺骗攻击，防止攻击者给DNS系统带来潜在的安全威胁。</div><h2 class="notion-h notion-h1 notion-block-cfe64d46c5c747559ee75fc41eb1780f" data-id="cfe64d46c5c747559ee75fc41eb1780f"><span><div id="cfe64d46c5c747559ee75fc41eb1780f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cfe64d46c5c747559ee75fc41eb1780f" title="参考"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">参考</span></span></h2><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-6d377d44259648798768de1980af6612" href="https://zhuanlan.zhihu.com/p/355579999"><div><div class="notion-bookmark-title">DNSSEC？禁止套娃！</div><div class="notion-bookmark-description">简介DNSSEC是DNS安全拓展，主要思想是通过在DNS记录中添加加密签名，从而为DNS解析流程提供 来源可认证和数据完整性的保障。 本文的目的是帮助大家大致理解DNSSEC的工作流程建议读者先掌握以下知识点再来阅读本文…</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://static.zhihu.com/heifetz/assets/apple-touch-icon-152.81060cab.png?t=6d377d44-2596-4879-8768-de1980af6612" alt="DNSSEC？禁止套娃！" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://zhuanlan.zhihu.com/p/355579999</div></div></div><div class="notion-bookmark-image"><img style="object-fit:cover" src="https://pic1.zhimg.com/v2-b32c4df81895a1fda0f598dc73b6339f_r.jpg?source=172ae18b&amp;t=6d377d44-2596-4879-8768-de1980af6612" alt="DNSSEC？禁止套娃！" loading="lazy" decoding="async"/></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-196e1fe2806f4430b596cd8f348141b9" href="https://bind9.readthedocs.io/en/v9_18_2/manpages.html?highlight=dnssec-loadkeys-interval#zone"><div><div class="notion-bookmark-title">Manual Pages — BIND 9 9.18.2 documentation</div><div class="notion-bookmark-description">arpaname translates IP addresses (IPv4 and IPv6) to the
corresponding IN-ADDR.ARPA or IP6.ARPA names.</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://bind9.readthedocs.io/favicon.ico?t=196e1fe2-806f-4430-b596-cd8f348141b9" alt="Manual Pages — BIND 9 9.18.2 documentation" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://bind9.readthedocs.io/en/v9_18_2/manpages.html?highlight=dnssec-loadkeys-interval#zone</div></div></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-dc353fa2e3e6458db71d29136325d759" href="https://backreference.org/2010/11/17/dnssec-verification-with-dig/"><div><div class="notion-bookmark-title">DNSSEC verification with dig</div><div class="notion-bookmark-description">DNSSEC is the (not so) new technology that will finally fix the trust problems inherent in the DNS, making spoofing and forging much harder or impossible. Or at least, that&#x27;s what everyone hopes.</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-text">https://backreference.org/2010/11/17/dnssec-verification-with-dig/</div></div></div></a></div></ul></ul></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DNS隧道攻击和防护]]></title>
            <link>https://hexo.fridaylab.top/article/3bf2382a-9384-4c6b-84e1-6831aaa4746b</link>
            <guid>https://hexo.fridaylab.top/article/3bf2382a-9384-4c6b-84e1-6831aaa4746b</guid>
            <pubDate>Thu, 18 Apr 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[了解基本的隧道攻击概念、隧道攻击的常用工具及防护基本方法]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-3bf2382a93844c6b84e16831aaa4746b"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-0a6935e28f754cd09fe00b3da08c1463" data-id="0a6935e28f754cd09fe00b3da08c1463"><span><div id="0a6935e28f754cd09fe00b3da08c1463" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0a6935e28f754cd09fe00b3da08c1463" title="隧道"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">隧道</span></span></h2><div class="notion-text notion-block-0e39dae9b78545dbaf58ebfc77bd7dcb">现实生活中我们乘坐汽车或火车常常会遇到隧道，隧道在物理世界是一种跨越无法跨越的地形或边界的方法，而在网络世界中的隧道则是一种绕过端口屏蔽的通信方法。
隧道技术是一种通过使用互联网络的基本设施在网络之间传递数据的方式，使用隧道传递的数据（或负载）可以是<b>不同协议的数据帧或包</b>。隧道技术将其他协议的数据帧或者数据包重新封装然后通过<b>隧道</b>发送。新的帧头提供路由信息，以便互联网传递被封装的负载数据。
常见的隧道如下：</div><ul class="notion-list notion-list-disc notion-block-e01a4c5d56984655a8d57ae0956d2240"><li>网络层</li><ul class="notion-list notion-list-disc notion-block-e01a4c5d56984655a8d57ae0956d2240"><li>IPV6隧道</li><li>ICMP隧道</li><li>GRE隧道</li></ul></ul><ul class="notion-list notion-list-disc notion-block-6a577d28bd01497b9511d851eb864cbe"><li>传输层</li><ul class="notion-list notion-list-disc notion-block-6a577d28bd01497b9511d851eb864cbe"><li>TCP隧道</li><li>UDP隧道</li></ul></ul><ul class="notion-list notion-list-disc notion-block-9b5165e39f7e48c399072f581d0e5581"><li>应用层</li><ul class="notion-list notion-list-disc notion-block-9b5165e39f7e48c399072f581d0e5581"><li>SSH隧道</li><li>HTTP隧道</li><li>HTTPS隧道</li><li>DNS隧道</li></ul></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-386629cfc75b4ab2ab401c0a9ae22527" data-id="386629cfc75b4ab2ab401c0a9ae22527"><span><div id="386629cfc75b4ab2ab401c0a9ae22527" class="notion-header-anchor"></div><a class="notion-hash-link" href="#386629cfc75b4ab2ab401c0a9ae22527" title="DNS隧道"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">DNS隧道</span></span></h2><div class="notion-text notion-block-c60b4d70d5b74b3899b834d87e18e7d3">DNS隧道是隐蔽信道的一种，通过将其他协议封装在DNS协议中进行通信。封装由客户端完成，将DNS流量还原成正常的流量由服务器完成。大多数防火墙和入侵检测设备对DNS流量是放行的，而隧道攻击正式利用了放行的特点以及协议解析流程来实现的。</div><div class="notion-text notion-block-27f76d950a63427298a7d4c8bed97401">
DNS隧道有两种实现方式：</div><ul class="notion-list notion-list-disc notion-block-4fd265435153441391e39d4786b88ad2"><li>IP直连型DNS隧道
直连也就是客户端直接和指定的目标DNS Server(Authoritative NS Server)连接，通过将数据编码封装在DNS协议中进行通信，这种方式速度快，但是隐蔽性比较弱，很容易被探测到，另外限制比较高，很多场景不允许自己指定DNS Server，很多的企业网络为了尽可能的降低遭受网络攻击的风险，一般将相关策略配置为仅允许与指定的可信任DNS服务器之间的流量通过。</li></ul><ul class="notion-list notion-list-disc notion-block-8eee9ff59bdd444aaa25f9a8d85168ba"><li>域名型DNS隧道（中继）
通过DNS迭代查询实现的中继隧道，比较隐蔽，但同时因为数据包到达目标DNS Server前需要经过多个节点，所以速度上较直连慢很多。</li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-18468cea28ce46fab3773698b74ff248" data-id="18468cea28ce46fab3773698b74ff248"><span><div id="18468cea28ce46fab3773698b74ff248" class="notion-header-anchor"></div><a class="notion-hash-link" href="#18468cea28ce46fab3773698b74ff248" title="DNS隧道攻击"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">DNS隧道攻击</span></span></h2><div class="notion-text notion-block-f63a6b3975c44e8a843cb3aa61f2f2ac">最常见的工具如下：</div><ul class="notion-list notion-list-disc notion-block-5ddc9c50bb7444049bbc79445e4411dc"><li>dns2tcp：支持直连模式的DNS隧道，只实现了简单的DNS隧道，相关命令和控制服务需要自行搭建，且已在kali系统中直接集成。</li></ul><ul class="notion-list notion-list-disc notion-block-4af6d7b60d07453ab445c980dcad3e27"><li>iodine：最活跃、速度最快、支持直连和中继模式，且支持丰富的编码、请求类型选择</li></ul><ul class="notion-list notion-list-disc notion-block-6f92a11ee2fb4f649e3efa87becadf01"><li>dnscat2：封装在DNS协议中的加密C&amp;C信道，直接运行工具即可实现数据传输、文件操作等命令和控制功能</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-8fa37d0a391c43a19ec18a274c444769" data-id="8fa37d0a391c43a19ec18a274c444769"><span><div id="8fa37d0a391c43a19ec18a274c444769" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8fa37d0a391c43a19ec18a274c444769" title="dns2tcp"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">dns2tcp</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-01d598029c054eac984802a4b31889ff" data-id="01d598029c054eac984802a4b31889ff"><span><div id="01d598029c054eac984802a4b31889ff" class="notion-header-anchor"></div><a class="notion-hash-link" href="#01d598029c054eac984802a4b31889ff" title="仓库"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">仓库</span></span></h4><div class="notion-text notion-block-fa391a71293b43a1890c97bebdb21eb4"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/alex-sector/dns2tcp">https://github.com/alex-sector/dns2tcp</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-8c85c69c2a204f54b998bf832bfe2312" data-id="8c85c69c2a204f54b998bf832bfe2312"><span><div id="8c85c69c2a204f54b998bf832bfe2312" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8c85c69c2a204f54b998bf832bfe2312" title="说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">说明</span></span></h4><div class="notion-text notion-block-90cbebd102764a21a843b1013a9121e6">dns2tcp是一款利用dns协议传输tcp数据的工具,适用于客户端的防火墙禁止tcp出站流量，无法上网，dns2tcp利用dns协议传输tcp数据，从而实现上网(dns协议是udp协议走53端口)</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4f8446966c964c12b583ed590381a08f" data-id="4f8446966c964c12b583ed590381a08f"><span><div id="4f8446966c964c12b583ed590381a08f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4f8446966c964c12b583ed590381a08f" title="安装"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-cd2dffe250d9408bb661736deb9ba6dd" data-id="cd2dffe250d9408bb661736deb9ba6dd"><span><div id="cd2dffe250d9408bb661736deb9ba6dd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cd2dffe250d9408bb661736deb9ba6dd" title="部署"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">部署</span></span></h4><div class="notion-text notion-block-1072044d56574e5d8e8cd152d3b4ec91">服务端配置和启动：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3c6d0ee9925740fc9f70dac7ebb1f6ae"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F8b62ac88-9cc0-4cae-8f19-db678e05baf6%2F%25E6%2588%25AA%25E5%25B1%258F2023-07-31_16.35.14.png?table=block&amp;id=3c6d0ee9-9257-40fc-9f70-dac7ebb1f6ae&amp;t=3c6d0ee9-9257-40fc-9f70-dac7ebb1f6ae&amp;width=680&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-c9d3f0b4f15a4be18d88f491e1a2226e">客户端启动：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3c90702a1ed842d090bc8ee62025b042"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fde411718-2df4-4409-8380-e01a2e4620c4%2FUntitled.png?table=block&amp;id=3c90702a-1ed8-42d0-90bc-8ee62025b042&amp;t=3c90702a-1ed8-42d0-90bc-8ee62025b042&amp;width=680&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-f7f62c720c014b6794b3b5fe6a2ec480">使用ssh即可进行登陆</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2de0e848963b43cc84ed92b982f9b5af"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F4985f121-c6f4-4fb2-89b5-b2a53063a551%2FUntitled.png?table=block&amp;id=2de0e848-963b-43cc-84ed-92b982f9b5af&amp;t=2de0e848-963b-43cc-84ed-92b982f9b5af&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-389ef870169b4effbc06cd6f7ee9c223">抓包查看相关DNS报文</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-9ca979ea05ea4c0094686eabb94cb5a9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F9c70e668-3e14-4ea1-aa25-a6d6d3de79ce%2FUntitled.png?table=block&amp;id=9ca979ea-05ea-4c00-9468-6eabb94cb5a9&amp;t=9ca979ea-05ea-4c00-9468-6eabb94cb5a9&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4ea4ec2d7ddb47868c5edd4e6016ec9d">可以看出一直有TXT类型查询，心跳和数据传输都是通过TXT类型的DNS记录查询进行完成的，dns2tcp还支持KEY类型的记录。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c2be22417faa448ea9baaabec70bb0d2" data-id="c2be22417faa448ea9baaabec70bb0d2"><span><div id="c2be22417faa448ea9baaabec70bb0d2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c2be22417faa448ea9baaabec70bb0d2" title="iodine"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">iodine</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-ffb2f2447ed84b4da8dfdfdadcb14215" data-id="ffb2f2447ed84b4da8dfdfdadcb14215"><span><div id="ffb2f2447ed84b4da8dfdfdadcb14215" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ffb2f2447ed84b4da8dfdfdadcb14215" title="仓库"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">仓库</span></span></h4><div class="notion-text notion-block-75e54857c41846248c14610625c645d1"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/yarrick/iodine">https://github.com/yarrick/iodine</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-ea2f778d30f3441e968737d5ed257ac3" data-id="ea2f778d30f3441e968737d5ed257ac3"><span><div id="ea2f778d30f3441e968737d5ed257ac3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ea2f778d30f3441e968737d5ed257ac3" title="说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">说明</span></span></h4><div class="notion-text notion-block-0d732c5a57d1438cb2e6ee9793b8cc96">iodine可以通过一台dns服务器制造一个IPv4数据通道，特别适合在目标主机只能发送dns请求的网络中环境中使用。iodine支持直接转发和中继两种模式，其原理是通过TAP虚拟网卡，在服务端建立一个局域网；在客户端，通过TAP建立一个虚拟网卡；两者通过DNS隧道连接，处于同一局域网（可以通过ping命令通信）。在客户端和服务端之间建立连接后，客户机上会多出一块“dns0”的虚拟网卡。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-d0aec5dbb5f34832884d3ed8f8d57d0a" data-id="d0aec5dbb5f34832884d3ed8f8d57d0a"><span><div id="d0aec5dbb5f34832884d3ed8f8d57d0a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d0aec5dbb5f34832884d3ed8f8d57d0a" title="部署"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">部署</span></span></h4><div class="notion-text notion-block-5fe65b6783034418a39f36e0045d066e">服务端执行命令：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-cfd35a13f5f44b68acf53caa99c02c59"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Ffa8f99aa-cc55-4cf1-ab92-a5c4db28b742%2FUntitled.png?table=block&amp;id=cfd35a13-f5f4-4b68-acf5-3caa99c02c59&amp;t=cfd35a13-f5f4-4b68-acf5-3caa99c02c59&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-2e51c91a259144faba9a47bb086ebb14">查看网卡发现多了一个dns0</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3db9341c4b35460c8f67887a31c48007"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F561a7716-f32a-46d4-a167-910f8bf56e1d%2FUntitled.png?table=block&amp;id=3db9341c-4b35-460c-8f67-887a31c48007&amp;t=3db9341c-4b35-460c-8f67-887a31c48007&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-b6aaa39aacc04180bfb8a1af2aa76624">客户端执行命令：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-74136a87d5214b80b49162dc4fda0068"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F21739fbf-3290-4b36-8c55-55c996a8a8ce%2FUntitled.png?table=block&amp;id=74136a87-d521-4b80-b491-62dc4fda0068&amp;t=74136a87-d521-4b80-b491-62dc4fda0068&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-ff2664bad3d34d1c9b91adaaaadbda78">客户端这边也多了一个虚拟网卡tun0</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-148de65cb7c549f5b9ef22aa2062d9fc"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F63336501-189b-4d63-aff4-e126ec63acc3%2FUntitled.png?table=block&amp;id=148de65c-b7c5-49f5-b9ef-22aa2062d9fc&amp;t=148de65c-b7c5-49f5-b9ef-22aa2062d9fc&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-73143d4d802d499188af99a52ee3a23b">DNS隧道建立后可以看到，服务端和客户端多了一个虚拟网卡，后续就可以通过这个网卡的ip进行相关通行。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-69f01d649ce442d8973604987a6c40e0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F9f69bab8-de3e-4864-a662-6fd92f3fa003%2FUntitled.png?table=block&amp;id=69f01d64-9ce4-42d8-9736-04987a6c40e0&amp;t=69f01d64-9ce4-42d8-9736-04987a6c40e0&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-60b70cf1746947728e8c726051cd276f">查看DNS报文,发现iodine使用NULL类型查询，这是工具自动选择的，当然它还支持 PRIVATE, TXT, SRV, MX, CNAME, A这些类型</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-6ce2685ee9434bd487ba0e630280700d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fa7002152-5133-4d7e-a085-a32ddb483063%2FUntitled.png?table=block&amp;id=6ce2685e-e943-4bd4-87ba-0e630280700d&amp;t=6ce2685e-e943-4bd4-87ba-0e630280700d&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-240833b1834846fb9c52ff386f1cf0f5" data-id="240833b1834846fb9c52ff386f1cf0f5"><span><div id="240833b1834846fb9c52ff386f1cf0f5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#240833b1834846fb9c52ff386f1cf0f5" title="dnscat2"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">dnscat2</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-2bfad312953d4c37933302030a59049e" data-id="2bfad312953d4c37933302030a59049e"><span><div id="2bfad312953d4c37933302030a59049e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2bfad312953d4c37933302030a59049e" title="仓库"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">仓库</span></span></h4><div class="notion-text notion-block-ed89fd9d2d994b4a8058d5febf5c53cc"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/iagox86/dnscat2">https://github.com/iagox86/dnscat2</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-61130d7ace494a239a077542dbf17353" data-id="61130d7ace494a239a077542dbf17353"><span><div id="61130d7ace494a239a077542dbf17353" class="notion-header-anchor"></div><a class="notion-hash-link" href="#61130d7ace494a239a077542dbf17353" title="部署"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">部署</span></span></h4><div class="notion-text notion-block-d5467dcec0ca48f69d753881eb667efc">使用docker启动服务端</div><div class="notion-text notion-block-9aa2bd5d801349d8a6d4a3e88de78721">编译客户端</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2fc210f4a5884342bed0ab141d6a418a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F83f6202e-5c11-46d5-b885-8ceaec8d360f%2FUntitled.png?table=block&amp;id=2fc210f4-a588-4342-bed0-ab141d6a418a&amp;t=2fc210f4-a588-4342-bed0-ab141d6a418a&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-db57619916f843d583c54d0d1fb5b65b">进入交互界面查看session，通过session与客户端通信</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-73744bb06d6c4f008a0df855a927dd32"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F575bc390-9428-47cd-8a7c-3665a488a0bc%2FUntitled.png?table=block&amp;id=73744bb0-6d6c-4f00-8a0d-f855a927dd32&amp;t=73744bb0-6d6c-4f00-8a0d-f855a927dd32&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-501e1fb3d71d43a59459b623733b594f">客户端收到服务端日志并执行</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-8e94c2fe32874b72a3f0e87b6e21af8e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F4294a353-cec7-4bee-a947-96ab07d1347c%2FUntitled.png?table=block&amp;id=8e94c2fe-3287-4b72-a3f0-e87b6e21af8e&amp;t=8e94c2fe-3287-4b72-a3f0-e87b6e21af8e&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-089547f472f94fdeb769b411c110daf4">使用shell，向client发送命令</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-85250b512f7f41d98b9fc04df76bd7ea"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fb9fe5983-bfab-4fe1-9ab7-7a14aba62975%2FUntitled.png?table=block&amp;id=85250b51-2f7f-41d9-8b9f-c04df76bd7ea&amp;t=85250b51-2f7f-41d9-8b9f-c04df76bd7ea&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-e857f812a0de42ffac3406619cd4738e">查看DNS报文,发现dnscat查询类型比较随机。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-cb01396b07e84d7aa6da06a94cfcac52"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F144bd829-e173-405a-9a50-7bd198bda873%2FUntitled.png?table=block&amp;id=cb01396b-07e8-4d7a-a6da-06a94cfcac52&amp;t=cb01396b-07e8-4d7a-a6da-06a94cfcac52&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-7b7c4e8d0cfc493a91154e3025d2e85f"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-1782a50815d647caade084b41a36e968" data-id="1782a50815d647caade084b41a36e968"><span><div id="1782a50815d647caade084b41a36e968" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1782a50815d647caade084b41a36e968" title="DNS隧道防护策略"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">DNS隧道防护策略</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-cb251202c18c4f74b62e8b1a62f984a2" data-id="cb251202c18c4f74b62e8b1a62f984a2"><span><div id="cb251202c18c4f74b62e8b1a62f984a2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cb251202c18c4f74b62e8b1a62f984a2" title="隧道消息类型分布"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">隧道消息类型分布</span></span></h3><div class="notion-text notion-block-524d2ec2e7934cbeaf12d9effd67139e">在正常的DNS流量中。A记录类型的流量占20%-30%，CNAME记录为38%-48%，AAAA记录占25%，NS记录只有5%，TXT记录只有1%-2%。然而为了获取更高的带宽，一部分的DNS隐蔽信道工具如iodine。在默认配置下会使用TXT或NULL等不常用的记录类型</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5e0ffc1288134524bbf0b7ebd2f7cc89" data-id="5e0ffc1288134524bbf0b7ebd2f7cc89"><span><div id="5e0ffc1288134524bbf0b7ebd2f7cc89" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5e0ffc1288134524bbf0b7ebd2f7cc89" title="域名中关键字和规则"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">域名中关键字和规则</span></span></h3><div class="notion-text notion-block-30643f9b41e547ccbb63019aa81f0ca3">在DNS隧道的报文中，我们可以看到变化的都是子域名，区是可以作为关联异常流量的切入点。 同时DNS隧道而言，控制端要不断借助DNS query的query_name来承载要传输的内容，所以从主机数量这个维度来看，在一个DNS隧道会话中，域名对应的主机名数量会明显大于正常的DNS通信。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-b6995032c63d4c1b9fb16cadeb2f3ac6" data-id="b6995032c63d4c1b9fb16cadeb2f3ac6"><span><div id="b6995032c63d4c1b9fb16cadeb2f3ac6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b6995032c63d4c1b9fb16cadeb2f3ac6" title="数据包数量"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">数据包数量</span></span></h3><div class="notion-text notion-block-f721c4af18104223afc74ddbcc7f9aaf">DNS隧道会话一般会向外发送心跳报文、传输本机敏感信息、资源文件等，控制端会下达相关的远程控制指令等所以在 DNS 隧道会话中 DNS报文数量大。但正常客户端产生的DNS会话随着一次DNS解析任务结束而结束，DNS会话比较简短。大多数情况是2个，由1个DNS请求报文和1个DNS响应报文组成。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-206b8949259745ba9887963a6c58ccad" data-id="206b8949259745ba9887963a6c58ccad"><span><div id="206b8949259745ba9887963a6c58ccad" class="notion-header-anchor"></div><a class="notion-hash-link" href="#206b8949259745ba9887963a6c58ccad" title="报文载荷量"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">报文载荷量</span></span></h3><div class="notion-text notion-block-64578122350d460faffcd512eda56998">一般正常的DNS查询报文都不会太大，但是DNS隧道由于是通过DNS报文中再封装其他协议的报文所以载荷量就会普遍大一些。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e9c46bcd50ac41b3819b62f75f1b64e0" data-id="e9c46bcd50ac41b3819b62f75f1b64e0"><span><div id="e9c46bcd50ac41b3819b62f75f1b64e0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e9c46bcd50ac41b3819b62f75f1b64e0" title="其他"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">其他</span></span></h3><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-5a14ebadce84427fb3d9555428b5fd34" data-id="5a14ebadce84427fb3d9555428b5fd34"><span><div id="5a14ebadce84427fb3d9555428b5fd34" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5a14ebadce84427fb3d9555428b5fd34" title="参考"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">参考</span></span></h2><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-67d5b9078886402a81be204b35ed5c75" href="https://www.freebuf.com/articles/network/271827.html"><div><div class="notion-bookmark-title">内网渗透基石篇-- 隐藏通信隧道技术（上） - FreeBuf网络安全行业门户</div><div class="notion-bookmark-description">那么什么是隧道呢？这里的隧道，就是一种绕过端口屏蔽的通信方式。</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://www.freebuf.com/favicon.ico?t=67d5b907-8886-402a-81be-204b35ed5c75" alt="内网渗透基石篇-- 隐藏通信隧道技术（上） - FreeBuf网络安全行业门户" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://www.freebuf.com/articles/network/271827.html</div></div></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-3731fc5ba89747bca843328b7335dbaa" href="http://blog.nsfocus.net/dns-tunnel-communication-characteristics-detection/"><div><div class="notion-bookmark-title">DNS 隧道通信特征与检测</div><div class="notion-bookmark-description">本地域名服务器向根域名服务器发送请求报文，根域名服务器要么给出ip地址要么告诉本地域名服务器下一步应该去查询另一个域名服务器(假设这个域名服务器为A)。本地域名服务器会向A域名服务器发送请求报文，A域名服务器要么给出ip地址要么告诉本地域名服务器下一步应该去查询B域名服务器。过程以此类推，直到查找到ip地址为止。</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://blog.nsfocus.net/favicon.ico?t=3731fc5b-a897-47bc-a843-328b7335dbaa" alt="DNS 隧道通信特征与检测" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">http://blog.nsfocus.net/dns-tunnel-communication-characteristics-detection/</div></div></div><div class="notion-bookmark-image"><img style="object-fit:cover" src="https://blog.nsfocus.net/wp-content/uploads/2019/09/摄图网_400240768.jpg?t=3731fc5b-a897-47bc-a843-328b7335dbaa" alt="DNS 隧道通信特征与检测" loading="lazy" decoding="async"/></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-a41e978a7376478abe44ad3f03945441" href="https://blog.csdn.net/deng_xj/article/details/88834124?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-88834124-blog-106159155.235^v38^pc_relevant_default_base&amp;spm=1001.2101.3001.4242.1&amp;utm_relevant_index=3"><div><div class="notion-bookmark-title">使用DNS2TCP搭建DNS隧道，绕过网络认证，实现免验证上网_校园网53端口绕不过认证-CSDN博客</div><div class="notion-bookmark-description">文章浏览阅读2.7w次，点赞28次，收藏166次。本文主要介绍利用 DNS 查询流量来封装 TCP 流量 , 达到绕过防火墙的目的，搭建DNS隧道，绕过网络认证，实现上网。_校园网53端口绕不过认证</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://g.csdnimg.cn/static/logo/favicon32.ico?t=a41e978a-7376-478a-be44-ad3f03945441" alt="使用DNS2TCP搭建DNS隧道，绕过网络认证，实现免验证上网_校园网53端口绕不过认证-CSDN博客" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://blog.csdn.net/deng_xj/article/details/88834124?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-88834124-blog-106159155.235^v38^pc_relevant_default_base&amp;spm=1001.2101.3001.4242.1&amp;utm_relevant_index=3</div></div></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-f5032e84858d428886f0b62bc91ceff0" href="https://developer.aliyun.com/article/395249"><div><div class="notion-bookmark-title">DNS隧道和工具-阿里云开发者社区</div><div class="notion-bookmark-description">DNS隧道和工具</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://img.alicdn.com/tfs/TB1_ZXuNcfpK1RjSZFOXXa6nFXa-32-32.ico?t=f5032e84-858d-4288-86f0-b62bc91ceff0" alt="DNS隧道和工具-阿里云开发者社区" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://developer.aliyun.com/article/395249</div></div></div><div class="notion-bookmark-image"><img style="object-fit:cover" src="https://img.alicdn.com/tfs/TB1LCE1aQ5E3KVjSZFCXXbuzXXa-200-200.png?t=f5032e84-858d-4288-86f0-b62bc91ceff0" alt="DNS隧道和工具-阿里云开发者社区" loading="lazy" decoding="async"/></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-063ed3dbac874408b34a619738e8ac3a" href="https://cloud.tencent.com/developer/article/2130056"><div><div class="notion-bookmark-title">内网隧道之dns2tcp-腾讯云开发者社区-腾讯云</div><div class="notion-bookmark-description">github：https://github.com/alex-sector/dns2tcp</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://cloud.tencent.com/favicon.ico?t=063ed3db-ac87-4408-b34a-619738e8ac3a" alt="内网隧道之dns2tcp-腾讯云开发者社区-腾讯云" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://cloud.tencent.com/developer/article/2130056</div></div></div><div class="notion-bookmark-image"><img style="object-fit:cover" src="https://cloudcache.tencentcs.com/open_proj/proj_qcloud_v2/gateway/shareicons/cloud.png?t=063ed3db-ac87-4408-b34a-619738e8ac3a" alt="内网隧道之dns2tcp-腾讯云开发者社区-腾讯云" loading="lazy" decoding="async"/></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-5c1ff7def9e9475685bf055c4e6893e1" href="https://zhuanlan.zhihu.com/p/143220945"><div><div class="notion-bookmark-title">DNS隧道检测特征总结</div><div class="notion-bookmark-description">一、摘要 企业内网环境中，DNS协议是必不可少的网络通信协议之一，为了访问互联网和内网资源，DNS提供域名解析服务，将域名和IP地址进行转换。网络设备和边界防护设备在一般的情况下很少对DNS进行过滤分析或屏蔽，…</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://static.zhihu.com/heifetz/assets/apple-touch-icon-152.81060cab.png?t=5c1ff7de-f9e9-4756-85bf-055c4e6893e1" alt="DNS隧道检测特征总结" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://zhuanlan.zhihu.com/p/143220945</div></div></div><div class="notion-bookmark-image"><img style="object-fit:cover" src="https://picx.zhimg.com/v2-bdece2870bbea4658a21d28267ee2b62_720w.jpg?source=172ae18b&amp;t=5c1ff7de-f9e9-4756-85bf-055c4e6893e1" alt="DNS隧道检测特征总结" loading="lazy" decoding="async"/></div></a></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WindowDNS使用GSS-TSIG协议]]></title>
            <link>https://hexo.fridaylab.top/article/1bed8efb-0c6f-4d6d-a3c9-46d448bfb282</link>
            <guid>https://hexo.fridaylab.top/article/1bed8efb-0c6f-4d6d-a3c9-46d448bfb282</guid>
            <pubDate>Fri, 19 Apr 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-1bed8efb0c6f4d6da3c946d448bfb282"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ee7bd38ea45042d19c84b3be49a0026f" data-id="ee7bd38ea45042d19c84b3be49a0026f"><span><div id="ee7bd38ea45042d19c84b3be49a0026f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ee7bd38ea45042d19c84b3be49a0026f" title="概述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">概述</span></span></h2><div class="notion-text notion-block-4e1c4fe096f347698fbee0827137deee">GSS-TSIG全称Generic Security Service Algorithm for Secret Key Transaction，即密钥事务的通用安全服务算法，用于对 DDNS 更新进行认证，它使用了Kerberos v5的认证系统（实现了<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://docs.oracle.com/cd/E19253-01/819-7056/overview-19/index.html">GSSAPI</a>）。原先通过TSIG记录使用共享密钥可以对DNS消息进行认证，但是这种方式不能全自动，必须手动介入生成和配置。引入GSS-TSIG和TKey纪录后就提供了一系列不同的模式建立和删除共享密钥用于解析服务器和DNS服务器之间通行认证。GSS-TSIG 通过客户端和服务端进行协商从而建立一个安全的请求上下文，它利用 Kerberos 服务器（在 AD 域控制器上运行）充当 KDC（Kerberos 密钥分发中心），并为 Active Directory 域中的用户和计算机提供会话凭证和临时会话密钥。客户端和服务器协作创建并相互验证它们交换的消息上的事务签名。 Windows 2000、Windows Server 2003、Windows Server 2008、Windows Server 2008 R2、Windows Server 2012、Windows Server 2012 R2 和 Windows Server 2016 都支持使用 GSS-TSIG 的 DDNS 更新。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ec0a776441e241fcaf99e04c147d83aa" data-id="ec0a776441e241fcaf99e04c147d83aa"><span><div id="ec0a776441e241fcaf99e04c147d83aa" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ec0a776441e241fcaf99e04c147d83aa" title="GSS-TSIG和Kerberos 认证的结合"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">GSS-TSIG和Kerberos 认证的结合</span></span></h2><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-6536fe5c32dc4e6e96d0c833056c3f94"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fa14f9110-5f43-431a-a664-e08d2457d1f4%2FPasted_image_20230112141327.png?table=block&amp;id=6536fe5c-32dc-4e6e-96d0-c833056c3f94&amp;t=6536fe5c-32dc-4e6e-96d0-c833056c3f94&amp;width=1110&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-8cd538723ba14305bcaf40b140a8c488">一个keytab文件包含成对的 Kerberos 主体名称及其对应的加密密钥。它可以包含单个领域或多个领域的密钥。整个流程大概如下：</div><ul class="notion-list notion-list-disc notion-block-b0c488282b874e21ac39019687cbd5de"><li>客户端使用keytab与KDC中的Authentication Server通信获取用户的TGT(AS-REQ/AS-REP)</li></ul><ul class="notion-list notion-list-disc notion-block-11213b891f524e5e9b970da7e802127f"><li>客户端使用TGT与Ticket Granting Server通信获取 session ticket（TGS-REQ/TGS-REP）</li></ul><ul class="notion-list notion-list-disc notion-block-963024e0656f4d0cb1de977c153bef64"><li>客户端使用session ticket与DNS Server通信获取<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.rfc-editor.org/rfc/rfc2930">TKEY记录</a>（Transaction Key RR），Transaction Key记录包含了共享密钥相关信息（TSIG）</li></ul><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-8094c2f9d2454b6b9cbf31adb4cc7121"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:600px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F6dc9ae19-f713-4f9e-b7ab-898d948a0307%2F%25E6%2588%25AA%25E5%25B1%258F2023-01-04_11.05.38.png?table=block&amp;id=8094c2f9-d245-4b6b-9cbf-31adb4cc7121&amp;t=8094c2f9-d245-4b6b-9cbf-31adb4cc7121&amp;width=600&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-ff200a56c58043e090dc481de944bda7">客户端进行动态更新操作，发送数据包含：</div><ul class="notion-list notion-list-disc notion-block-29867b3fe2cb4ef29b2e735517471427"><li>需要更新的记录</li></ul><ul class="notion-list notion-list-disc notion-block-f2b8a58fcaec450baf70e629cccf70c1"><li>tsig rr</li></ul><div class="notion-text notion-block-9910115f3a6d4b35b47f68f7af9a0a6e">在 KDC 上生成 keytab 文件并将其 SPN（Service Principal Name）映射到帐户，DNS 服务器对域进行身份验证。KDC 知道DNS服务器的密钥，在session ticket中使用DNS服务器密钥进行加密，client拿到后直接发给DNS Server，DNS server使用自己的密钥进行解密，解密成功并且验证client信息通过后，返回tkey给client，client在使用tkey进行动态更新的操作。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4e914da18bd4459c9bfacd7558859d40" data-id="4e914da18bd4459c9bfacd7558859d40"><span><div id="4e914da18bd4459c9bfacd7558859d40" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4e914da18bd4459c9bfacd7558859d40" title="配置步骤"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">配置步骤</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1122ac93d6f7439cb7a3d8cca6611ea5" data-id="1122ac93d6f7439cb7a3d8cca6611ea5"><span><div id="1122ac93d6f7439cb7a3d8cca6611ea5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1122ac93d6f7439cb7a3d8cca6611ea5" title="window侧"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">window侧</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-aa93bda141df443094f2d610ac1ff511"><li>创建用户,全名：dns1</li><ol class="notion-list notion-list-numbered notion-block-aa93bda141df443094f2d610ac1ff511"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3e840b44775d4c368467e25d904ac1c8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fc107cb6d-a1e8-4420-86aa-6b4d76768bfa%2FUntitled.png?table=block&amp;id=3e840b44-775d-4c36-8467-e25d904ac1c8&amp;t=3e840b44-775d-4c36-8467-e25d904ac1c8&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-70bc2677e8e043e5bde166f498031ff6"><li>将新用户与服务主体名称（SPN）关联</li><ol class="notion-list notion-list-numbered notion-block-70bc2677e8e043e5bde166f498031ff6"></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-aad38df3e8f340c485df8fbf8187d131"><li>生成keytab文件,使用<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/ktpass">Ktpass</a>工具</li><ol class="notion-list notion-list-numbered notion-block-aad38df3e8f340c485df8fbf8187d131"></ol></ol><ol start="4" class="notion-list notion-list-numbered notion-block-6b90eed1e6ea467dbe58250a7660e20b"><li>window需要配置Kerberos
打开本地安全策略 -&gt; 本地策略 -&gt; 安全选项 ，设置Kerberos允许的加密类型</li><ol class="notion-list notion-list-numbered notion-block-6b90eed1e6ea467dbe58250a7660e20b"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-74a7159abde64ed99a4801a7ea03324d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F4bed97bd-663f-4286-b705-b1dcfab204b6%2FUntitled.png?table=block&amp;id=74a7159a-bde6-4ed9-9a48-01a7ea03324d&amp;t=74a7159a-bde6-4ed9-9a48-01a7ea03324d&amp;width=680&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure></ol></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-fffc4553930c4184b343b06f5e5a5b10" data-id="fffc4553930c4184b343b06f5e5a5b10"><span><div id="fffc4553930c4184b343b06f5e5a5b10" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fffc4553930c4184b343b06f5e5a5b10" title="linux侧"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">linux侧</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-80013365d217461c9fbf8401965e0fcc" data-id="80013365d217461c9fbf8401965e0fcc"><span><div id="80013365d217461c9fbf8401965e0fcc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#80013365d217461c9fbf8401965e0fcc" title="linux机器上安装kerberos客户端"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">linux机器上安装kerberos客户端</span></span></h4><div class="notion-text notion-block-3bc617a5fae44beeb45d319df092dc28">配置kerberos配置文件</div><div class="notion-text notion-block-cfd1f8bbb1094c78a10ce188eab41f38">配置hosts</div><div class="notion-text notion-block-bceb28ee49b14da28d03a86ff28d2c97">将生成的keytab拷贝到linux机器，并执行命令获取ticket</div><div class="notion-text notion-block-aa4cf001f27e469b81a60e8e42b4ad70">如果该命令无任何返回说明执行成功，然后使用<code class="notion-inline-code">klist</code>查看ticket</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a78c16ea949b4a9ca70f602d50f8db2b"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:513px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F1a092553-fdc1-4cd5-8e76-1d247d0207c7%2FUntitled.png?table=block&amp;id=a78c16ea-949b-4a9c-a70f-602d50f8db2b&amp;t=a78c16ea-949b-4a9c-a70f-602d50f8db2b&amp;width=513&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-a27d9273cfb1431a8d6b343190a18c4f">客户端已经从KDC获取了ticket。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-ba557e15c4ad4f479b71faf189bf7b1f" data-id="ba557e15c4ad4f479b71faf189bf7b1f"><span><div id="ba557e15c4ad4f479b71faf189bf7b1f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ba557e15c4ad4f479b71faf189bf7b1f" title="Bind相关"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Bind相关</span></span></h4><div class="notion-text notion-block-2f24406430fa4881973efa3fb0ccbd4b">编译完成后，在 named.conf 配置</div><div class="notion-text notion-block-5659ad31d5a148ba8b3bd62261916a6b">启动named，使用<code class="notion-inline-code">named -d 6</code>打开更详细的debug日志，如果named服务未启动，出现如下报错
![[截屏2023-01-14 10.09.34.png]]
说明<code class="notion-inline-code">tkey-gssapi-credential</code>配置有问题。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a8258c4fa52a4e0791e6d02c678cbdf7"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F936c6737-7f83-45d6-86c7-e2b417eb2496%2FUntitled.png?table=block&amp;id=a8258c4f-a52a-4e07-91e6-d02c678cbdf7&amp;t=a8258c4f-a52a-4e07-91e6-d02c678cbdf7&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-55793d7f95b84cee995b9420e6c163cc" data-id="55793d7f95b84cee995b9420e6c163cc"><span><div id="55793d7f95b84cee995b9420e6c163cc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#55793d7f95b84cee995b9420e6c163cc" title="测试gss-tsig"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">测试gss-tsig</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-fc953f6994ab4e18a70ea28492845d25"><li>首先使用<code class="notion-inline-code">kinit -k -t /etc/dns1.keytab DNS/dns1.example.com</code>获取TGT，</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-7fb3e7b9fe0944019490bcab9fffe68a"><li>然后使用nsupdate测试</li></ol><div class="notion-callout notion-gray_background_co notion-block-ceb8c9e90c0a48558d0ead3a6e063cf8"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="❗">❗</span></div><div class="notion-callout-text">出现如下报错说明没有申请到TGT，需要使用kinit重新申请</div></div><div class="notion-callout notion-gray_background_co notion-block-dcff10bb0d7a493b8f8616d1e9c55170"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="❓">❓</span></div><div class="notion-callout-text">出现如下这个错误，说明在window那边没有example.com的SPN。需要在window那边配置一下</div></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-92ba019ec9854aed8cfa8493a3730b44"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F7b85cf8a-e540-4908-8445-6866fbdceb7a%2FUntitled.png?table=block&amp;id=92ba019e-c985-4aed-8cfa-8493a3730b44&amp;t=92ba019e-c985-4aed-8cfa-8493a3730b44&amp;width=648&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-9f24cb59a16940619d19a8855c548129" data-id="9f24cb59a16940619d19a8855c548129"><span><div id="9f24cb59a16940619d19a8855c548129" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9f24cb59a16940619d19a8855c548129" title="日志"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">日志</span></span></h4><div class="notion-text notion-block-3ba5be29c8ae4eb18546aded56092827">没有报错说明操作成功，查看bind的debug日志可以看到如下信息：</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-8e9d3a0e173748fe8a7536b7d74061f1" data-id="8e9d3a0e173748fe8a7536b7d74061f1"><span><div id="8e9d3a0e173748fe8a7536b7d74061f1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8e9d3a0e173748fe8a7536b7d74061f1" title="整体流程报文分析"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">整体流程报文分析</span></span></h2><div class="notion-text notion-block-4a4fd333d34847dab4dd8c1c6b7af7fb">Service Ticket请求报文</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4d856f02e21448cea54fcdd67593093f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F075ecfa7-1461-462a-8a6c-cce400c99355%2FUntitled.png?table=block&amp;id=4d856f02-e214-48ce-a54f-cdd67593093f&amp;t=4d856f02-e214-48ce-a54f-cdd67593093f&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-8fd4463c517f4221a885036d38a29458">Service Ticket响应报文</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-0eb1ecdc0db645d4ad0b88bcdfe93d11"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F96fd1580-3cc3-410f-afcc-f3a5b7907ddb%2FUntitled.png?table=block&amp;id=0eb1ecdc-0db6-45d4-ad0b-88bcdfe93d11&amp;t=0eb1ecdc-0db6-45d4-ad0b-88bcdfe93d11&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-176616b821144fd28351ac6b895167dc">Tkey请求报文</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3eb72d9da67e42ef86f87ff6b661b128"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Feea39b39-2853-445c-9e4c-77217931d610%2FUntitled.png?table=block&amp;id=3eb72d9d-a67e-42ef-86f8-7ff6b661b128&amp;t=3eb72d9d-a67e-42ef-86f8-7ff6b661b128&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-d8b834eb14ca44ddbc314c6cefb1aec2">Tkey响应报文</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-da384aa6c28d454db6a09fb5037c46fe"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F58842680-6d1e-498d-8d99-7e0f72d3c379%2FUntitled.png?table=block&amp;id=da384aa6-c28d-454d-b6a0-9fb5037c46fe&amp;t=da384aa6-c28d-454d-b6a0-9fb5037c46fe&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-6671f32bdb92434ca3efe989a731c25a">动态更新请求报文</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-b40efc8b6e874b2f951e8dd14015da56"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fbc697107-a49d-4885-a3c0-a405d5a77bab%2FUntitled.png?table=block&amp;id=b40efc8b-6e87-4b2f-951e-8dd14015da56&amp;t=b40efc8b-6e87-4b2f-951e-8dd14015da56&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-3df3460bb17d4f419be70519045d3c4a">动态更新响应报文</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-f34f07a0758d43ae83bd825c32664e8e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F219c31af-f145-4278-aa65-b9ca81e3d831%2FUntitled.png?table=block&amp;id=f34f07a0-758d-43ae-83bd-825c32664e8e&amp;t=f34f07a0-758d-43ae-83bd-825c32664e8e&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-callout notion-gray_background_co notion-block-7e6a5dce2bf0433d87b7fe1a330c5fec"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="❓">❓</span></div><div class="notion-callout-text">TKey记录的作用是什么？</div></div><blockquote class="notion-quote notion-block-a2dedb5c362947a8b1d6a6282ad421ed"><div>[RFC 2845] provides a means of authenticating Domain Name System(DNS) queries and responses using shared secret keys via the Transaction Signature (TSIG) resource record (RR). However, it provides no mechanism for setting up such keys other than manual exchange. This document describes a Transaction Key (TKEY) RR that can be used in a number of different modes to establish shared secret keys between a DNS resolver and server.Note that TKEY established keying material and TSIGs that use it are associated with DNS servers or resolvers. They are not associated with zones. They may be used to authenticate queries and responses but they do not provide zone based DNS data origin or denial authentication [<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.rfc-editor.org/rfc/rfc2535"><b>RFC 2535</b></a>].</div></blockquote><div class="notion-text notion-block-10899ed3c0194810aed72b44f2d45646">通俗的理解就是Tkey记录支持多种模式下建立共享密钥的能力，从而解决之前使用手动设置密钥。TKey记录和区无关，它们可用于认证查询和响应但不提供区原始记录查询。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-dcd0ae0a2e5a4f888b3e14a39507a796"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fbf194081-389a-4984-809d-c65aaf35f67b%2FUntitled.png?table=block&amp;id=dcd0ae0a-2e5a-4f88-8b3e-14a39507a796&amp;t=dcd0ae0a-2e5a-4f88-8b3e-14a39507a796&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-f0a0ce88cf5e42d68ad2e11f9184b892">从报文我们可以看出，每次的更新都会协商出一个新的TSIG。</div><div class="notion-blank notion-block-481fbb33b4234974be69d0cd682e6381"> </div><div class="notion-blank notion-block-8471f7e4d72a4d63a2079bcb7e583cc2"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FRRouting使用]]></title>
            <link>https://hexo.fridaylab.top/article/a326ec81-d727-4707-b3ca-d7d5556e1a59</link>
            <guid>https://hexo.fridaylab.top/article/a326ec81-d727-4707-b3ca-d7d5556e1a59</guid>
            <pubDate>Fri, 19 Apr 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-a326ec81d7274707b3cad7d5556e1a59"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><hr class="notion-hr notion-block-8425edca81664eb5a4302e9e8b3ff232"/><blockquote class="notion-quote notion-block-85a5ae797a1e4deb9495981669ee64af"><div>官方文档： <a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://docs.frrouting.org/en/latest">FRR</a></div></blockquote><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-7c7beaa0dbfb42d5a7f05b81362d698a" data-id="7c7beaa0dbfb42d5a7f05b81362d698a"><span><div id="7c7beaa0dbfb42d5a7f05b81362d698a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7c7beaa0dbfb42d5a7f05b81362d698a" title="架构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">架构</span></span></h2><div class="notion-text notion-block-20af463295a34658b3f01c9e3c9f842e">可以看出和Quagga基本类似，毕竟FRR就是从Quagga fork出来的，但支持更多的协议功能,同时架构图中省略了一个关键服务就是watchfrr，该服务用来监控其他服务的运行状态还有配置文件的更新。</div><blockquote class="notion-quote notion-block-877f0b06ee54436cb8bb2ad91a319e8d"><div>FRR is currently implementing a new internal configuration system based on YANG data models. When this work is completed, FRR will be a fully programmable routing stack</div></blockquote><div class="notion-text notion-block-876a054823b14e668b94e62c262844ce">FRR 目前正基于YANG 数据模型的发开一种新的配置模式。完成后，FRR 将是一个完全可编程的路由。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-9da9eb10d34b469d8c70613304920932" data-id="9da9eb10d34b469d8c70613304920932"><span><div id="9da9eb10d34b469d8c70613304920932" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9da9eb10d34b469d8c70613304920932" title="安装"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装</span></span></h2><ul class="notion-list notion-list-disc notion-block-84514df18a2a4a6aaee1dd8f2c0d7c93"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/FRRouting/frr/releases">通过Pakage包安装</a></li></ul><ul class="notion-list notion-list-disc notion-block-6441e1ebbd7e4285963520b5613d1912"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://snapcraft.io/frr">通过Snapcraft安装</a></li></ul><ul class="notion-list notion-list-disc notion-block-3c33afac766e4997bffbd4a6a088706c"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://docs.frrouting.org/projects/dev-guide/en/latest/building.html">通过源码安装</a></li></ul><div class="notion-text notion-block-2157a60f86434723a514f3728db4a885">前面两种方式比较简单，这里主要列出通过源码编译</div><ol start="1" class="notion-list notion-list-numbered notion-block-dbf299ec92f14ffdba8170d7f5224fc1"><li>编译libyang</li><ol class="notion-list notion-list-numbered notion-block-dbf299ec92f14ffdba8170d7f5224fc1"></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-b4519019fc7c4e539866b8df1adfbacd"><li>编译frr</li><ol class="notion-list notion-list-numbered notion-block-b4519019fc7c4e539866b8df1adfbacd"></ol></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-73083ad6dc6346b9bc8ad4c78f66e8bf" data-id="73083ad6dc6346b9bc8ad4c78f66e8bf"><span><div id="73083ad6dc6346b9bc8ad4c78f66e8bf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#73083ad6dc6346b9bc8ad4c78f66e8bf" title="安装后需要注意"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装后需要注意</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-a1d313d259504bafb1798c8592ea04e4"><li>当使用 Linux 作为路由器时，有几个内核参数会影响 FRR 的整体操作。通常，这些参数应该在 sysctl 相关的配置文件中设置，例如， Ubuntu 的系统 <code class="notion-inline-code">/etc/sysctl.conf</code> 和Centos 的系统<code class="notion-inline-code">/etc/sysctl.d/90-routing-sysctl.conf</code>文件中。
<code class="notion-inline-code">net.ipv4.conf.all.forwarding=1net.ipv6.conf.all.forwarding=1</code></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-26ba360f9ce94cbd86e3251d949c8862"><li>在使用ripd或ospfd时需要保证是开启了IP多播的，因为这些协议使用到了多播
<code class="notion-inline-code">CONFIG_IP_MULTICAST = yes</code></li></ol><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-9d3abbd977ff4fb0a4ed67eb11f38913" data-id="9d3abbd977ff4fb0a4ed67eb11f38913"><span><div id="9d3abbd977ff4fb0a4ed67eb11f38913" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9d3abbd977ff4fb0a4ed67eb11f38913" title="配置说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">配置说明</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-57e8fe549f2b4a3eac4092a677add452" data-id="57e8fe549f2b4a3eac4092a677add452"><span><div id="57e8fe549f2b4a3eac4092a677add452" class="notion-header-anchor"></div><a class="notion-hash-link" href="#57e8fe549f2b4a3eac4092a677add452" title="系统日志"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">系统日志</span></span></h3><div class="notion-text notion-block-910197498191448d92c4174fdade53c5">如果任何守护进程由于某种原因崩溃，它将写入位于<code class="notion-inline-code">/var/tmp/frr/&lt;daemon&gt;[-&lt;instance&gt;].&lt;pid&gt;/crashlog</code>目录下，该路径暂时不能通过配置文件进行修改。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-21a0b6580af84e79aba737586ce5bf5b" data-id="21a0b6580af84e79aba737586ce5bf5b"><span><div id="21a0b6580af84e79aba737586ce5bf5b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#21a0b6580af84e79aba737586ce5bf5b" title="配置文件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">配置文件</span></span></h3><div class="notion-text notion-block-917544394b8247359316b2866607f95f">在/etc/frr目录下存在三个配置文件，分别是</div><ul class="notion-list notion-list-disc notion-block-a9add2f61e16490ebc1cc0061b0a4994"><li>daemon ： 配置各个服务启动和启动参数的文件</li></ul><ul class="notion-list notion-list-disc notion-block-7d485d59e00942dea881af9a103131bf"><li>frr.conf： 配置每个服务具体的参数值</li></ul><ul class="notion-list notion-list-disc notion-block-af12f60dd7a14b51b58a1a1bf65284a8"><li>vtysh.conf： 配置使用vtysh命令工具的</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-587866365fc04086bc94878ff0a92448" data-id="587866365fc04086bc94878ff0a92448"><span><div id="587866365fc04086bc94878ff0a92448" class="notion-header-anchor"></div><a class="notion-hash-link" href="#587866365fc04086bc94878ff0a92448" title="daemon文件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">daemon文件</span></span></h4><div class="notion-text notion-block-54b2aef7b5b1462e9d449bffbded1e5d">该配置文件就是用来负责配置开启哪些服务，以及每个服务的配置参数的设置。例如需要启动rip和bgp则修改配置文件</div><div class="notion-text notion-block-a8febcc1fad74eee92da2428fed52f02"><b>重启服务</b></div><div class="notion-text notion-block-4f7fb54375ac417285f83052157e063c">重新启动会杀死所有正在运行的 FRR 守护程序并重新启动它们</div><div class="notion-text notion-block-f398a2f5cabe409db86f882533884ca0"><b>重加载服务</b></div><div class="notion-text notion-block-1369bd85d5d047f0a2509ef8fe5a84bd">重新加载应用磁盘配置和当前运行 FRR 进程的有效配置之间的差异， 当修改了某一个服务的配置文件可以通过该命令使其生效。</div><div class="notion-callout notion-gray_background_co notion-block-9e4a7efd194a4aab8dc79257030eee0f"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="❗">❗</span></div><div class="notion-callout-text">目前没有办法停止或重新启动单个守护程序。这是因为 FRR 的监控程序目前无法区分崩溃/终止的守护程序与故意停止或重新启动的守护程序。只有将需要停止的服务设置/etc/frr/daemons为no，然后重新启动服务。</div></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-61bdd7444b7b4472bf2dfc7fc6b220c8" data-id="61bdd7444b7b4472bf2dfc7fc6b220c8"><span><div id="61bdd7444b7b4472bf2dfc7fc6b220c8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#61bdd7444b7b4472bf2dfc7fc6b220c8" title="frr.conf"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">frr.conf</span></span></h4><div class="notion-text notion-block-6e9157951f7c44a5894fa3d3b698ff2b">使用过Quagga的应该知道，每个服务有对应的配置文件，默认的配置文件名是：守护进程名称 .conf。比如zebra 的默认配置文件是<code class="notion-inline-code">zebra.conf</code>，ospf的默认配置文件是<code class="notion-inline-code">ospf.conf</code>。</div><div class="notion-text notion-block-baa2b73c7e2b4adc861be0a9d78b83a9">由于这样会创建大量的配置文件，因此frr使用一个文件为<code class="notion-inline-code">/etc/frr/frr.conf</code>来配置所有的服务。 当使用 init 脚本或 systemd 启动 FRR 时，<code class="notion-inline-code">vtysh</code>会调用它来读取配置文件并将适当的部分仅发送给对它们感兴趣的守护进程，如果需要为每个服务指定配置，可以在daemon中通过配置参数<code class="notion-inline-code">-f</code> 或者 <code class="notion-inline-code">--config_file</code>进行指定。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-323a59ddaa684e52b80225d5b9b1f509" data-id="323a59ddaa684e52b80225d5b9b1f509"><span><div id="323a59ddaa684e52b80225d5b9b1f509" class="notion-header-anchor"></div><a class="notion-hash-link" href="#323a59ddaa684e52b80225d5b9b1f509" title="vtysh.conf"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">vtysh.conf</span></span></h4><div class="notion-text notion-block-26545f1367fb4b28b54b152ac1010265">配置vtysh工具</div><div class="notion-text notion-block-8294ec82303244348a3575530e005991">service integrated-vtysh-config</div><div class="notion-text notion-block-fa1bf9976f4649108a938f1ee60aea49">该命令表示，当在vtysh里面执行<code class="notion-inline-code">write</code>命令时，配置写入到什么地方去。</div><ul class="notion-list notion-list-disc notion-block-44d4173eb53a4e1d98e17d2db5abefe7"><li>service integrated-vtysh-config：</li><ul class="notion-list notion-list-disc notion-block-44d4173eb53a4e1d98e17d2db5abefe7"><li>vtysh将始终写入frr.conf文件中</li></ul></ul><ul class="notion-list notion-list-disc notion-block-521c65d402504759a30ba24fa0315b7b"><li>no service integrated-vtysh-config：</li><ul class="notion-list notion-list-disc notion-block-521c65d402504759a30ba24fa0315b7b"><li>vtysh永远不会写frr.conf文件，它会要求守护进程编写它们各自的配置文件。</li></ul></ul><ul class="notion-list notion-list-disc notion-block-e735ab6dc990402db3733f6f4dbac113"><li>Neither option present (default)：</li><ul class="notion-list notion-list-disc notion-block-e735ab6dc990402db3733f6f4dbac113"><li>vtysh会检查是否frr.conf文件存在。如果是这样，配置写入将更新该文件。否则，将通过各个守护程序执行写入</li></ul></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-089d7f0b92ab4cbd8d7fe0d52daba199" data-id="089d7f0b92ab4cbd8d7fe0d52daba199"><span><div id="089d7f0b92ab4cbd8d7fe0d52daba199" class="notion-header-anchor"></div><a class="notion-hash-link" href="#089d7f0b92ab4cbd8d7fe0d52daba199" title="vtysh"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">vtysh</span></span></h3><div class="notion-text notion-block-96d04130e0f34043a9476f5c9d1a30d6">vtysh是一个cli工具，可用于为所有 FRR 守护进程提供前端服务的。它在构建时默认启用，但可以通过<code class="notion-inline-code">--disable-vtysh</code>配置脚本的选项禁用。</div><div class="notion-text notion-block-2f3e3d9e7e9549a98ac257c2fd857042">FRR守护进程中，有一个watchfrr服务负责收集和写入各个服务的配置信息。使用vtysh进行相关服务的配置时，实际上是与watchfrr服务进行通信，通过watchfrr尝试配置写入，由于_watchfrr_以超级用户身份运行， 因此 vtysh能够确保对 <code class="notion-inline-code">write integrated frr.conf</code>。如果watchfrr没有运行或者配置写入失败，vtysh会尝试直接写入文件。</div><div class="notion-callout notion-gray_background_co notion-block-1fc6912483224a349cad368d8c9dea50"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="❗">❗</span></div><div class="notion-callout-text">在启动时，所有守护程序都会检查启动时是否存在frr.conf，如果存在，则不会加载各个配置文件。调用vtysh -b来处理frr.conf并将其设置应用于单个守护进程。</div></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0fdc9b1fb9ea427e84a624fee643b17e" data-id="0fdc9b1fb9ea427e84a624fee643b17e"><span><div id="0fdc9b1fb9ea427e84a624fee643b17e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0fdc9b1fb9ea427e84a624fee643b17e" title="配置实例"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">配置实例</span></span></h3><div class="notion-text notion-block-9c9772efc392407c8e3b6ccd02230c87">实际上和quagga的配置方式几乎一样，这里将演示通过vtysh和配置文件的方式进行配置测试</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-6c1fdfd8838f4b25afa79b12871fee76" data-id="6c1fdfd8838f4b25afa79b12871fee76"><span><div id="6c1fdfd8838f4b25afa79b12871fee76" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6c1fdfd8838f4b25afa79b12871fee76" title="OSPF"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">OSPF</span></span></h4><div class="notion-text notion-block-f7885811fe4f42cf8af03eff8ec195e5">添加一个虚拟网卡并配置地址</div><div class="notion-text notion-block-1a9887c061e34356be6da5207a4aa06c">保存以后会写入/etc/frr/frr.conf</div><div class="notion-text notion-block-eeb57d8410214a2a936da865e74f0594">另一台机器类似的操作。然后就可以通过查看<code class="notion-inline-code">route -n</code> 查看路由，可以发现多了一条路由规则，就是通过ospf协议学习得到的。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-7a38a42395004effa83dce3b03b463d0" data-id="7a38a42395004effa83dce3b03b463d0"><span><div id="7a38a42395004effa83dce3b03b463d0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7a38a42395004effa83dce3b03b463d0" title="BGP"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">BGP</span></span></h4><div class="notion-text notion-block-169879bb58ad48a09df1988bf42137cd">在使用bgp时，绝大部分配置和quagga是一样的，但是frr需要添加一条配置项<code class="notion-inline-code">no bgp ebgp-requires-policy</code>,才能正常的获取到路由。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[初识SAML2.0协议]]></title>
            <link>https://hexo.fridaylab.top/article/1b76dd5a-4608-4d60-a2a4-4bf65def9cc0</link>
            <guid>https://hexo.fridaylab.top/article/1b76dd5a-4608-4d60-a2a4-4bf65def9cc0</guid>
            <pubDate>Thu, 18 Apr 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-1b76dd5a46084d60a2a44bf65def9cc0"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-77e6f47cf347452e9b04f096ed1ab88b" data-id="77e6f47cf347452e9b04f096ed1ab88b"><span><div id="77e6f47cf347452e9b04f096ed1ab88b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#77e6f47cf347452e9b04f096ed1ab88b" title="什么是SAML"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是SAML</span></span></h2><div class="notion-text notion-block-b2b527a4b2894565a5a35d72ecdd3a5b">SAML全称安全断言标记语言（Security Assertion Markup Language），它是一种基于XML的开放标准，用于表示和交换用户属性、身份和认证信息。在对用户进行一次身份验证的基础上，将验证结果传递给多个应用程序，达到单点登录SSO的效果。</div><div class="notion-text notion-block-f9333782edcf45eb971c9c2c2439188c">SAML是一种身份验证，并不包括用户授权认证的过程。身份验证用于确认用户的身份，类似于身份证，用来展示一个人的信息并证明“我是我“。而授权则是确认用户的权限，表明用户他能进行哪些操作</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-005ab738ca1444daae5f4c261c4547c4" data-id="005ab738ca1444daae5f4c261c4547c4"><span><div id="005ab738ca1444daae5f4c261c4547c4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#005ab738ca1444daae5f4c261c4547c4" title="SAML是如何运行的"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">SAML是如何运行的</span></span></h2><div class="notion-callout notion-gray_background_co notion-block-bc29d2daedd2421c840c981805e087d4"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="📎">📎</span></div><div class="notion-callout-text">三个参与方：<div class="notion-text notion-block-23c657f2d89946bb95e00779d01e5e57">1. <b>用户</b>
2. <b>身份提供方（IDP）</b>：是一种存储和管理用户数字身份的服务，IDP 可以通过验证账号密码等方式来检查用户身份，并提供用户身份列表供其他服务提供商（如 SSO）检查。
3. <b>服务提供方（SP）</b>：用户使用的相关服务，如B站、淘宝、飞书都是服务的提供方.</div></div></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-e3045dbdf2634eafb92907b05689c196"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F3a714807-e2dd-4042-85b7-3a771a85a3ae%2FUntitled.png?table=block&amp;id=e3045dbd-f263-4eaf-b929-07b05689c196&amp;t=e3045dbd-f263-4eaf-b929-07b05689c196&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-74d65d60923b42d2ab07f1054328a472">如上图所示，处理流程：</div><ol start="1" class="notion-list notion-list-numbered notion-block-6ea4c89efbb941a995cebf670bfc8975"><li>用户访问SP提供的服务页面，并进行SSO登录</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-98e6da31e778467bb368d21e4cce90b0"><li>SP通过重定向跳转到IDP服务</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-3b05848c901c44f4bda0d7b92b517496"><li>IDP识别到用户未登录则会跳转到登录页面，用户进行登录操作</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-33852f8cfb744a48bcb96713f8771b14"><li>IDP登录成功后，返回SAML Response断言信息</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-60bea9faf39c497986f11b80ba403a65"><li>SP获取到SAML断言后根据结果提供对应的访问策略
SAML断言包含了SP所需要的所有信息，包括断言的ID来源、签发时间、有效时间、SP的地址等信息。</li></ol><div class="notion-text notion-block-fa9e4a5c5d204832ac9e0b6d3d71e1ae">在SP重定向到IDP时会发送一个AuthNRequest消息</div><div class="notion-text notion-block-7b56e5713ea74b0d9fe6125eadf42269">可以看出，该XML里面存储了几个关键信息：</div><ul class="notion-list notion-list-disc notion-block-535d213696654f10845c0bafd330b371"><li><code class="notion-inline-code">ID=&quot;ONELOGIN_809707f0030a5d00620c9d9df97f627afe9dcc24&quot;</code></li><ul class="notion-list notion-list-disc notion-block-535d213696654f10845c0bafd330b371"><li>唯一ID</li><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-68f77155d2cb4f83b752542252559c2b"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F776e9a55-08e7-4324-86d9-fca7618062d1%2F1.jpeg?table=block&amp;id=68f77155-d2cb-4f83-b752-542252559c2b&amp;t=68f77155-d2cb-4f83-b752-542252559c2b&amp;width=1200&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure></ul></ul><ul class="notion-list notion-list-disc notion-block-7d3c91aa663a44fcb01eceebd47f75c9"><li><code class="notion-inline-code">IssueInstant=&quot;2014-07-16T23:52:45Z&quot;</code></li><ul class="notion-list notion-list-disc notion-block-7d3c91aa663a44fcb01eceebd47f75c9"><li>签发时间</li></ul></ul><ul class="notion-list notion-list-disc notion-block-4a421766c8114c23a83e0d8e8f7c6bfc"><li><code class="notion-inline-code">Destination=&quot;&lt;http://idp.example.com/SSOService.php&gt;&quot;</code></li><ul class="notion-list notion-list-disc notion-block-4a421766c8114c23a83e0d8e8f7c6bfc"><li>IDP地址</li></ul></ul><ul class="notion-list notion-list-disc notion-block-0394452f7acf43a0befd00ee0053bef6"><li><code class="notion-inline-code">ProtocolBinding=&quot;urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST&quot;</code></li><ul class="notion-list notion-list-disc notion-block-0394452f7acf43a0befd00ee0053bef6"><li>使用的协议</li></ul></ul><ul class="notion-list notion-list-disc notion-block-6f6f4a10634d4d98b99dfa328918e166"><li><code class="notion-inline-code">AssertionConsumerServiceURL=&quot;&lt;http://sp.example.com/demo1/index.php?acs&gt;&quot;</code></li><ul class="notion-list notion-list-disc notion-block-6f6f4a10634d4d98b99dfa328918e166"><li>回调SP的接口地址</li></ul></ul><ul class="notion-list notion-list-disc notion-block-3c935aafab7844afa322ebf603166780"><li><code class="notion-inline-code">&lt;saml:Issuer&gt;&lt;http://sp.example.com/demo1/metadata.php&gt;&lt;/saml:Issuer&gt;</code></li><ul class="notion-list notion-list-disc notion-block-3c935aafab7844afa322ebf603166780"><li>发起方</li></ul></ul><div class="notion-text notion-block-3a1fadec26a2491c8e3aa8909a6c2da1">IDP登录成功后就会返回响应的SAML Response</div><div class="notion-text notion-block-8399c90e619642a6a8aa9b88887a1f7a">返回结果中也有一些关键信息：</div><ul class="notion-list notion-list-disc notion-block-6e0d30fe2446447da976fdd342704955"><li><code class="notion-inline-code">InResponseTo=&quot;ONELOGIN_4fee3b046395c4e751011e97f8900b5273d56685&quot;</code></li><ul class="notion-list notion-list-disc notion-block-6e0d30fe2446447da976fdd342704955"><li>对应于SP发起请求的ID</li></ul></ul><ul class="notion-list notion-list-disc notion-block-b17804ff52ab40c5b33bb37d34c7e85e"><li><code class="notion-inline-code">&lt;samlp:StatusCode Value=&quot;urn:oasis:names:tc:SAML:2.0:status:Success&quot;/&gt;</code></li><ul class="notion-list notion-list-disc notion-block-b17804ff52ab40c5b33bb37d34c7e85e"><li>响应结果</li></ul></ul><ul class="notion-list notion-list-disc notion-block-3bbe7b7171c24246b41f15889fae7bbe"><li><code class="notion-inline-code">&lt;saml:AuthnStatement AuthnInstant=&quot;2014-07-17T01:01:48Z&quot; SessionNotOnOrAfter=&quot;2024-07-17T09:01:48Z&quot; SessionIndex=&quot;_be9967abd904ddcae3c0eb4189adbe3f71e327cf93&quot;&gt;</code></li><ul class="notion-list notion-list-disc notion-block-3bbe7b7171c24246b41f15889fae7bbe"><li>会话有效期</li></ul></ul><ul class="notion-list notion-list-disc notion-block-f47546d1b6cd492e99edcb695bf98638"><li><code class="notion-inline-code">&lt;saml:Attribute Name=&quot;uid&quot; NameFormat=&quot;urn:oasis:names:tc:SAML:2.0:attrname-format:basic&quot;&gt;</code></li><ul class="notion-list notion-list-disc notion-block-f47546d1b6cd492e99edcb695bf98638"><li>返回结果相关属性参数</li></ul></ul><div class="notion-text notion-block-03ecdf1aea3d4896bf666908ece54029">整个流程图如下图所示：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-c172fb0adb4843a1be1a7d8a00a8626c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:459px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F54fed115-8783-413f-b6f0-cc8cea07f542%2FUntitled.png?table=block&amp;id=c172fb0a-db48-43a1-be1a-7d8a00a8626c&amp;t=c172fb0a-db48-43a1-be1a-7d8a00a8626c&amp;width=459&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-ba5849691ce846368c81569d88d0931b">上述用户以SP为入口是一种场景，还有一种场景是用户先登录IDP，然后在选择指定的SP应用，IDP再跳转到SP应用中去。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-0fcaee8f6bd34c0f91ff98e5b2b2d98f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:487px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F9d355746-308b-41d6-a625-7c955588ed58%2FUntitled.png?table=block&amp;id=0fcaee8f-6bd3-4c0f-91ff-98e5b2b2d98f&amp;t=0fcaee8f-6bd3-4c0f-91ff-98e5b2b2d98f&amp;width=487&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-c3f4b63be1d84782a1cc8bc35bc93e8f">该场景处理流程：</div><ul class="notion-list notion-list-disc notion-block-5eed4e2b1f3b44f2837d1e051b53b333"><li>用户访问IDP，进行登录；登录完成选择SP访问</li></ul><ul class="notion-list notion-list-disc notion-block-e576dda737534cfbb28b2dd7cd28f59f"><li>IDP重定向到SP，生成SAML Response，并调用SP 的ACS url 将结果返回</li></ul><ul class="notion-list notion-list-disc notion-block-34694d60cde54bb0bbe5799b6d63aea2"><li>SP验证SAML Response，并授权访问</li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-a392bdfe617d435cbf73527cd451c8fd" data-id="a392bdfe617d435cbf73527cd451c8fd"><span><div id="a392bdfe617d435cbf73527cd451c8fd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a392bdfe617d435cbf73527cd451c8fd" title="代码实践"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">代码实践</span></span></h2><div class="notion-text notion-block-67dac66c2c7d4943bae7c9b49734aff0">我是用go进行代码编辑和测试，使用https://samltest.id 这个网站进行测试，用到的三方库是 <code class="notion-inline-code">go get github.com/crewjam/saml</code></div><div class="notion-text notion-block-bbf38c636a854eca8244c3ac7a1f2dbd">服务启动后，首先访问 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://localhost:8001/saml/metadata">http://localhost:8001/saml/metadata</a> 获取xml元数据，上传到https://samltest.id/upload.php ，再访问 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://localhost:8001/auth">http://localhost:8001/auth</a> 就会跳转到samltest的登录页面。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-09cc65f8b2ae49f99dfb77f3af1ec1f5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F59c79166-e5fc-4619-b16e-4651abdd2823%2FUntitled.png?table=block&amp;id=09cc65f8-b2ae-49f9-9dfb-77f3af1ec1f5&amp;t=09cc65f8-b2ae-49f9-9dfb-77f3af1ec1f5&amp;width=1080&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-5b7ec4c03f254aaba90fa9f574962c46">选择页面下方任意一个提供的账号密码进行登录,登录成功后就会显示如下信息</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2091db763641495b85ce868d2eda3837"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fc6d1a302-54ef-41d4-aeb8-5fe28d22b0cc%2FUntitled.png?table=block&amp;id=2091db76-3641-495b-85ce-868d2eda3837&amp;t=2091db76-3641-495b-85ce-868d2eda3837&amp;width=784&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4fec4be242204eceaf1de9c42f946929">通过Wireshake抓包，监听lo网卡，端口设置tcp.port == 8001，我们可以得到</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-fa9508acb709424eb3e9ea187ed1c1df"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F92f9a08f-6a9b-49f4-a32c-92bc2772248b%2FUntitled.png?table=block&amp;id=fa9508ac-b709-424e-b3e9-ea187ed1c1df&amp;t=fa9508ac-b709-424e-b3e9-ea187ed1c1df&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-efd40475adad4a8aa6a9bc8208c2f689">可以看出，首先访问/auth地址时，我们启动的服务（SP）将请求重定向到了https://samltest.id/idp/profile/SAML2/Redirect/SSO, 然后我们输入账号密码验证成功后，IDP就回调了/saml/acs接口，发送了saml断言信息，我们服务根据信息再经过重定向到我们最开始访问的/auth接口，最终返回具体的信息。整个测试过程，我们启动的服务是作为服务提供方，<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://samltest.id/">https://samltest.id</a>, 则是作为身份提供方，对身份进行验证，并返回验证结果和身份的相关属性。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-1148364ee6364a5ba75ee143e95d5c83" data-id="1148364ee6364a5ba75ee143e95d5c83"><span><div id="1148364ee6364a5ba75ee143e95d5c83" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1148364ee6364a5ba75ee143e95d5c83" title="对接Okta"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">对接Okta</span></span></h2><div class="notion-text notion-block-d736d034caf04825b6847d0eb3d7bf11">为了更好的模拟真实的对接场景，我将通过与okta进行SSO集成对接进行演示。使用ruby进行测试。首先登录okta后台，选择Application --&gt; Create App Integration创建应用，然后再选择SAML2.0；再输入应用名。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-e9a9c68eae42477d90a9fefdd3fb3010"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F22a0611d-8981-4c7c-a447-bb081bbd28c0%2FUntitled.png?table=block&amp;id=e9a9c68e-ae42-477d-90a9-fefdd3fb3010&amp;t=e9a9c68e-ae42-477d-90a9-fefdd3fb3010&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><ol start="1" class="notion-list notion-list-numbered notion-block-ef880cddf02a4810aeeb310e46f2d3ab"><li>Single sign on URL 填写的是SP的回调接口Audience URI 填写SP的metadata地址</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-3cfb499559db41718f3352b6c8183e60"><li>Attribute Statements可填写一些属性，如用户名，ID等信息。</li></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-7fe0685edd78441f8425a243c8487642"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F0962d1d9-a0ff-466e-8010-3cdc7c977df3%2FUntitled.png?table=block&amp;id=7fe0685e-dd78-441f-8425-a243c8487642&amp;t=7fe0685e-dd78-441f-8425-a243c8487642&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-145b0f53e43e4a398492785e56957866">应用创建完成后，再将该应用授权给指定用户，在Directory --&gt; People --&gt; Add person 创建用户，然后点击该用户，选择Assign Application选择授权的应用。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-86a3b8e0b409459880c64d897705cca0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F5edf711b-b55e-451e-bbb5-92cf2d091998%2FUntitled.png?table=block&amp;id=86a3b8e0-b409-4598-80c6-4d897705cca0&amp;t=86a3b8e0-b409-4598-80c6-4d897705cca0&amp;width=900&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-8c3795fa5873414588b332e20069626a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2F2b697746-bd97-4737-86f2-28aa53015051%2FUntitled.png?table=block&amp;id=8c3795fa-5873-4145-88b3-32e20069626a&amp;t=8c3795fa-5873-4145-88b3-32e20069626a&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-f1dc4c7d18934bcbb28f2ae709fc2744">所有的步骤操作完成后，我们获取okta的saml 登录证书地址，选择Application，点击创建的应用，再选择Sign on，就可看到okta提供的证书，为了拿到其地址我们点击View Idp metadata，他就会回跳转到新的页面，页面地址就是我们需要的IDP metadata url，将其替换代码的相应位置即可。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a0968263fae04f23be0eac238ecaa7ed"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F08d46eca-8983-47ea-b472-2f608083c721%2Fa7ec1cd6-35bf-4fa4-ab98-d74b2558ca10%2FUntitled.png?table=block&amp;id=a0968263-fae0-4f23-be0e-ac238ecaa7ed&amp;t=a0968263-fae0-4f23-be0e-ac238ecaa7ed&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-af08364bc1b04e30bc1d933045dc8e0f">接下来测试流程就和上面经过抓包，使用我们对相关请求使用工具(<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.scottbrady91.com/tools/saml-parser">https://www.scottbrady91.com/tools/saml-parser</a>) 进行解码处理得到：</div><div class="notion-text notion-block-ca258eb812874bd186f13aed40a4e5f0">这是在重定向时携带的SAML Request的信息，包含ID、发起时间、目标IDP地址,回调SP的地址和发起者。  </div><div class="notion-text notion-block-5314b03ab2884ff0be66c6f96c5f7cea">这是okta登录成功后回调请求/saml/acs接口时发送的SAML Response，包含目的SP回调地址，该消息对应的请求ID，响应状态，用户属性等。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-bc17a3ba611241ca8953895d23738b9c" data-id="bc17a3ba611241ca8953895d23738b9c"><span><div id="bc17a3ba611241ca8953895d23738b9c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bc17a3ba611241ca8953895d23738b9c" title="总结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">总结</span></span></h2><div class="notion-text notion-block-3e62faa2d08d4e989b89465fa981d820">SAML协议制定于2005年，所以在制定的时候主要针对Web应用程序，并没有考虑后来的App，在兼容性上不是那么好。特别是在2012后OAuth2的出现，越来越多的人在单点登录上的第一选择更多是OAuth2（后面也会写相关文章来介绍OAuth2）。但SAML通过HTTP Redirect 和Post 协议来传递身份验证消息，并使用Form格式进行数据提交，整个协议交互比较简单，方便使用集成，在今天还是有它的一席之地的。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-3d0fe327bae74509950e99092a61643d" data-id="3d0fe327bae74509950e99092a61643d"><span><div id="3d0fe327bae74509950e99092a61643d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3d0fe327bae74509950e99092a61643d" title="参考文档"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">参考文档</span></span></h2><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-403a23db11914e5f86c0ff6f648551c9" href="https://www.ibm.com/docs/zh/was-liberty/base?topic=authentication-saml-20-web-browser-single-sign"><div><div class="notion-bookmark-title">SAML 2.0 Web 浏览器单点登录</div><div class="notion-bookmark-description">SAML Web 浏览器单点登录 (SSO) 允许 Web 应用程序将用户认证授权给 SAML 身份提供者（而不是所配置的用户注册表）。</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://www.ibm.com/favicon.ico?t=403a23db-1191-4e5f-86c0-ff6f648551c9" alt="SAML 2.0 Web 浏览器单点登录" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://www.ibm.com/docs/zh/was-liberty/base?topic=authentication-saml-20-web-browser-single-sign</div></div></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-0d1dbf7db4394692a7d94ebb7c4d6b89" href="http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0-cd-02.pdf"><div><div class="notion-bookmark-title">docs.oasis-open.org</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-text">http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0-cd-02.pdf</div></div></div></a></div><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-c3a681dfea6749dda291979866036795" href="https://klose911.github.io/html/material/saml.html"><div><div class="notion-bookmark-title">SAML2.0 指南</div><div class="notion-bookmark-description">SAML 全称为 Security Assertion Markup Language ，是一种用于 安全性断言 的 标记语言 ，目前的最新版本是 2.0</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-text">https://klose911.github.io/html/material/saml.html</div></div></div></a></div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>