[RELEASE] Shaiya packet emcryption/decryption library

11/22/2016 23:06 szobonya3#1
Hi Everyone!

Im releasing a library for the encryption/decryption of shaiya network packets.
(The code might not be the best so bear with me.)

The handshake - some basic explanation how it works:

Client side:
  • Connect to login server
  • Receive RSA 1024 publickey
  • Generate a 1024bit random number
  • Encrypt the random number with rsa publickey
  • Send encrypted random number
  • hash the random number using sha256
  • Create a hmac(hashed random number, rsa modulus) using sha256
  • Use the first 16 bytes of hmac as the base AES key
  • Use the second 16 bytes of hmac as the base IV
  • Expand the base AES key
  • Use the first extended AES key as AES key
  • Use the base IV as the send and recieve counter


Server side:
  • Accept connection
  • Generate RSA 1024 keypair (or use pre generated)
  • Send RSA 1024 publickey
  • Receive encrypted random number
  • Decrypt the random number with rsa privatekey
  • hash the random number using sha256
  • Create a hmac(hashed random number, rsa modulus) using sha256
  • Use the first 16 bytes of hmac as the base AES key
  • Use the second 16 bytes of hmac as the base IV
  • Expand the base AES key(creates 11 keys)
  • Use the first extended AES key as AES key
  • Use the base IV as the send and recieve counter

After the handshake both the client and the server use AES 128 counter mode.

So basicly:
  • Divide the packet into 16byte or less sized chunks. (chunks smaller than 16 bytes gets padded automatically)
  • Do AES encryption/decryption with IV (send and recv packets use different IV as above)
  • Increment IV
  • Do the next chunk

More info:
[Only registered and activated users can see links. Click Here To Register...]

The library is written in c++ and uses cryptopp (5.6.x should be fine) also the AES expanson method taken from
[Only registered and activated users can see links. Click Here To Register...]

The library includes an example "login" server which:
  • Accepts the first and only connection
  • Initiates handshake
  • Receives and the decrypts the login packet

NOTE:
The library part (crypto.cpp, crypto.hh) should compile in windows however the poject was done on linux so no guaranties. The server.cpp (the example file uses BSD sockets, so modifications is needed on windows).

LIMITATIONS:
In the handshake process 11 aes keys are generated, however the first one is observed to be used.Its very likely that the key changes after a certain number of encrypted/decrypted chunks.
11/23/2016 15:21 shen1l#2
nice!
we check here

/**< Receive login packet */
ret=recv(cli_sockfd,login_packet,52,0);
if(ret!=sizeof(login_packet))
{
hError("recv error");
}

we have got lots of attacks in the past years
people could send request to ps_login directly without game client..
and coz once connected,server side will not kick you
so what if they send create 1000~2000 sockets in a short time?
so we better get a firewall to prevent people login from multiple connection of a ip