EasyHook recv不会“挂钩”所有数据包
我设法编写了一个挂钩recv函数的半工作EasyHook示例。 我写了一个表单,添加了一个WebBrowser组件,并启动了该应用程序。 问题是,我得到HTTP数据包,但如果有一个套接字,似乎recv停止“挂钩”。 问题是,通过外部应用程序,Spystudio,我可以让他们挂钩recv。 那么,我错过了什么?
using System; using System.Collections.Generic; using System.Data; using System.Runtime.InteropServices; using System.Threading; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.IO; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels.Ipc; using EasyHook; namespace flashing { public partial class Form1 : Form,EasyHook.IEntryPoint { public LocalHook CreateRecvHook; public Form1() { InitializeComponent(); } [DllImport("Ws2_32.dll")] static extern int recv( IntPtr socketHandle, IntPtr buf, int count, int socketFlags ); [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)] delegate int Drecv( IntPtr socketHandle, IntPtr buf, int count, int socketFlags ); static int recv_Hooked( IntPtr socketHandle, IntPtr buf, int count, int socketFlags) { int bytesCount = recv(socketHandle, buf, count, socketFlags); if (bytesCount > 0) { byte[] newBuffer = new byte[bytesCount]; Marshal.Copy(buf, newBuffer, 0, bytesCount); string s = System.Text.ASCIIEncoding.ASCII.GetString(newBuffer); TextWriter tw = new StreamWriter("log.txt"); tw.Write(s); tw.Close(); Debug.WriteLine("Hooked:>" + s); } return bytesCount; } private void bottonHook_Click(object sender, EventArgs e) { try { CreateRecvHook = LocalHook.Create( LocalHook.GetProcAddress("Ws2_32.dll", "recv"), new Drecv(recv_Hooked), this); CreateRecvHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 }); } catch (Exception ExtInfo) { Debug.WriteLine("Error creating the Hook"); return; } RemoteHooking.WakeUpProcess(); } private void buttonLoader_Click(object sender, EventArgs e) { axShockwaveFlash1.LoadMovie(0, "test.swf"); } } }
编辑 :我对recv毫不怀疑,这是apimonitor告诉我的:
# TID Module API Return Error 5 2696 Flash10l.ocx recv ( 1992, 0x07080000, 65536, 0 ) 1
那么,有人可以帮助我吗?
问题解决了。 造成麻烦的那条线是
CreateRecvHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
我改成了
CreateRecvHook.ThreadACL.SetInclusiveACL(new Int32[] { 0 });
现在一切正常。 谢谢大家 :)
套接字使用了许多不同的function。 也许该插件没有使用名为recv
的函数。 在我的脑海中,我可以想到recvfrom
, recvmsg
, WSARecv
, WSARecvFrom
, WSARecvMsg
, ReadFile
, ReadFileEx
。
然后,插件可能正在执行具有重叠I / O的请求(可能由完成例程或完成端口复杂化),在这种情况下,数据不会在例如ReadFile
函数调用期间存储,而是在稍后的某个时间存储。 挂钩那些将更具挑战性。
我在c#中编写了一个使用sharppcs转储http的工具。 它使用winpcap驱动程序。 我觉得tan apihooks更可靠。
HTTPSaver(带源代码)
SharpPcap
Winpcap的