[Tutorial] C++ Fix Api Tool / P2P Port Protection

  • Autor subiect darius95
  • Dată creare
  • Răspunsuri: Răspunsuri 0
  • Vizualizări: Vizualizări 4K

darius95

Member
2 Sep 2020
110
1
18
36
București
Monede Dragon
0
Server

Mt2/server/common/service.h

Adauga:

#define ENABLE_PORT_SECURITY

sVfIOd4.png

Server

db/src/Peerbase.cpp

Cauta

bool CPeerBase::Accept(socket_t fd_accept)
{
struct sockaddr_in peer;

if ((m_fd = socket_accept(fd_accept, &peer)) == INVALID_SOCKET)
{
Destroy();
return false;
}

Adauga:

#ifdef ENABLE_PORT_SECURITY
if (strcmp(inet_ntoa(peer.sin_addr), "127.0.0.1")) // refuse if remote host != localhost (only the same machine must be able to connect in here)
{
sys_log(0, "BLOCK CONNECTION FROM %s", inet_ntoa(peer.sin_addr));
Destroy();
return false;
}
#endif

ZKYxvY1.png

Server

game/src/desc_p2p.cpp

Cauta:

#include "desc_p2p.h"

Adauga:

#ifdef ENABLE_PORT_SECURITY
#include "config.h"
#endif
XUjmbdk.png



Cauta

m_iMinInputBufferLen = 1024 * 1024;

Adauga:

#ifdef ENABLE_PORT_SECURITY
if (strcmp(host, g_szPublicIP)) // refuse if remote host != public ip (only the same machine must be able to connect in here)
{
sys_log(0, "SYSTEM: new p2p connection from [%s] to [%s] fd: %d BLOCKED", host, g_szPublicIP, m_sock);
SetPhase(PHASE_CLOSE);
return true;
}
#endif

t1G5lPL.png

Server

Mt2/server/input.cpp

Cauta

int CInputHandshake::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
{
if (bHeader == 10) // ??? ??
return 0;

if (bHeader == HEADER_CG_TEXT)
{

Adauga

#ifdef ENABLE_PORT_SECURITY
if (IsEmptyAdminPage() || !IsAdminPage(inet_ntoa(d->GetAddr().sin_addr))) // block if adminpage is not set or if not admin
{
sys_log(0, "SOCKET_CMD: BLOCK FROM(%s)", d->GetHostName());
return -1;
}
#endif

U4HN7VZ.png


Done