fiddler - 在检查器中通过 c# 即时解码自定义加密主体

fiddler - decode custom encrypted body in inspector by c# on the fly

内容是用自定义加密器加密的。 fiddler 捕获的内容主体是纯文本的 base64 编码字符串

应用流量:

要求:

base64Encode(customEncryptFromStringTobytes(jsonString) ) -> application -> http server

回复:

customDecryptFrombytesToString(base64Decode(jsonString) ) <- application <- http server

我在 c# 中有 encrypt/decrypt class: string EncryptToBase64(string plainText); string DecryptFromBase64(string plainText);

我构建了一个 exe 来进行转换,我想知道如何让 fiddler 动态解码 request/respose body

我希望 Fiddler 在 inspector 中显示解密内容,并在每次 [Reissue and Edit(E)] 请求时再次加密。

我找到了一些接近但不知道如何调用 exe 进行解码的东西。 http://docs.telerik.com/fiddler/KnowledgeBase/FiddlerScript/ModifyRequestOrResponse

更新: 我已经为 Fiddler 实现了自定义检查器。请参阅下面的答案。

添加一个虚拟对象 header

Fiddler-Encoding: base64

并使用 base64 对 body 进行编码(如果它包含任何二进制数据)。 Fiddler 将在将数据传输到服务器之前对其进行解码。

取自http://www.fiddlerbook.com/fiddler/help/composer.asp

我为自定义检查器创建了一个扩展

完整示例https://github.com/chouex/FiddlerExtensionExample

您将构建一个 dll 并将文件复制到 fiddler 中的 Inspectors 和 Scripts 文件夹。重新启动 fiddler 将加载扩展。

注意: 我使用pre/post-build脚本复制dll并在vs项目中重启fiddler。

自定义检查员: 这个例子只是美化了 json 的主体。

public class ResponseInspector : Inspector2, IResponseInspector2
{
    TextBox myControl;
    private byte[] m_entityBody;
    private bool m_bDirty;

private bool m_bReadOnly;

public bool bReadOnly
{
    get { return m_bReadOnly; }
    set
    {
        m_bReadOnly = value;
        // TODO: You probably also want to turn your visible control CONFIG.colorDisabledEdit (false) or WHITE (true) here depending on the value being passed in.   
    }
}

public void Clear()
{
    m_entityBody = null;
    m_bDirty = false;
    myControl.Text = "";
}

public ResponseInspector()
{
    // TODO: Add constructor logic here
}

public HTTPResponseHeaders headers
{
    get { return null; // Return null if your control doesn't allow header editing.
    }
    set { }
}

public byte[] body
{
    get { return m_entityBody; }
    set
    {
        // Here's where the action is.  It's time to update the visible display of the text
        m_entityBody = value;

        if (null != m_entityBody)
        {
            var text = System.Text.Encoding.UTF8.GetString(m_entityBody);

                if (!String.IsNullOrEmpty(text) && text.StartsWith("{"))
                {
                    text = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(text), Formatting.Indented);
                }

            myControl.Text = text;
            // TODO: Use correct encoding based on content header.
        }
        else
        {
            myControl.Text = "";
        }

        m_bDirty = false;
        // Note: Be sure to have an OnTextChanged handler for the textbox which sets m_bDirty to true!
    }
}

public bool bDirty
{
    get { return m_bDirty; }
}

public override int GetOrder()
{
    return 0;
}

public override void AddToTab(System.Windows.Forms.TabPage o)
{
    myControl = new TextBox(); // Essentially the TextView class is simply a usercontrol containing a textbox.
    myControl.Height = o.Height;
    myControl.Multiline = true;
    myControl.ScrollBars = ScrollBars.Vertical;
    o.Text = "TextViewExample";
    o.Controls.Add(myControl);
    o.Controls[0].Dock = DockStyle.Fill;
}
}

for Traffic Tamper(没有提及但我认为这很有用):

在 IAutoTamper2 中实施 AutoTamperResponseBefore()

此示例仅替换每个请求正文中从 "xt" 到 "c1" 的任何文本