我将一个 dll 注入到服务器中,因为我需要阻止一些服务器没有丢弃的坏数据包。
我的代码片段:
#pragma comment(lib, "detours.lib")
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Mswsock.lib")
(...)
int (WINAPI *pRecv)(SOCKET s, char* buf, int len, int flags) = recv;
int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags);
(...)
AllocConsole();
freopen("CONOUT$", "w", stdout);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pRecv, MyRecv);
if(DetourTransactionCommit() == NO_ERROR)
cout << "[" << MyRecv << "] successfully detoured." << endl;
出于测试目的,我只是将数据打印出来。
int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags)
{
cout << "[ RECV " << len << " ] ";
for ( int i = 0; i < len; i++ )
{
printf( "%02x ", unsigned char (buf[i]) );
}
printf( "\n" );
return pRecv(s, buf, len, flags);
}
现在我把它钩住了,它显示[ address ] successfully detoured.
.
我想一切都已经上钩并且正在工作。
现在我去客户端并开始发送数据包。
例如我登录,现在这会向服务器发送一个数据包。
而且我成功登录了,所以服务器应该已经收到了我发送的数据包。
现在我检查连接到 的控制台,但server
没有打印任何内容。
这很奇怪,所以我尝试在服务器上连接 WPE_PRO 并再次开始与客户端通信。现在我发现即使是 WPE 也无法记录数据包。
这怎么可能?为什么会这样?
我正在尝试在服务器上构建一个数据包记录器/过滤器来阻止坏数据包。
黑客正在使用数据包来破坏我们的服务器。
我正在尝试挂钩的应用程序的信息:
It works like a relay server. It receives info from the client then sends it to the right server inside the internal network.
So Client <-> `Application` <-> Servers
So what I'm trying to hook is the Application .
更新
尝试在recv()
,WSArecv()
函数上设置断点,它不会中断。
Address Ordinal Name Library
------- ------- ---- -------
004121A8 23 socket WS2_32
004121A4 20 sendto WS2_32
004121E8 3 closesocket WS2_32
0041219C 9 htons WS2_32
004121A0 17 recvfrom WS2_32
004121E4 111 WSAGetLastError WS2_32
004121E0 115 WSAStartup WS2_32
004121DC 11 inet_addr WS2_32
004121D8 WSAIoctl WS2_32
004121D4 WSAConnect WS2_32
004121D0 22 shutdown WS2_32
004121CC 12 inet_ntoa WS2_32
004121C8 2 bind WS2_32
004121C4 8 htonl WS2_32
004121B4 16 recv WS2_32
004121BC WSASocketA WS2_32
004121B8 19 send WS2_32
004121B0 WSAAccept WS2_32
004121AC 13 listen WS2_32
004121C0 21 setsockopt WS2_32
当我检查 PE 时,只有这些 dll 被导入:
pdh.dll
WS2_32.dll
KERNEL32.dll
USER32.dll
GDI32.dll
WINMM.dll
更新
只是为了测试我的代码是否有效,我将 DLL 连接到客户端,是的,数据包被记录/打印。确认我的代码有效。嗯。
更新
还试图绕道ff。
int ( WINAPI *pSend )( SOCKET s, const char *buf, int len, int flags ) = send;
int ( WINAPI *pRecv )( SOCKET s, char *buf, int len, int flags ) = recv;
int ( WINAPI *pRecvFrom )( SOCKET s, char *buf, int len, int flags, sockaddr *from, int *fromlen ) = recvfrom;
int ( WINAPI *pWSARecvEx )( SOCKET s, char *buf, int len, int *flags ) = WSARecvEx;
仍然没有。
更新
所以我使用wireshark
并看到了通过的数据包。
我整天都在调试程序,在所有 winsock 调用上设置断点,但仍然一无所获。