简体   繁体   English

如何捕获来自某些进程的所有 HTTP 请求?

[英]How to capture all HTTP requests from certain processes?

I've searched for this, I came to know WinPCap , but I still didn't get the answer I needed.我已经搜索过这个,我开始知道WinPCap ,但我仍然没有得到我需要的答案。 WinPCap can monitor packets, and seems not to give a track to processes (I don't know much about it). WinPCap可以监视数据包,并且似乎不会跟踪进程(我对此知之甚少)。

I want my application to listen to every HTTP request made from certain processes (usually the ones from browsers which I will define later), and modify them if necessary.我希望我的应用程序侦听某些进程(通常是我稍后将定义的浏览器发出的那些)发出的每个 HTTP 请求,并在必要时修改它们。

My application is originally written in Delphi , but any help in C++ would also be cool.我的应用程序最初是用Delphi编写的,但在C++ 中的任何帮助也很酷。 Can anyone help me with this?谁能帮我这个?

Edit 1 : Of course I don't expect you to give me an answer according to winPcap necessarily!编辑1 :当然我不希望你一定根据winPcap给我一个答案!

WinPCap allows you to access the source and destination IP/Port pairs for each captured packet. WinPCap 允许您访问每个捕获的数据包的源和目标 IP/端口对。 You can iterate the OS's TCP tables (on Windows, you can use GetTcpTable2() and GetTcp6Table2() ) looking for those pairs, and when you find a match then you will know the process ID that owns that connection.您可以迭代操作系统的 TCP 表(在 Windows 上,您可以使用GetTcpTable2()GetTcp6Table2() )查找这些对,当您找到匹配项时,您将知道拥有该连接的进程 ID。 From that ID, you can then extract further information about that process from the OS (filename, etc).然后,您可以从该 ID 中提取有关该进程的更多信息(文件名等)。

There are a number of ideas I can think of, depending on how low-level you need to get and other parameters of your requirements我可以想到很多想法,具体取决于您需要获得的低级别以及您要求的其他参数

  • Set up an HTTP proxy of some kind.设置某种类型的 HTTP 代理。 This could be something you write yourself and configure the browser to use.这可能是您自己编写并配置要使用的浏览器的内容。 Or it could be something like Fiddler - I'm not sure if Fiddler allows you to plug in your own functionality...if not and if it's open source, then you can do whatever you like.或者它可能是类似 Fiddler 的东西——我不确定 Fiddler 是否允许你插入你自己的功能......如果不是,如果它是开源的,那么你可以做任何你喜欢的事情。

  • Look into existing browser plug-in mechanisms.查看现有的浏览器插件机制。 For example for IE there are BHOs (Browser Helper Objects).例如,对于 IE,有 BHO(浏览器帮助对象)。 TBH I'm not sure what exactly the various plug-in mechanisms allow. TBH 我不确定各种插件机制到底允许什么。 If you get native code executing in the browser, maybe you can hook arbitrary APIs (see Detours below)如果您在浏览器中执行本机代码,也许您可​​以挂钩任意 API(请参阅下面的绕道)

  • Use the MS user-level hooking mechanism to inject code (a .dll) into the target processes.使用 MS 用户级挂钩机制将代码(.dll)注入目标进程。 You can configure the hook to only load into processes with a certain name (eg iexplore.exe) and maybe other attributes as well.您可以将钩子配置为仅加载到具有特定名称(例如 iexplore.exe)和其他属性的进程中。 Worst-case, you can hook all processes and then in your DllLoad bail out if the process is not one you want to hook.最坏的情况是,您可以挂钩所有进程,然后在您的 DllLoad 中退出,如果该进程不是您想要挂钩的进程。 In your hook's DllLoad, use an entry-point hooking mechanism like Detours to hook a set of network APIs with your own functions.在你的钩子的 DllLoad 中,使用像Detours这样的入口点钩子机制,用你自己的函数来钩住一组网络 API。 Then whenever the process calls those network APIs it will be the function in your DLL that is called.然后,每当进程调用这些网络 API 时,就会调用 DLL 中的函数。 It can do whatever it wants (eg modify the data being sent) and then call through to the real method.它可以做任何它想做的事情(例如修改正在发送的数据),然后调用真正的方法。 For example, IE uses WinHTTP (I think) which uses wininet which uses winsock.例如,IE 使用 WinHTTP(我认为),它使用使用 winsock 的 wininet。 I have done this (not for networking but other APIs) many times and the mechanism itself is straightforward.我已经多次这样做了(不是为了网络,而是为了其他 API),而且机制本身很简单。

  • Write a network driver of some kind to filter all traffic.编写某种网络驱动程序来过滤所有流量。 Without thinking through the details right now, you should be able to figure out what process the traffic is for even from kernel mode.现在不考虑细节,即使从内核模式,您也应该能够弄清楚流量是用于哪个进程的。 I can't remember exactly but I think Window's (which is to say, NT's) network stack has user-mode drivers as well.我记不清了,但我认为 Window 的(也就是说,NT 的)网络堆栈也有用户模式驱动程序。

Lots of software like VPNs have to do what you are talking about.很多像 VPN 这样的软件必须做你所说的。 It's definitely possible, including per-process filtering.这绝对是可能的,包括按进程过滤。 One thing to always keep in mind, if you have control of the OS you want to do this on (Administrator rights), you can do anything you want.要始终记住的一件事是,如果您可以控制要执行此操作的操作系统(管理员权限),则您可以执行任何操作。 Unlike certain mobile OSes, in desktop OSes you own the OS and the hardware and don't have to beg permission to do what you want with your own property.与某些移动操作系统不同,在桌面操作系统中,您拥有操作系统和硬件,不必请求许可就可以用自己的财产做您想做的事。 It's only a matter of how hard it is and how long it will take...这只是难度和需要多长时间的问题......

Try SnoopSpy3 application.尝试 SnoopSpy3 应用程序。 http://www.snoopspy.com/778 I hope it will help you. http://www.snoopspy.com/778希望对你有所帮助。

In Windows I've used Sysinternals ProcMon to achieve this filtering by the PID and then Tools -> Network Summary在 Windows 中,我使用 Sysinternals ProcMon 通过 PID 和工具 -> 网络摘要来实现此过滤

https://docs.microsoft.com/en-us/sysinternals/downloads/procmon https://docs.microsoft.com/en-us/sysinternals/downloads/procmon

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM