挂钩闪光应用

发布于 2024-10-09 02:30:58 字数 247 浏览 6 评论 0原文

如果我在我的 C# 应用程序中加载一个 flash 应用程序 A,该应用程序打开与服务器 B 的套接字,是否可以设置本地挂钩,以便我可以读取 A 和服务器 B 之间交换的数据包?

  • 如果需要,我可以获取 flash 应用程序源代码,但我不是编写它们的人,
  • 我是 C# 新手(说实话,我仍然想知道为 Windows 编写此类应用程序的最佳语言是什么)并且挂钩,所以任何例子都会非常感激:)
  • 我正在客户端工作

if I load in my C# application a flash application A that opens a socket with a server B, is it possible to setup a local hook so that i can read the packets exchanged between A and the server B?

  • I may obtain the flash application sources if needed, but I'm not the one who wrote them
  • I'm new to C# ( to be honest, I'm still wondering what's the best language to write this kind of application for windows ) and to hooking, so any example would be really appreciated :)
  • I'm working client side

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

む无字情书 2024-10-16 02:30:58

是的,你可以。
您应该使用 EasyHook 库来挂钩来自 C# 的本机套接字 API 调用。
并通过在连接< /a>, 发送 和 recv 您可以在基于 Windows 的应用程序中挂钩任何流量的功能。

这是一个示例:

private IntPtr _socketsLib;
private LocalHook _createConnectHook;
private LocalHook _createRecvHook;
private LocalHook _createSendHook;

_socketsLib = NativeAPI.LoadLibrary("Ws2_32.dll");
_createConnectHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "connect"), new NativeSocketMethod.DConnect(connect_Hooked), this);
_createRecvHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "recv"),
                                           new NativeSocketMethod.Drecv(recv_Hooked), this);

_createSendHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "send"),
                              new NativeSocketMethod.Dsend(send_Hooked), this);
_createConnectHook.ThreadACL.SetExclusiveACL(new int[1]);
_createRecvHook.ThreadACL.SetExclusiveACL(new int[1]);
_createSendHook.ThreadACL.SetExclusiveACL(new int[1]);

private static int connect_Hooked(IntPtr socketHandle, ref NativeSocketMethod.sockaddr name, ref int namelen)
    {
        // TODO: do something with data here
        return NativeSocketMethod.connect(socketHandle, ref name, ref namelen);
    }

private static int recv_Hooked(IntPtr socketHandle, IntPtr buf, int count, int socketFlags)
    {
        // TODO: do something with data here
        return NativeSocketMethod.recv(socketHandle, buf, count, socketFlags);
    }

private static int send_Hooked(IntPtr socketHandle, IntPtr buf, int count, int socketFlags)
    {
        // TODO: do something with data here
        return NativeSocketMethod.send(socketHandle, buf, count, socketFlags);
    }

和 NativeSocketMethod.cs

public static class NativeSocketMethod
{
    [DllImport("Ws2_32.dll")]
    public static extern int connect(IntPtr socketHandle, ref sockaddr Address, ref int Addresslen);
    [DllImport("Ws2_32.dll")]
    public static extern int getpeername(IntPtr s, ref sockaddr Address, ref int namelen);
    [DllImport("ws2_32.dll")]
    public static extern IntPtr inet_ntoa(in_addr a);
    [DllImport("ws2_32.dll")]
    public static extern ushort ntohs(ushort netshort);
    [DllImport("Ws2_32.dll")]
    public static extern int recv(IntPtr socketHandle, IntPtr buf, int Buffercount, int socketFlags);
    [DllImport("Ws2_32.dll")]
    public static extern int send(IntPtr socketHandle, IntPtr buf, int count, int socketFlags);

    public enum AddressFamily
    {
        AppleTalk = 0x11,
        BlueTooth = 0x20,
        InterNetworkv4 = 2,
        InterNetworkv6 = 0x17,
        Ipx = 4,
        Irda = 0x1a,
        NetBios = 0x11,
        Unknown = 0
    }

