I need an advice. I have a communication protocol using 3DES cipher. Each time the client connects (and it can be very often like 1-10 per second), the 24-byte key is generated randomly on server side, encoded by XORing with some static 24-byte password (quite complicated, not many repeated bytes) and then sent to the client.

How good/weak is such a way of communication assuming that the hacker can only listen to the transmission and does not have access to applications binaries?


The security of this scheme largely depends on how good your key generation is. If an attacker observes two key exchanges, he may calculate the xor of the two unobfuscated keys:

The values ka and kb are two unobfuscated keys. kA and kB are the associated obfuscated keys. o is the static obfuscation key.

kA = ka ^ o
kB = kb ^ o
kA ^ kB = ka ^ o ^ kb ^ o

The two instances of o cancel out, giving us ka ^ kb. This works with any two chosen session keys.

This might allow an attacker to leverage weaknesses in your random number generator, by eliminating internal states that cannot produce consecutive outputs that exhibit such a pattern.

Of course, if an attacker ever discovers the unobfuscated value of a key, through any means at all, then he may simply xor the obfuscated key with the unobfuscated key to find o, and therefore break all future communications.

In reality, this is a bad way to do it, because an attacker is likely to have access to your application. By simply reverse engineering your binary, the attacker can discover this hard-coded key and break all communications. You're relying on obscurity for your security, which goes against Kerckhoff's Principle - i.e. "the enemy knows the system".

I did something similar recently with an application that took almost exactly the same route, and it only took me an hour to completely break their crypto and reverse engineer their internal packet format. From there I wrote up a Python script that automatically decrypts the entire session from a pcap packet capture file.

If you're looking for proper end-to-end communications security, go for something like SSL. Most languages have libraries for implementing it, so it shouldn't be too difficult.

If you don't got for SSL, you're going to need to handle the following:

  • Cryptographic strength key generation.
  • Key exchange (e.g. Diffie-Hellman or hard-coded RSA public key)
  • 3DES encryption and decryption with an appropriate mode of operation, and IV exchange.
  • Authentication and integrity checking, e.g. via HMAC.
  • Defence against timing attacks and other side-channel attacks.
  • Proper error handling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy