Implement FDB Checksum

- Added config option `check_fdb`
- Added check in WorldServer.cpp
- Added raw MD5 function in MD5.cpp and MD5.h
This commit is contained in:
Jett 2021-12-12 03:41:11 +00:00
parent 180db5dea5
commit 49c1cb3aff
4 changed files with 36 additions and 0 deletions

View File

@ -115,6 +115,14 @@ MD5::MD5(const std::string &text)
finalize(); finalize();
} }
// raw md5 construstor
MD5::MD5(const char * input, size_type length)
{
init();
update(input, length);
finalize();
}
////////////////////////////// //////////////////////////////
void MD5::init() void MD5::init()

View File

@ -54,6 +54,7 @@ public:
MD5(); MD5();
MD5(const std::string& text); MD5(const std::string& text);
MD5(const char * input, size_type length);
void update(const unsigned char *buf, size_type length); void update(const unsigned char *buf, size_type length);
void update(const char *buf, size_type length); void update(const char *buf, size_type length);
MD5& finalize(); MD5& finalize();

View File

@ -838,6 +838,30 @@ void HandlePacket(Packet* packet) {
case MSG_WORLD_CLIENT_VALIDATION: { case MSG_WORLD_CLIENT_VALIDATION: {
std::string username = PacketUtils::ReadString(0x08, packet, true); std::string username = PacketUtils::ReadString(0x08, packet, true);
std::string sessionKey = PacketUtils::ReadString(74, packet, true); std::string sessionKey = PacketUtils::ReadString(74, packet, true);
std::string fdbChecksum = PacketUtils::ReadString(packet->length - 33, packet, false);
if (bool(std::stoi(Game::config->GetValue("check_fdb")))) {
std::ifstream fileStream;
fileStream.open ("res/CDServer.fdb", std::ios::binary | std::ios::in);
fileStream.seekg (0, std::ios::end);
uint64_t fileStreamLength = fileStream.tellg();
fileStream.seekg (0, std::ios::beg);
char * fileStreamData = new char[fileStreamLength + 1];
fileStream.read(fileStreamData, fileStreamLength);
*(fileStreamData + (fileStreamLength + 1)) = 0x00; // null terminate the string
MD5 md5 = MD5(fileStreamData, fileStreamLength + 1);
std::string ourFdbChecksum = md5.hexdigest();
Game::logger->Log("WorldServer", "Got client checksum %s and we have server checksum %s. \n", fdbChecksum.c_str(), ourFdbChecksum.c_str());
if (fdbChecksum != ourFdbChecksum) {
Game::logger->Log("WorldServer", "Client checksum does not match server checksum.\n");
Game::server->Disconnect(packet->systemAddress, SERVER_DISCON_KICK);
return;
}
}
//Request the session info from Master: //Request the session info from Master:
CBITSTREAM; CBITSTREAM;

View File

@ -47,3 +47,6 @@ solo_racing=0
# Disables the anti-speedhack system. If you get kicked randomly you might want to disable this, as it might just be lag # Disables the anti-speedhack system. If you get kicked randomly you might want to disable this, as it might just be lag
disable_anti_speedhack=0 disable_anti_speedhack=0
# 0 or 1, check server fdb (res/CDServer.fdb) against clients
check_fdb=0