    [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true)]
    public delegate int DConnect(IntPtr socketHandle, ref NativeSocketMethod.sockaddr Address, ref int Addresslen);

    [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true)]
    public delegate int Drecv(IntPtr socketHandle, IntPtr buf, int Buffercount, int socketFlags);

    [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true)]
    public delegate int Dsend(IntPtr socketHandle, IntPtr buf, int count, int socketFlags);

    [StructLayout(LayoutKind.Sequential)]
    public struct in_addr
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
        public byte[] sin_addr;
    }

    public enum ProtocolType
    {
        BlueTooth = 3,
        ReliableMulticast = 0x71,
        Tcp = 6,
        Udp = 0x11
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct sockaddr
    {
        public short sin_family;
        public ushort sin_port;
        public NativeSocketMethod.in_addr sin_addr;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
        public byte[] sin_zero;
    }

    public enum SocketType
    {
        Unknown,
        Stream,
        DGram,
        Raw,
        Rdm,
        SeqPacket
    }
}

Yes you can.
You should use EasyHook library to hook native socket API calls from C#.
And by placing hooks on connect, send and recv functions you can hook any traffic in Windows based application.

Here's an example:

private IntPtr _socketsLib;
private LocalHook _createConnectHook;
private LocalHook _createRecvHook;
private LocalHook _createSendHook;

_socketsLib = NativeAPI.LoadLibrary("Ws2_32.dll");
_createConnectHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "connect"), new NativeSocketMethod.DConnect(connect_Hooked), this);
_createRecvHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "recv"),
                                           new NativeSocketMethod.Drecv(recv_Hooked), this);

_createSendHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "send"),
                              new NativeSocketMethod.Dsend(send_Hooked), this);
_createConnectHook.ThreadACL.SetExclusiveACL(new int[1]);
_createRecvHook.ThreadACL.SetExclusiveACL(new int[1]);
_createSendHook.ThreadACL.SetExclusiveACL(new int[1]);

private static int connect_Hooked(IntPtr socketHandle, ref NativeSocketMethod.sockaddr name, ref int namelen)
    {
        // TODO: do something with data here
        return NativeSocketMethod.connect(socketHandle, ref name, ref namelen);
    }

private static int recv_Hooked(IntPtr socketHandle, IntPtr buf, int count, int socketFlags)
    {
        // TODO: do something with data here
        return NativeSocketMethod.recv(socketHandle, buf, count, socketFlags);
    }

private static int send_Hooked(IntPtr socketHandle, IntPtr buf, int count, int socketFlags)
    {
        // TODO: do something with data here
        return NativeSocketMethod.send(socketHandle, buf, count, socketFlags);
    }

And NativeSocketMethod.cs

public static class NativeSocketMethod
{
    [DllImport("Ws2_32.dll")]
    public static extern int connect(IntPtr socketHandle, ref sockaddr Address, ref int Addresslen);
    [DllImport("Ws2_32.dll")]
    public static extern int getpeername(IntPtr s, ref sockaddr Address, ref int namelen);
    [DllImport("ws2_32.dll")]
    public static extern IntPtr inet_ntoa(in_addr a);
    [DllImport("ws2_32.dll")]
    public static extern ushort ntohs(ushort netshort);
    [DllImport("Ws2_32.dll")]
    public static extern int recv(IntPtr socketHandle, IntPtr buf, int Buffercount, int socketFlags);
    [DllImport("Ws2_32.dll")]
    public static extern int send(IntPtr socketHandle, IntPtr buf, int count, int socketFlags);

    public enum AddressFamily
    {
        AppleTalk = 0x11,
        BlueTooth = 0x20,
        InterNetworkv4 = 2,
        InterNetworkv6 = 0x17,
        Ipx = 4,
        Irda = 0x1a,
        NetBios = 0x11,
        Unknown = 0
    }

    [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true)]
    public delegate int DConnect(IntPtr socketHandle, ref NativeSocketMethod.sockaddr Address, ref int Addresslen);

    [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true)]
    public delegate int Drecv(IntPtr socketHandle, IntPtr buf, int Buffercount, int socketFlags);

    [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true)]
    public delegate int Dsend(IntPtr socketHandle, IntPtr buf, int count, int socketFlags);

    [StructLayout(LayoutKind.Sequential)]
    public struct in_addr
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
        public byte[] sin_addr;
    }

    public enum ProtocolType
    {
        BlueTooth = 3,
        ReliableMulticast = 0x71,
        Tcp = 6,
        Udp = 0x11
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct sockaddr
    {
        public short sin_family;
        public ushort sin_port;
        public NativeSocketMethod.in_addr sin_addr;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
        public byte[] sin_zero;
    }

    public enum SocketType
    {
        Unknown,
        Stream,
        DGram,
        Raw,
        Rdm,
        SeqPacket
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文