Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about decrypting packets #58

Open
futurumesta opened this issue May 1, 2023 · 3 comments
Open

Question about decrypting packets #58

futurumesta opened this issue May 1, 2023 · 3 comments

Comments

@futurumesta
Copy link

futurumesta commented May 1, 2023

Hi!
I want to ask about encrypting packets, I have some problem with that.

When we encrypt packet headers (send from client), we encrypt 6 bytes (as an example: CMSG_CHAR_CREATE), Since we are using a Circular buffer the next offset will be 6 bytes (and so on each time +6 bytes on the next send from the client, offset 6,12,18,24...). This works fine for me and the server understands and correctly decodes the packet headers. But the problem comes when I (the client) try to decode the response (server) headers. We must always decode exactly 4 bytes of the server header (as always, shouldn't we? as an example SMSG_CHAR_CREATE). I can only decrypt the header of the first packet. Further, all other packets coming from the server cannot be decrypted by me. Here we use the same Circular buffer, only offset is now +4 bytes (4,8,12,16...) - SMSG (server) headers are always 4 bytes

Am I making a mistake somewhere?

private int InternalTransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
for (var counter = 0; counter < inputCount; counter++)
{
x = (byte)(x + 1);
y = (byte)(state[x] + y);
// swap byte
var tmp = state[x];
state[x] = state[y];
state[y] = tmp;
var xorIndex = (byte)(state[x] + state[y]);
outputBuffer[outputOffset + counter] = (byte)(inputBuffer[inputOffset + counter] ^ state[xorIndex]);
}
return inputCount;
}
}
}

@jackpoz
Copy link
Owner

jackpoz commented May 2, 2023

Hi, I have not modified that code and kept what the previous author did, so no idea what could go wrong. Are you building something of your own ?

@futurumesta
Copy link
Author

Hi, I have not modified that code and kept what the previous author did, so no idea what could go wrong. Are you building something of your own ?

Yeah, I'm writing my new application and I just can't figure out how the decryption algorithm works here

@jackpoz
Copy link
Owner

jackpoz commented May 3, 2023

you could check what https://github.com/TrinityCore/TrinityCore/tree/3.3.5 does, maybe it will help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants