使用fiddler作为https反向代理 - 发生超时

时间:2013-03-04 15:21:07

标签: c# https fiddler reverse-proxy

我正在尝试使用Fiddler.Core创建反向代理,我们可以使用它来通过http重放第三方请求。

lib非常适合http,对于https,我似乎缺少一步,因为重放响应似乎只是暂停。

以下是规范的代码:

[TestClass]
public class Verify_basic_proxy_functionality
{
    WebClient WC;
    Proxy SUT;

    [TestInitialize]
    public void Init()
    {
        SUT = new Proxy();
        SUT.InsertSession(Url:"http://proxy/ping",ResponseBody:"pong");
        var uri = SUT.Startup(9100,IsRecording: false);
        WC = new WebClient() { Proxy = new WebProxy(uri)};
    }

    [TestMethod]
    public void Ping_should_return_pong()
    {
        WC.DownloadString("http://proxy/ping").ShouldBe("pong");
    }

    [TestMethod]
    [ExpectedException(typeof(WebException))]
    public void Pang_should_return_error()
    {
        WC.DownloadString("http://proxy/pang");
    }

    [TestMethod]
    public void Http_reverse_proxy_should_work()
    {
        SUT.IsRecording = true;
        var http_url = "http://httpbin.org/ip";
        var initial_result = WC.DownloadString(http_url);
        initial_result.ShouldContain("origin");
        SUT.IsRecording = false;
        var result = WC.DownloadString(http_url);
        result.ShouldBe(initial_result);
    }

    // This one fails with a timeout... Probably need to close the connection or similar?
    [TestMethod]
    public void Https_reverse_proxy_should_work()
    {
        SUT.IsRecording = true;
        var https_url = "https://httpbin.org/ip"; 
        var initial_result = WC.DownloadString(https_url);
        initial_result.ShouldContain("origin");
        SUT.IsRecording = false;
        var result = WC.DownloadString(https_url);
        result.ShouldBe(initial_result);
    }
}

可以在此要点找到代理的代码:https://gist.github.com/ToJans/5082560

我想我可能需要为https(即编码)添加额外的步骤。当我拦截OnValidateServerCertificate并且总是返回true时,AFAIK fiddler.core忽略证书错误。

谁能告诉我这里做错了什么?

1 个答案:

答案 0 :(得分:1)

好吧,我的一位同事向我指出了我的想法中的一个缺陷;在为SSL重播时,你不应该记录/重播CONNECT !!!

MITMproxy现在正在运作.....