fiddlercore问题解决方案,fidder抓包,抓手机app

1.浏览器提示“您的连接不是私密连接”
解决办法:
1.手动安装证书,访问你监听端口,比如http://127.0.0.1:8888/
直接安装,
2.使用代码安装

    //证书管理
            X509Certificate2 oRootCert = CertMaker.GetRootCertificate();
            //创建证书
            X509Store certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
            //打开证书管理
            certStore.Open(OpenFlags.ReadWrite);
            try
            {
               // 将伪造证书加入根证书库
                certStore.Add(oRootCert);
            }
            finally
            {
               // 关闭证书库
                certStore.Close();
            }

            //指定伪造证书
            FiddlerApplication.oDefaultClientCertificate = oRootCert;

2.不是安全连接
解决方法:创建一个代理服务器

            // 我们还将创建一个HTTPS监听器,当FiddlerCore被伪装成HTTPS服务器有用
            // 而不是作为一个正常的CERN样式代理服务器。
            oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, oRootCert);
 static Proxy oSecureEndpoint;
        static string sSecureEndpointHostname = "localhost";
        static int iSecureEndpointPort = 8888;


  //设置别名
            Fiddler.FiddlerApplication.SetAppDisplayName("FiddlerCoreDemoApp");

            //启动方式
            FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default;

            //定义http代理端口
            int iPort = 8888;
            Fiddler.CONFIG.IgnoreServerCertErrors = false;
            Fiddler.CertMaker.createRootCert();
            //证书管理
            X509Certificate2 oRootCert = CertMaker.GetRootCertificate();
            //创建证书
            X509Store certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
            //打开证书管理
            certStore.Open(OpenFlags.ReadWrite);
            try
            {
               // 将伪造证书加入根证书库
                certStore.Add(oRootCert);
            }
            finally
            {
               // 关闭证书库
                certStore.Close();
            }

            //指定伪造证书
            FiddlerApplication.oDefaultClientCertificate = oRootCert;
            //忽略服务器证书错误
            CONFIG.IgnoreServerCertErrors = true;
            //信任证书
            CertMaker.trustRootCert();
            //看字面意思知道是啥,但实际起到啥作用。。。鬼才知道,官方例程里有这句,加上吧,管它呢。
            FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);
            //启动代理服务————启动参数1:捕捉https;启动参数2:允许局域网其他终端连入本代理
            //启动代理程序,开始监听http请求
            //端口,是否使用windows系统代理(如果为true,系统所有的http访问都会使用该代理)我使用的是
            Fiddler.FiddlerApplication.Startup(iPort, true, true, true);

            // 我们还将创建一个HTTPS监听器,当FiddlerCore被伪装成HTTPS服务器有用
            // 而不是作为一个正常的CERN样式代理服务器。
            oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, oRootCert);
            txtlog.AppendText("启动代理成功" + Environment.NewLine);


            List<Fiddler.Session> oAllSessions = new List<Fiddler.Session>();

            请求出错时处理
            //Fiddler.FiddlerApplication.BeforeReturningError += FiddlerApplication_BeforeReturningError;

            //在发送请求之前执行的操作
            Fiddler.FiddlerApplication.BeforeRequest += delegate (Fiddler.Session oS)
            {
                //请求的全路径
                Console.WriteLine("Before request for:\t" + oS.fullUrl);
                // 为了使反应篡改,必须使用缓冲模式
                // 被启用。这允许FiddlerCore以允许修改
                // 在BeforeResponse处理程序中的反应,而不是流
                // 响应给客户机作为响应进来。

                oS.bBufferResponse = true;
                Monitor.Enter(oAllSessions);
                oAllSessions.Add(oS);
                Monitor.Exit(oAllSessions);
                oS["X-AutoAuth"] = "(default)";

                /* 如果请求是要我们的安全的端点,我们将回显应答。
                
                注:此BeforeRequest是越来越要求我们两个主隧道代理和我们的安全的端点,
                让我们来看看它的Fiddler端口连接到(pipeClient.LocalPort)客户端,以确定是否该请求
                被发送到安全端点,或为了达到**安全端点被仅仅发送到主代理隧道(例如,一个CONNECT)。
                因此,如果你运行演示和参观的https://本地主机:7777在浏览器中,你会看到
                Session list contains...
                 
                    1 CONNECT http://localhost:7777
                    200                                         <-- CONNECT tunnel sent to the main proxy tunnel, port 8877
                    2 GET https://localhost:7777/
                    200 text/html                               <-- GET request decrypted on the main proxy tunnel, port 8877
                    3 GET https://localhost:7777/               
                    200 text/html                               <-- GET request received by the secure endpoint, port 7777
                */



                if ((oS.oRequest.pipeClient.LocalPort == iSecureEndpointPort) && (oS.hostname == sSecureEndpointHostname))
                {
                    oS.utilCreateResponseAndBypassServer();
                    oS.oResponse.headers.SetStatus(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());
                }
                //if ((oS.oRequest.pipeClient.LocalPort == 8877) && (oS.hostname == "www.baidu.com"))
                //{
                //    string url = oS.fullUrl;
                //    oS.utilCreateResponseAndBypassServer();
                //    oS.oResponse.headers.SetStatus(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());
                //}
            };

            /*
                // 下面的事件,您可以检查由Fiddler阅读每一响应缓冲区。  
             *     请注意,这不是为绝大多数应用非常有用,因为原始缓冲区几乎是无用的;它没有解压,它包括标题和正文字节数等。
                //
                // 本次仅适用于极少数的应用程序这就需要一个原始的,未经处理的字节流获取有用
                Fiddler.FiddlerApplication.OnReadResponseBuffer += new EventHandler<RawReadEventArgs>(FiddlerApplication_OnReadResponseBuffer);
            */


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

                oS.utilDecodeResponse();

                string content = oS.GetResponseBodyAsString();
                Regex rx = new Regex(@"^0{0,1}(13[4-9]|15[7-9]|15[0-2]|18[7-8])[0-9]{8}$");

                if (textBox1.Text != "")
                {
                    if (oS.fullUrl.IndexOf(textBox1.Text) > 0) {
                        txtlog.AppendText("已抓到数据" + oS.GetResponseBodyAsString() + Environment.NewLine);
                    }

                }
                else {
                    txtlog.AppendText("已抓到数据" + oS.GetResponseBodyAsString() + Environment.NewLine);

                }



                if (txtlog.Lines.Count() > 3000)
                {
                    txtlog.Text = "";
                    txtlog.AppendText("清空缓存" + Environment.NewLine);
                }


            };





  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值