Today I've got a problem with a packet or buffer overflow. Some Hackers are attacking my server by sending too much packets. The first time the programm they attack starts to lag and it doesnt response anymore. After some time the programm crashes.
Here is the snippet where the client sends the packet:
if( !IsValid() || !pPacket )
return;
Encrypt(pPacket);
LPBYTE pBUF = pPacket->GetBuffer();
int nSEND = 0;
int nSIZE = INT(pPacket->GetSize());
while(nSEND < nSIZE)
{
int nLOCAL = send( m_sock, (const char *) pBUF, nSIZE - nSEND, 0);
if( nLOCAL != SOCKET_ERROR )
{
nSEND += nLOCAL;
pBUF += nLOCAL;
}
else
{
int nERROR = WSAGetLastError();
if( nERROR != WSAEWOULDBLOCK )
return;
}
}
And this is the part where the server receives the packet:
SMART_LOCKCS(&m_cs)
if( INVALID_SOCKET == m_sock || !m_bValid || !m_bCanRecv )
{
return FALSE;
}
DWORD dwFlags = 0;
DWORD dwRecv = 0;
if(m_Recv.IsReadBufferFull())
m_Recv.ExpandIoBuffer(m_Recv.GetSize());
memset( &m_vBUF, 0, sizeof(WSABUF));
m_vBUF.buf = (char *) (m_Recv.GetBuffer() + m_Recv.GetReadBytes());
m_vBUF.len = m_Recv.m_dwBufferSize - m_Recv.GetReadBytes();
if( WSARecv(
m_sock,
&m_vBUF, 1,
&dwRecv,
&dwFlags,
(LPOVERLAPPED) &m_ovRECV,
NULL))
{
DWORD dwERROR = WSAGetLastError();
if( dwERROR != ERROR_IO_PENDING )
return FALSE;
}
return TRUE;
So, what I want to do is to create a function which checks if the packet was sent from my client (I suppose the Hackers use an extern programm). But I dont know how they can send a packet anyway because I use my on encryption/decryption. So maybe you guys can help me with it. If you have an other idea how to block the overflow then please give me you idea.
Comments
Post a Comment