0

I have a Python client and server communicating over a TCP socket - they send and receive a certain set of standardized string commands to each other.

How can I prevent a hacker from creating their own client that sends the same kind of string commands (but with their own values) to the server?

Is it right that I can assume the hacker has access to the TCP messages being transmitted/received, but not the individual code that is being executed (if I only give them the executable)?

I'm new to network security and wanted to decide how best to design my network communication scheme.

Idea - I was imagining that I could possibly encrypt the messages before sending and decrypt on the server (assuming the hacker can't find any of the keys in the source code?). Is this a secure way of going about it and am I on the right track?

2
  • "Is it right that I can assume " -- that depends entirely on where the "hacker" is. What you are describing is a "Threat Modelling" process. You are trying to work out where the threats could be and where your weaknesses might be. Your first step is to stop using the term "hacker"; "hackers" are magical evil beings. In Threat Modelling, you have "actors". Actors can observe, interact, and act. What observations, interactions, and actions pose a threat to your data and systems?
    – schroeder
    Commented Aug 22, 2020 at 7:07
  • Encryption prevents communication from being observed. It does not prevent an actor from creating a client and sending encrypted commands. What you are looking for is the concept of "authentication". You want to authenticate your clients.
    – schroeder
    Commented Aug 22, 2020 at 7:11

2 Answers 2

1

Never trust the client. If the client has a local copy of your application, they can do many things to manipulate and reverse engineer it. You can possibly slow down and discourage this by obfuscating and encrypting/packing the code, requiring certificate pinning, employing anti-debugging techniques etc., but a determined adversary will not be delayed for long.

Instead, focus on the server side. Make sure users are properly authenticated before they are able to interact any further, and check if they are properly authorized for every action. It is especially important to validate their input; since you can't trust the client, you should expect to receive invalid input. Any critical code (business logic, authn/authz, secrets, proprietary code) should be solely located on the server side. If the application is designed correctly, you shouldn't need to care about having rogue clients.

0

Your idea to suspect that you cannot just trust the client is correct. But you can never solve this issue on the network or the client. You must solve it on the server side.

You assume that they cannot see your code, but you also state "I have a Python client". Python is an interpretive language, therefore they can see the code.

How can I prevent a hacker from creating their own client that sends the same kind of string commands (but with their own values) to the server?

There are a number of ways. Firewalling so hackers don't get access to your application. Authenticating proxy in front of it. Use a VPN. Things like that. But the most important part is to make your application more robust. Does your application have authentication? What happens if they send wrong values? Can you check the validity of the input? In your server design, you must assume that not all clients are the correct clients. This has nothing to do with network security; it is application security.

Encryption will probably help if designed and used correctly; look at asymmetric encryption and digital signing for non-repudiation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .