C#-EasyHook没有拦截任何recv调用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#-EasyHook没有拦截任何recv调用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3166字,纯文字阅读大概需要5分钟。
内容图文
![C#-EasyHook没有拦截任何recv调用](/upload/InfoBanner/zyjiaocheng/663/cd9f1ef75c2c4f38bec489ab8ecefb13.jpg)
我一直在尝试使用EasyHook从Chrome和Firefox挂接到对“ recv”的调用.但是,这不起作用-它不会因任何错误而失败,而且也不会捕获任何数据包.我已经尝试了使用’CreateFile’钩子的示例程序,并且效果很好…
由于几乎没有与此相关的文档,因此我无法解决此问题.这是我的代码:
// the injected library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EasyHook;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace SocketMon
{
public class Injection : EasyHook.IEntryPoint
{
SocketMonInterface Interface;
LocalHook CreateFileHook;
Stack<String> Queue = new Stack<String>();
public Injection(RemoteHooking.IContext InContext, String InChannelName)
{
// connect to host...
Interface =
RemoteHooking.IpcConnectClient<SocketMonInterface>(InChannelName);
// validate connection...
Interface.Ping();
}
public void Run(RemoteHooking.IContext InContext, String InChannelName)
{
// install hook...
try
{
CreateFileHook = LocalHook.Create(
LocalHook.GetProcAddress("Ws2_32.dll", "recv"),
new Drecv(recv_Hooked),
this);
CreateFileHook.ThreadACL.SetInclusiveACL(new Int32[] { 0 });
}
catch (Exception ExtInfo)
{
Interface.ReportException(ExtInfo);
return;
}
Interface.IsInstalled(RemoteHooking.GetCurrentProcessId());
// wait for host process termination...
try
{
while (true)
{
Thread.Sleep(500);
if (Queue.Count > 0)
{
String[] Package = null;
MessageBox.Show(Queue.Count.ToString());
lock (Queue)
{
Package = Queue.ToArray();
Queue.Clear();
}
Interface.OnRecvData(RemoteHooking.GetCurrentProcessId(), Package);
}
else
Interface.Ping();
}
}
catch
{
// NET Remoting will raise an exception if host is unreachable
}
}
[UnmanagedFunctionPointer(CallingConvention.StdCall,
CharSet = CharSet.Unicode,
SetLastError = true)]
delegate int Drecv(
IntPtr socketHandle,
IntPtr buf,
int count,
int socketFlags
);
// just use a P-Invoke implementation to get native API access
// from C# (this step is not necessary for C++.NET)
[DllImport("Ws2_32.dll")]
static extern int recv(
IntPtr socketHandle,
IntPtr buf,
int count,
int socketFlags
);
public int recv_Hooked(
IntPtr socketHandle,
IntPtr buf,
int count,
int socketFlags
)
{
int len = recv(socketHandle, buf, count, socketFlags);
Queue.Push(String.Format("Received {0} bytes of data on socket {1}", socketHandle, count));
return len;
}
}
}
*
//the ipc interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SocketMon
{
public class SocketMonInterface : MarshalByRefObject
{
public void IsInstalled(Int32 InClientPID)
{
Console.WriteLine("SocketMon has been installed in target {0}.\r\n", InClientPID);
}
public void OnRecvData(Int32 InClientPID, String[] InSocketData)
{
for (int i = 0; i < InSocketData.Length; i++)
{
Console.WriteLine(InSocketData[i]);
}
}
public void ReportException(Exception InInfo)
{
Console.WriteLine("The target process has reported" +
" an error:\r\n" + InInfo.ToString());
}
public void Ping()
{
Console.WriteLine("Got pinged");
}
}
}
我已经尝试将SetExclusiveACL更改为SetInclusiveACL,但这并没有帮助…
解决方法:
我意识到我的代码实际上在工作…
使用P / Invoke手动调用’recv’工作正常…
问题是Chrome和Firefox没有使用’recv’-当我使用SpyStudio钩住它们时,它们实际上在’wininet.dll’中调用了其他方法,而不是使用winsocks
内容总结
以上是互联网集市为您收集整理的C#-EasyHook没有拦截任何recv调用全部内容,希望文章能够帮你解决C#-EasyHook没有拦截任何recv调用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。