Apply the principle of least privilege.
Validate all untrusted data.
Apply the latest patches.
Scan your services and disable the ones which are not needed and are
exposed unnecessarily. Exposing programs increases the attack surface. Only
expose the services which are needed and have security mechanisms such as
authentication built around them.
Avoid revealing information about your system (e.g., version of the
program) to anonymous users.
Make sure that your program or service fail safely. What happen if the
communication protocol is interrupted suddenly? What happen if a parameter
is missing? Does your system have resistance and resiliance to attack? Fail
safely when a resource exhaustion occurs.
If possible use a sandbox model which limits the actions that programs can
take. A sandbox restricts a program to a set of privileges and commands that
make it difficult or impossible for the program to cause any damage.
Check your program for buffer overflow and format String vulnerabilities
which can lead to execution of malicious code.
Monitor traffic and resource usage and pay attention if resource
exhaustion occurs.
Protect your log file from unauthorized modification and log
forging.