2013-01-05 54 views
7

我試圖實現使用FiddlerCore一個在系統SSL服務器修改請求時超過了最大允許長度的記錄: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/工作正常,但是當我得到https://localhost:7777/,以下錯誤Firefox的報道:

SSL received a record that exceeded the maximum permissible length

爲什麼我得到這個,我怎麼能解決這個問題?

UPDATE 這只是發生在我使用的是與Firefox代理小提琴手。當我刪除小提琴手代理時,我可以訪問https://localhost:7777/。但是,我還希望能夠通過代理訪問https://localhost:7777/

+0

讓我們稍微備份一下。當Fiddler *在Firefox中未被設置爲代理時,您可以訪問https:// localhost:7777嗎?另外,您使用的Firefox的確切版本是什麼? utilCreateResponseAndBypassServer上的斷點是否受到影響? – EricLaw

+0

我正在使用ff17.0.1。當我訪問沒有代理的「https:// localhost:7777」時,它可以工作。 'oS.utilCreateResponseAndBypassServer();'被命中,並且該函數返回對fiddler核心的響應。 –

回答

1

在這種情況下的問題是,你正在處理此業務的兩倍:

首先,瀏覽器發送一個連接到端口8888說:「請給我一個TCP/IP隧道口7777」,然後在Fiddler說「好吧,我們會這樣做」,客戶端通過該隧道向端口7777發送HTTPS請求。

這裏的問題在於,您正在修改CONNECT響應並返回HTML,而不是允許HTTPS握手從港口7777流過。

來解決,這將是改變你的BeforeRequest代碼以下最簡單的方法:

if ((oS.hostname == sSecureEndpointHostname) && (oS.port==7777) 
    && !oS.HTTPMethodIs("CONNECT")) { 

完成這一步之後,你的連接隧道將不再獲得錯位和HTTPS握手會成功。

1

由於Web調試器代理無法解密/分析通過fiddler發送的數據包數據,因此HTTPS流量被加密和提琴手。它採用了MITM攻擊解密通過提琴手發送SSL流量,在這裏看到: http://www.fiddler2.com/fiddler/help/httpsdecryption.asp

所以,你必須啓用SSL小提琴手選項,然後重新檢查。如果它不起作用,請嘗試向小提琴手提供手動MITM證書。

+0

fiddler解密ssl流量正常。但當我試圖修改它,我得到這個錯誤 –

+0

提琴手應該允許你修改數據包和內部信息;如果你希望。它應該有你可以配置的Fiddler Injector屬性。 – Greg

+0

好吧,根據我的經驗,它可以讓我修改http請求就好,並且在https請求上失敗,出現此錯誤 –