• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

tibia packet decryption

selo

SOON!! eh ?!
Joined
Nov 16, 2008
Messages
94
Reaction score
3
hello
could some one explain for me please how can the forgotten server decrypt tibia packets
is the developers or the forgotten server know the Decryption code (RSA KEY) or what is the matter
if some one know please explain for me how can this happen
rep++ for the member that can help me
 
From protocollogin.cpp: (also found in protocolgame.cpp, protocolold.cpp)
Code:
bool ProtocolLogin::parseFirstPacket(NetworkMessage& msg)
{
	if(
#if defined(WINDOWS) && !defined(__CONSOLE__)
		!GUI::getInstance()->m_connections ||
#endif
		g_game.getGameState() == GAME_STATE_SHUTDOWN)
	{
		getConnection()->close();
		return false;
	}

	uint32_t clientIp = getConnection()->getIP();
	/*uint16_t operatingSystem = msg.GetU16();*/msg.SkipBytes(2);
	uint16_t version = msg.GetU16();

	msg.SkipBytes(12);
[B]	if(![COLOR="red"]RSA_decrypt[/COLOR](msg))[/B]
	{
		getConnection()->close();
		return false;
	}
From protocol.cpp:
Code:
bool Protocol::RSA_decrypt(RSA* rsa, NetworkMessage& msg)
{
	if(msg.getMessageLength() - msg.getReadPos() != 128)
	{
		std::cout << "[Warning - Protocol::RSA_decrypt] Not valid packet size" << std::endl;
		return false;
	}

	[B][COLOR="red"]rsa[/COLOR]->[COLOR="red"]decrypt[/COLOR]((char*)(msg.getBuffer() + msg.getReadPos()), 128);[/B]
	if(!msg.GetByte())
		return true;

	std::cout << "[Warning - Protocol::RSA_decrypt] First byte != 0" << std::endl;
	return false;
}
From rsa.cpp:
[cpp]void RSA::decrypt(char* msg, int32_t size)
{
boost::recursive_mutex::scoped_lock lockClass(rsaLock);

mpz_t c,v1,v2,u2,tmp;
mpz_init2(c, 1024);
mpz_init2(v1, 1024);
mpz_init2(v2, 1024);
mpz_init2(u2, 1024);
mpz_init2(tmp, 1024);

mpz_import(c, 128, 1, 1, 0, 0, msg);

mpz_mod(tmp, c, m_p);
mpz_powm(v1, tmp, m_dp, m_p);
mpz_mod(tmp, c, m_q);
mpz_powm(v2, tmp, m_dq, m_q);
mpz_sub(u2, v2, v1);
mpz_mul(tmp, u2, m_u);
mpz_mod(u2, tmp, m_q);
if(mpz_cmp_si(u2, 0) < 0)
{
mpz_add(tmp, u2, m_q);
mpz_set(u2, tmp);
}
mpz_mul(tmp, u2, m_p);
mpz_set_ui(c, 0);
mpz_add(c, v1, tmp);

size_t count = (mpz_sizeinbase(c, 2) + 7)/8;
memset(msg, 0, 128 - count);
mpz_export(&msg[128 - count], NULL, 1, 1, 0, 0, c);

mpz_clear(c);
mpz_clear(v1);
mpz_clear(v2);
mpz_clear(u2);
mpz_clear(tmp);
}[/cpp]
 
Last edited:
I don't know either, look at it :p
By the looks of it, someone who's good at math has made it originally :p
 
Look at 0.4 code. It's much simpler since we use OpenSSL instead of rsa.cpp. RSA are explained @wikipedia.

EDIT: Don't forget we got XTEA too.
 
hmm,im wondering how can the forgotten server decrypt that with out RSA key ? :(
p7YwU.png


The private key is in otserv.cpp
 
Back
Top