首页 > 编程语言 >C#用FiddlerCore抓包HTTP和HTTPS

C#用FiddlerCore抓包HTTP和HTTPS

时间:2022-10-29 11:35:23浏览次数:48  
标签:HTTP C# void System private FiddlerCore FiddlerApplication using oSession


FiddlerCore是收费软件,提供了Fiddler的抓包API,能抓取HTTP和HTTPS的网络请求。
官网:https://www.telerik.com/fiddlercore
安装FiddlerCore依赖引用有两种方式:
1、通过Telerik NuGet Server下载。这种方式需要注册账号,一般也会下载失败。
2、通过VS引用FiddlerCore.dll。

实现界面:

C#用FiddlerCore抓包HTTP和HTTPS_https

实现代码:

using Fiddler;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

static string tmp = "-------------------------------------";

private void btn_start_Click(object sender, EventArgs e)
{
startFiddler();
}

// 启动捕获
public void startFiddler()
{
if (!FiddlerApplication.IsStarted())
{
FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest;
FiddlerApplication.Startup(8888, true, true, true);
}
else
{
appendtext("fiddler is running...");
}
}


// 请求前回调
private void FiddlerApplication_BeforeRequest(Session oSession)
{
if (oSession.RequestMethod == "POST" || oSession.RequestMethod == "GET")
{

string url = oSession.fullUrl;
string body = oSession.GetRequestBodyAsString();
string header = oSession.RequestHeaders.ToString();
appendtext(url);
appendtext(header);
appendtext(body);

}
}

// 会话结束后回调
private void FiddlerApplication_AfterSessionComplete(Session oSession)
{
if (oSession.RequestMethod == "POST" || oSession.RequestMethod == "GET")
{
string body = oSession.GetResponseBodyAsString();
appendtext(body);
appendtext(tmp);
}

}

// 停止捕获
public void stopFiddler()
{
if (FiddlerApplication.IsStarted())
{
FiddlerApplication.Shutdown();

}
}

// 安装证书
public void install()
{
if (!CertMaker.rootCertExists())
{
CertMaker.createRootCert();
CertMaker.trustRootCert();
}
}

// 证书移除
public void remove()
{
if (CertMaker.rootCertExists())
{
CertMaker.removeFiddlerGeneratedCerts();
}
}

public void appendtext(string value)
{
if (InvokeRequired)
{
this.Invoke(new Action(() =>
{
richTextBox1.AppendText(value + "\r\n");
}));
}
}

private void btn_stop_Click(object sender, EventArgs e)
{
stopFiddler();
}

private void btn_install_Click(object sender, EventArgs e)
{
install();
}

private void btn_remove_Click(object sender, EventArgs e)
{
remove();
}

// 关闭窗口
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{



stopFiddler();
if (FiddlerApplication.oProxy != null)
{
if (FiddlerApplication.oProxy.IsAttached)
FiddlerApplication.oProxy.Detach();
}
}

private void Form1_Load(object sender, EventArgs e)
{
this.splitContainer1.SplitterDistance = this.Height / 7;
}
}
}

参考: https://docs.telerik.com/fiddlercore/getting-started/telerik-nuget-server


标签:HTTP,C#,void,System,private,FiddlerCore,FiddlerApplication,using,oSession
From: https://blog.51cto.com/lilongsy/5805840

相关文章

  • 【P4314】CPU监控(线段树维护区间历史信息)
    线段树维护区间历史信息的模板题。看了cmd的博客。大概思路是:由于我们需要求出历史信息,所以暴力的做法是在做区间修改时的tag我们先不合并,而是按时间顺序存一个tag......
  • C#实现MD5加密(32位md5加密和16位md5加密)
    MD5是经典HASH算法,这里用C#实现一边:usingSystem;usingSystem.Security.Cryptography;usingSystem.Text;namespaceConsoleApp1{classProgram{//32位md......
  • C#的LINQ select查询、where过滤、group分组、join关联
    语言集成查询(LanguageIntegratedQuery)是一系列直接将查询功能集成到C#语言的技术统称,用于在所有基于.NET平台的变成语言中更加直接地声明跨越、过滤和投射操作的一......
  • Java通过jdbc连接MySql数据库进行操作
    下载​​MySql​​驱动包​​https://dev.mysql.com/downloads/connector/j/​​解压,把文件夹中的​​jar​​包拷贝到项目文件中新建一个java类进行连接​​db1​​是我......
  • Scanner类
    1、需要传参:System.in2、scanner.next()接收字符串类型3、scanner.nextInt()接收整型packagecom.ke.demo1;importjava.util.Scanner;publicclassdemo1{......
  • [Vue warn]: Method “components“ has type “object“ in the component definitio
    [Vuewarn]:Method“components”hastype“object”inthecomponentdefinition.Didyoureferencethe报错如下:仔细检查代码发现:components写到methods方法里面去......
  • 云小课|MRS基础原理之CarbonData入门
    阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说)、深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云。更多精彩内容请单击......
  • 贝叶斯推理三种方法:MCMC 、HMC和SBI
    对许多人来说,贝叶斯统计仍然有些陌生。因为贝叶斯统计中会有一些主观的先验,在没有测试数据的支持下了解他的理论还是有一些困难的。本文整理的是作者最近在普林斯顿的一个......
  • Mockito使用方法(Kotlin)
    一、为什么要使用Mockito1.实际案例1.1遇到的问题对于经常维护的项目,经常遇到一个实际问题:需求不停改变,导致架构经常需要修改某些概念的定义。对于某些十分基础又十分......
  • C/C++ struct结构体的三种使用方法
    #include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>#include<conio.h>usingnamespacestd;structhero{charname[16];ch......