简体   繁体   中英

c# FiddlerCore AutoResponder Tunnel Connection Failed

So im trying to get basically the same functionality as the "AutoResponder" inside the Fiddler app.

also i need this to work offline.

the website im trying to autorespond for it HTTP(S) i put in code to ask the user to Trust the Root Certificate which i have included below incase its somehow relevant.

            if (Fiddler.CertMaker.rootCertExists())
        {
            if (!Fiddler.CertMaker.rootCertIsTrusted())
            {
                MessageBox.Show(this, "You need to approve the Fiddler Root CA.", "First Time?");
                Fiddler.CertMaker.trustRootCert();
            }

        }
        else
        {
            Fiddler.CertMaker.createRootCert();
            if (!Fiddler.CertMaker.rootCertIsTrusted())
            {
                MessageBox.Show(this, "You need to approve the Fiddler Root CA.", "First Time?");
                Fiddler.CertMaker.trustRootCert();

            }
        }

        if (!Fiddler.CertMaker.rootCertIsTrusted())
        {
            MessageBox.Show(this, "Fiddler Root CA not Trusted.", "Error");
            this.Close();
        }

As for the autoresponder (and what im pretty sure is causing the problem)

 FiddlerApplication.Startup(8080, true, true, true);



        FiddlerApplication.BeforeRequest += delegate (Session session)
        {
            if (session.HTTPMethodIs("CONNECT")) { session.oFlags["X-ReplyWithTunnel"] = "Fake for HTTPS Tunnel"; return; }
            if (session.uriContains("https://google.com"))
            {
                session.bBufferResponse = true;
            }
        };

        FiddlerApplication.BeforeResponse += delegate (Session session)
        {
            session.utilDecodeResponse();
            session.LoadResponseFromFile("Google.txt");
        };

However after running this code i cannot access any HTTPS websites and receive the error "ERR_TUNNEL_CONNECTION_FAILED" even on the website im trying to AutoRespond to.

I mannaged to fix it

            Fiddler.FiddlerApplication.BeforeRequest += new SessionStateHandler(FiddlerApplication_BeforeRequest);
                FiddlerApplication.Startup(8080 , true,true);

-

        private void FiddlerApplication_BeforeRequest(Session oSession)
    {
        FiddlerApplication.BeforeRequest += delegate (Session session)
        {

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

                if (!oS.uriContains("google.com") && oSession.HTTPMethodIs("CONNECT")) { oSession.oFlags["X-ReplyWithTunnel"] = "Connect for real.."; }

                if (oS.uriContains("google.com") && oS.HTTPMethodIs("CONNECT")) { oS["x-replywithtunnel"] = "Fake tunnel..."; }
                if (oS.uriContains("https://google.com/"))
                {
                    oS.oFlags["x-replywithfile"] = AppDomain.CurrentDomain.BaseDirectory + "google.txt";
                }


                }
            };
        };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM