Fiddler修改请求时SSL收到的记录超过了最大允许长度

7

我正在尝试使用FiddlerCore实现一个系统内SSL服务器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fiddlerCoreTest
{
    using System.IO;
    using System.Threading;
    using Fiddler;

    class Program
    {
        static Proxy oSecureEndpoint;
        static string sSecureEndpointHostname = "localhost";
        static int iSecureEndpointPort = 7777;

        static void Main(string[] args)
        {
            //var tt = Fiddler.CertMaker.GetRootCertificate().GetRawCertData();
            //File.WriteAllBytes("root.crt",tt);

            Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS)
            {
                oS.bBufferResponse = false;               

                if ((oS.hostname == sSecureEndpointHostname)&&oS.port==7777)
                {
                    oS.utilCreateResponseAndBypassServer();
                    oS.oResponse.headers.HTTPResponseStatus = "200 Ok";
                    oS.oResponse["Content-Type"] = "text/html; charset=UTF-8";
                    oS.oResponse["Cache-Control"] = "private, max-age=0";
                    oS.utilSetResponseBody("<html><body>Request for httpS://" + sSecureEndpointHostname + ":" + iSecureEndpointPort.ToString() + " received. Your request was:<br /><plaintext>" + oS.oRequest.headers.ToString());
                }
            };

            FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default;
            oFCSF = (oFCSF & ~FiddlerCoreStartupFlags.RegisterAsSystemProxy);

            Fiddler.FiddlerApplication.Startup(8877, oFCSF);

            oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, sSecureEndpointHostname);
            if (null != oSecureEndpoint)
            {
                FiddlerApplication.Log.LogFormat("Created secure end point listening on port {0}, using a HTTPS certificate for '{1}'", iSecureEndpointPort, sSecureEndpointHostname);
            }

            Console.WriteLine("Press any key to exit");

            Console.ReadKey();
        }
    }
}

在Firefox中,GET http://localhost:7777/ 可以正常工作,但当我 GET https://localhost:7777/ 时,Firefox报告以下错误:SSL received a record that exceeded the maximum permissible length。为什么会出现这种情况,我该如何解决?更新:仅在我使用fiddler作为代理与Firefox配合使用时才会出现此问题。当我删除fiddler代理时,可以访问https://localhost:7777/,但我也希望能够通过代理访问https://localhost:7777/

让我们回到一点。当Fiddler没有在Firefox中设置为代理时,您能否访问https://localhost:7777?另外,您使用的Firefox确切版本是什么?utilCreateResponseAndBypassServer上的断点是否被触发? - EricLaw
我正在使用ff17.0.1。当我没有代理访问https://localhost:7777时,它可以正常工作。 oS.utilCreateResponseAndBypassServer();被触发,该函数将响应返回给Fiddler核心。 - Arsen Zahray
2个回答

1
HTTPS流量是加密的,作为Web调试代理的Fiddler无法解密/分析通过Fiddler发送的数据包数据。它使用MITM攻击来解密通过Fiddler发送的SSL流量,请参见此处:http://www.fiddler2.com/fiddler/help/httpsdecryption.asp 因此,您必须在Fiddler中启用SSL选项,然后重新检查它。如果不起作用,请尝试向Fiddler提供手动MITM证书。

Fiddler可以解密SSL流量,但是当我尝试修改它时,会出现这个错误。 - Arsen Zahray
Fiddler应该允许你修改数据包和内部信息,如果你愿意的话。它应该有一个可以配置的Fiddler注入器属性。 - Greg
根据我的经验,它可以很好地修改HTTP请求,但在HTTPS请求时会出现错误。 - Arsen Zahray
你能在Fiddler和Web服务器中使用同一张证书吗? - Vahid Farahmand

1
这种情况的问题在于你对这个流量进行了两次处理:
首先,浏览器向端口8888发送CONNECT请求,请求内容为:“请给我一个到端口7777的TCP/IP隧道”,然后Fiddler回复:“好的,我们会做到”,客户端通过该隧道向端口7777发送HTTPS请求。
问题在于,你篡改了CONNECT响应并返回HTML,而不是允许从端口7777流过的HTTPS握手。
最简单的解决方法是将你的BeforeRequest代码更改为以下内容:
if ( (oS.hostname == sSecureEndpointHostname) && (oS.port==7777)
    && !oS.HTTPMethodIs("CONNECT")) {

完成这些步骤后,您的CONNECT隧道将不再被篡改,HTTPS握手将成功。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接