Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EasyHook未拦截任何recv呼叫_C#_Easyhook - Fatal编程技术网

C# EasyHook未拦截任何recv呼叫

C# EasyHook未拦截任何recv呼叫,c#,easyhook,C#,Easyhook,我一直在尝试使用EasyHook从Chrome和Firefox连接对“recv”的调用。然而,这是不工作的-它不会失败,并没有任何错误,但也没有数据包被捕获。我已经用“CreateFile”钩子尝试了这个示例程序,效果非常好。。。 因为几乎没有关于这方面的文档,所以我很难解决这个问题。这是我的密码: // the injected library using System; using System.Collections.Generic; using System.Linq; using Sy

我一直在尝试使用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;
        }
    }
}
//注入的库
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用简易工具;
使用System.Runtime.InteropServices;
使用系统线程;
使用System.Windows.Forms;
命名空间SocketMon
{
公共类注入:EasyHook.IEntryPoint
{
SocketMonitor接口;
LocalHook-CreateFileHook;
堆栈队列=新堆栈();
公共注入(RemoteHooking.IContext InContext,String InChannelName)
{
//连接到主机。。。
接口=
IpcConnectClient(InChannelName);
//验证连接。。。
接口Ping();
}
public void Run(RemoteHooking.IContext InContext,String InChannelName)
{
//安装挂钩。。。
尝试
{
CreateFileHook=LocalHook.Create(
LocalHook.GetProcAddress(“Ws2_32.dll”,“recv”),
新Drecv(recv_钩形),
这),;
CreateFileHook.ThreadACL.setInclusiveAll(新的Int32[]{0});
}
捕获(例外情况)
{
接口.ReportException(exterfo);
返回;
}
已安装接口(RemoteHooking.GetCurrentProcessId());
//等待主机进程终止。。。
尝试
{
while(true)
{
睡眠(500);
如果(Queue.Count>0)
{
String[]Package=null;
Show(Queue.Count.ToString());
锁(队列)
{
Package=Queue.ToArray();
Queue.Clear();
}
OnRecvData(RemoteHooking.GetCurrentProcessId(),包);
}
其他的
接口Ping();
}
}
抓住
{
//如果无法访问主机,NET远程处理将引发异常
}
}
[UnmanagedFunctionPointer(CallingConvention.StdCall,
CharSet=CharSet.Unicode,
SetLastError=true)]
代表int Drecv(
IntPtr socketHandle,
IntPtr buf,
整数计数,
int socketFlags
);
//只需使用P-Invoke实现即可获得本机API访问
//从C++(此步骤对于C++ .NET来说不是必需的)
[DllImport(“Ws2_32.dll”)]
静态外部内部记录(
IntPtr socketHandle,
IntPtr buf,
整数计数,
int socketFlags
);
公共int recv_挂钩(
IntPtr socketHandle,
IntPtr buf,
整数计数,
int socketFlags
)
{
int len=recv(socketHandle、buf、count、socketFlags);
Push(String.Format(“在套接字{1}上接收到{0}字节的数据”,socketHandle,count));
回程透镜;
}
}
}
*

//ipc接口
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
命名空间SocketMon
{
公共类SocketMonitorInterface:MarshallByRefObject
{
已安装public void(Int32 InClientPID)
{
WriteLine(“SocketMon已安装在目标{0}.\r\n”,InClientPID);
}
OnRecvData上的公共void(Int32 InClientPID,字符串[]在SocketData中)
{
for(int i=0;i

我已经尝试过将setExclusiveAll更改为setInclusiveAll,但这并没有帮助…

我意识到我的代码实际上在工作

使用p/Invoke手动调用“recv”


问题是Chrome和Firefox没有使用“recv”-当我使用SpyStudio钩住它们时,它们实际上调用了“wininet.dll”中的其他方法,而不是使用winsocks

在钩子方法中设置断点并附加到进程时会发生什么?有什么东西被截获了吗?另外,你能展示一下你的主要方法/类吗?
//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");
        }
    }
}