import{_ as n}from"./ac-3hZRgLfv.js";import{_ as s,o as a,c as t,e}from"./app-xDBkFjzT.js";const o={},p=e('<blockquote><p>网络代理可以利用重定向中间人技术,接管系统的所有tcp网络连接。</p><p>适用于:上网行为管理、网络监控审计、零信任的网络准入、广告过滤等。</p><p>支持http、https,支持https的自动识别、回退。支持对http代理下流量的二次监控过滤。</p></blockquote><h2 id="上网行为管理示例" tabindex="-1"><a class="header-anchor" href="#上网行为管理示例" aria-hidden="true">#</a> 上网行为管理示例</h2><blockquote><p>代码参考 sample/http_access_control</p></blockquote><figure><img src="'+n+`" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><h2 id="接口说明" tabindex="-1"><a class="header-anchor" href="#接口说明" aria-hidden="true">#</a> 接口说明</h2><h3 id="imonitoragentengine" tabindex="-1"><a class="header-anchor" href="#imonitoragentengine" aria-hidden="true">#</a> IMonitorAgentEngine</h3><div class="language-cpp line-numbers-mode" data-ext="cpp"><pre class="language-cpp"><code>interface IMonitorAgentEngine <span class="token operator">:</span> <span class="token keyword">public</span> IUnknown
<span class="token punctuation">{</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>          <span class="token function">Agent</span>                <span class="token punctuation">(</span>IMonitorMessage<span class="token operator">*</span> Message<span class="token punctuation">,</span> IMonitorAgentCallback<span class="token operator">*</span> Callback<span class="token punctuation">,</span> <span class="token keyword">bool</span> SSL <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

HRESULT     <span class="token function">CreateAgentEngine</span>    <span class="token punctuation">(</span>ULONG MaxThread<span class="token punctuation">,</span> IMonitorAgentEngine<span class="token operator">*</span><span class="token operator">*</span> Engine<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><table><thead><tr><th>函数</th><th>说明</th></tr></thead><tbody><tr><td>CreateAgentEngine</td><td>创建代理引擎,MaxThread表示并发的线程数,默认是1,最大是10。SDK会为每一个线程创建一个独立监听端口。同一个连接的回调都是在单线程触发。</td></tr><tr><td>Agent</td><td>建立代理,只支持SocketConnect、WFPTcpConnect的消息类型,并且需要是Wating状态的。SSL表示是否支持SSL连接。</td></tr></tbody></table><blockquote><p>代理建立后连接如下:</p><p>client(本地客户端,比如浏览器) --&gt; Agent --&gt; remote(远程网络)</p><p>所有的事件通过IMonitorAgentCallback触发。</p></blockquote><h3 id="imonitoragentcallback" tabindex="-1"><a class="header-anchor" href="#imonitoragentcallback" aria-hidden="true">#</a> IMonitorAgentCallback</h3><div class="language-cpp line-numbers-mode" data-ext="cpp"><pre class="language-cpp"><code>interface IMonitorAgentCallback
<span class="token punctuation">{</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnCreate</span>            <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnLocalConnect</span>      <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">OnLocalSSLHello</span>     <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">,</span> <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> ServerName<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnLocalReceive</span>      <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">,</span> <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> Data<span class="token punctuation">,</span> size_t Length<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnLocalError</span>        <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">,</span> <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> Error<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnLocalDisconnect</span>   <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">OnRemotePreConnect</span>  <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">OnRemoteSSLVerify</span>   <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">,</span> <span class="token keyword">bool</span> PreVerified<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> PreVerified<span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnRemoteConnect</span>     <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnRemoteReceive</span>     <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">,</span> <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> Data<span class="token punctuation">,</span> size_t Length<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnRemoteError</span>       <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">,</span> <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> Error<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnRemoteDisconnect</span>  <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">OnClose</span>             <span class="token punctuation">(</span>IMonitorAgentChannel<span class="token operator">*</span> Channel<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><table><thead><tr><th>函数</th><th>说明</th></tr></thead><tbody><tr><td>OnCreate</td><td>代理创建的时候,这时可以通过SetContext设置上下文</td></tr><tr><td>OnLocalConnect</td><td>本地(浏览器连接到Agent)连接建立成功</td></tr><tr><td>OnLocalSSLHello</td><td>【https】ssl的握手client_hello,这里可以判断是否继续代理,返回false则不会解析https的内容,直接透传原始数据,可以解决双向认证的代理失败问题等。</td></tr><tr><td>OnRemotePreConnect</td><td>开始连接远程服务器,可以这里设置IP、Port修改原始的远程地址,适用于网络代理、准入、零信任等需求</td></tr><tr><td>OnRemoteSSLVerify</td><td>【https】证书校验结果,如果返回true的使用有效证书,返回false则保留无效证书(浏览器会变红)</td></tr><tr><td>OnRemoteConnect</td><td>双向连接建立成功,可以开始收发包</td></tr><tr><td>OnClose</td><td>连接断开,这时可以反初始化,比如释放Context的内容</td></tr></tbody></table><h3 id="imonitoragentchannel" tabindex="-1"><a class="header-anchor" href="#imonitoragentchannel" aria-hidden="true">#</a> IMonitorAgentChannel</h3><div class="language-cpp line-numbers-mode" data-ext="cpp"><pre class="language-cpp"><code>interface IMonitorAgentChannel
<span class="token punctuation">{</span>
    <span class="token keyword">struct</span> <span class="token class-name">Address</span> <span class="token punctuation">{</span>
        ULONG                IP<span class="token punctuation">;</span>
        USHORT                Port<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>

    <span class="token keyword">virtual</span> ULONG           <span class="token function">LocalGetProcessId</span>   <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> Address         <span class="token function">LocalGetAddress</span>     <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">LocalSetAutoSend</span>    <span class="token punctuation">(</span><span class="token keyword">bool</span> Enable<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">LocalSetAutoReceive</span> <span class="token punctuation">(</span><span class="token keyword">bool</span> Enable<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">LocalSend</span>           <span class="token punctuation">(</span><span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> Data<span class="token punctuation">,</span> size_t Length<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">LocalReceive</span>        <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">LocalDisconnect</span>     <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">RemoteSetAddress</span>    <span class="token punctuation">(</span>ULONG IP<span class="token punctuation">,</span> USHORT Port<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> Address         <span class="token function">RemoteGetAddresss</span>   <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">RemoteSetAutoSend</span>   <span class="token punctuation">(</span><span class="token keyword">bool</span> Enable<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">RemoteSetAutoReceive</span><span class="token punctuation">(</span><span class="token keyword">bool</span> Enable<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">RemoteSend</span>          <span class="token punctuation">(</span><span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> Data<span class="token punctuation">,</span> size_t Length<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">RemoteReceive</span>       <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">RemoteDisconnect</span>    <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">SetContext</span>          <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token operator">*</span> Context<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span><span class="token operator">*</span>           <span class="token function">GetContext</span>          <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">SSLRestartAgent</span>     <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">SSLIsRestartAgent</span>   <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">bool</span>            <span class="token function">SSLIsFallback</span>       <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">virtual</span> <span class="token keyword">void</span>            <span class="token function">Close</span>               <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><table><thead><tr><th>函数</th><th>说明</th></tr></thead><tbody><tr><td>LocalGetProcessId</td><td>获取本地(浏览器)的进程id</td></tr><tr><td>LocalGetAddress</td><td>获取本地(浏览器)的网络地址</td></tr><tr><td>LocalSetAutoSend</td><td>是否自动发包(本地收到包后,自动发给远程),默认为true</td></tr><tr><td>LocalSetAutoReceive</td><td>是否自动收包,默认为true,如果设置false,需要自己通过LocalReceive通知收包,不然不会有OnLocalReceive回调</td></tr><tr><td>RemoteSetAddress</td><td>设置修改远程的服务器地址,一般在OnRemotePreConnect里面设置</td></tr><tr><td>RemoteGetAddresss</td><td>参考LocalXxx</td></tr><tr><td>RemoteSetAutoSend</td><td>参考LocalXxx</td></tr><tr><td>RemoteSetAutoReceive</td><td>参考LocalXxx</td></tr><tr><td>SetContext</td><td>设置用户自己的额外数据</td></tr><tr><td>GetContext</td><td>返回设置的数据</td></tr><tr><td>SSLRestartAgent</td><td>重新启动https解析:在设置了代理的情况下,所有流量都会走代理,为了解析出代理里面的内容,可以在代理连接成功后,设置SSLRestartAgent重新发起https代理,这样就可以监控到代理后的内容。(其他任何ssl前有数据包的协议都适用)</td></tr><tr><td>SSLIsRestartAgent</td><td>判断当前是否重新解析的</td></tr><tr><td>SSLIsFallback</td><td>如果设置了ssl,但是解析后发现不是ssl的,会回退到原始数据包的状态,这里判断是否回退过。</td></tr></tbody></table>`,15),c=[p];function l(i,r){return a(),t("div",null,c)}const d=s(o,[["render",l],["__file","agent.html.vue"]]);export{d as default};