Capture https traffic using selenium and fiddler core

804 views
Skip to first unread message

Avinash Vootla

unread,
Feb 23, 2015, 7:58:42 AM2/23/15
to httpf...@googlegroups.com
I want to capture https traffic using selenium and fiddler core i have registered flags as below 
FiddlerCoreStartupFlags flags = FiddlerCoreStartupFlags.DecryptSSL & FiddlerCoreStartupFlags.AllowRemoteClients & FiddlerCoreStartupFlags.CaptureFTP & FiddlerCoreStartupFlags.ChainToUpstreamGateway & FiddlerCoreStartupFlags.MonitorAllConnections & FiddlerCoreStartupFlags.CaptureLocalhostTraffic;
Installed cert successfully when using BeforeRequest event getting only http traffic 

could you suggest me a solution.

Thank you 

Regards,
Avinash.

EricLaw

unread,
Feb 23, 2015, 12:17:18 PM2/23/15
to httpf...@googlegroups.com
You should use FiddlerCoreStartupFlags.Default, but that's not the problem.

My guess is that you haven't configured your client to trust the FiddlerRoot certificate.

Avinash Vootla

unread,
Feb 24, 2015, 7:52:13 AM2/24/15
to httpf...@googlegroups.com
           I have coded as below to capture https url and declared flags as above before strating fiddler proxy

            CONFIG.bCaptureCONNECT = true;
            CONFIG.IgnoreServerCertErrors = true;
            CONFIG.bMITM_HTTPS = true;            
            var cert = InstallCertificate();
          Console.WriteLine("Certificate  installed {0}", cert);
            int proxyPort = p.StartProxy(0);         
          FiddlerApplication.BeforeRequest += delegate(Session oSession)
          {
            Console.WriteLine("Request URL {0}", oSession.fullUrl);
         };
   
            OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
            proxy.HttpProxy = string.Format("127.0.0.1:{0}", proxyPort);

            FirefoxProfile profile = new FirefoxProfile();
            profile.SetProxyPreferences(proxy);
            IWebDriver driver = new FirefoxDriver(profile);
           
           
            driver.Navigate().GoToUrl(<url>);
 public static bool InstallCertificate()
        {
           
            if (!CertMaker.rootCertExists())
            {
                if (!CertMaker.createRootCert())
                    return false;
               
                if (!CertMaker.trustRootCert())
                    return false;

                X509Store certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                certStore.Open(OpenFlags.ReadWrite);
                try
                {
                    certStore.Add(CertMaker.GetRootCertificate());
                }
                finally
                {
                    certStore.Close();
                }

            }
            return true;
        }
     could you suggest me a solution 

Regards and Thank you,
Avinash.

Avinash Vootla

unread,
Feb 24, 2015, 7:55:59 AM2/24/15
to httpf...@googlegroups.com
In the above code Install Certificate return true which means Certificate installed successfully but i'm getting only http traffic not https did i miss anything here.

Code to start proxy:
FiddlerCoreStartupFlags flags = FiddlerCoreStartupFlags.DecryptSSL & FiddlerCoreStartupFlags.AllowRemoteClients & FiddlerCoreStartupFlags.CaptureFTP & FiddlerCoreStartupFlags.ChainToUpstreamGateway & FiddlerCoreStartupFlags.MonitorAllConnections & FiddlerCoreStartupFlags.CaptureLocalhostTraffic;

 FiddlerApplication.Startup(<desiredPort>, flags);

EricLaw

unread,
Feb 24, 2015, 2:23:24 PM2/24/15
to httpf...@googlegroups.com
CertMaker.TrustRootCert modifies the Windows Certificate Store.
Unlike Chrome, IE, Safari, etc, Firefox does not use the Windows Certificate Store.

Avinash Vootla

unread,
Feb 25, 2015, 4:34:24 AM2/25/15
to httpf...@googlegroups.com
Hi Eric,
          I have done what you said on above link still BeforeRequest event session has only http traffic.Certificate was installed successfully(refer above code installcertificate() return true) code running successfully opening browser with selenium requesting website capturing http traffic failing to capture https traffic.

Thank you,

Regards,
Avinash.

Avinash Vootla

unread,
Feb 25, 2015, 5:17:07 AM2/25/15
to httpf...@googlegroups.com
Hi Eric,

        I have used chrome driver 

            CONFIG.bCaptureCONNECT = true;
            CONFIG.IgnoreServerCertErrors = true;
            CONFIG.bMITM_HTTPS = true;
            FiddlerApplication.BeforeRequest += delegate(Session oSession)
            {
                Console.WriteLine("Request URL {0}", oSession.fullUrl);            
            };
            var cert = InstallCertificate();
            int proxyPort = StartProxy(0);
            OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
            proxy.HttpProxy = string.Format("127.0.0.1:{0}", proxyPort);
            ChromeOptions options = new ChromeOptions();
            options.Proxy = proxy;
            IWebDriver Driver = new ChromeDriver(@"C:\chromedriver_win32", options);
            Console.WriteLine("Certificate {0}", cert);
            Driver.Navigate().GoToUrl(<url>);
            public static bool InstallCertificate()
        {

            if (!Fiddler.CertMaker.rootCertExists())
            {
                if (!Fiddler.CertMaker.createRootCert())
                    return false;

                if (!Fiddler.CertMaker.trustRootCert())
                    return false;
                X509Store certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                certStore.Open(OpenFlags.ReadWrite);
                try
                {
                    certStore.Add(Fiddler.CertMaker.GetRootCertificate());
                }
                finally
                {
                    certStore.Close();
                }
            }

            return true;
        }



Here chrome browser opened successfully but failed to capture even http traffic.

Avinash Vootla

unread,
Feb 25, 2015, 7:28:04 AM2/25/15
to httpf...@googlegroups.com
I have registered FiddlerApplication.Log.OnLogString event with firefox selenium webdriver i'm getting this exception.

Process-determination failed. fiddler.config.path.lsof=/usr/sbin/lsof
Call returned 2.
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at Fiddler.Winsock.GetPIDFromLSOF(Int32 iPort)



EricLaw

unread,
Feb 26, 2015, 2:43:13 PM2/26/15
to httpf...@googlegroups.com
You didn't think to mention previously that you're running on Linux or Mac?

trustRootCert probably won't do anything on those platforms, as neither of them offer an API.

As to why you're getting the lsof exception: you asked this in three places, so I'll point you to the second time I answered it: http://www.telerik.com/forums/capture-https-traffic
Reply all
Reply to author
Forward
0 new messages