Most break-ins are not dramatic. There is no message on the screen. The attacker wants your server’s CPU, bandwidth, email reputation or data, and quietly keeps using it for as long as nobody notices. These are the signs we look for, and the first checks we run on a Linux server.
Signs from the outside
- Your mail starts bouncing or landing in spam, or your IP address appears on a blocklist. The server may be sending spam.
- Your hosting provider or a CERT emails you about attacks or scans coming from your IP address.
- Google shows a warning next to your site, or search results show pages in Japanese or for pharmacy products that you never made.
- Customers report redirects to other sites, strange pop-ups or card payments they did not make.
- The bill goes up: more bandwidth or cloud usage than your traffic explains.
Signs on the server
- CPU stays high when the site is quiet. Cryptocurrency miners are one of the most common payloads, and they often use names that look like system processes.
- Unknown processes, users or SSH keys. Check for accounts you did not create, and keys in
~/.ssh/authorized_keys, including root’s, that nobody on the team recognises. - New scheduled jobs in crontabs or systemd timers that download or run something.
- Unexpected network connections, especially outgoing ones to addresses you do not know, or services listening on unusual ports.
- Files changed recently in your web folders, such as PHP files in an uploads folder or code you did not write at the top of existing files.
- Logs with gaps, or logs that were cleared. Attackers often try to hide their tracks.
First checks
Run these as a normal admin user, and write down what you find:
lastandlastbshow recent logins and failed attempts. Look for logins at odd times or from unfamiliar places.ss -tunaplists network connections and the processes that own them.ps auxfortop: look for processes with high CPU, odd names or that run from/tmpor/dev/shm.crontab -lfor each user, and the files in/etc/cron.*.find /var/www -name "*.php" -mtime -7lists PHP files changed in the last week. Adjust the path and days to suit.- Check
/etc/passwdfor new users and/etc/sudoersfor new admin rights.
A clever attacker can hide from these tools on a fully compromised system, so finding nothing is not proof that the server is clean. If the outside signs are strong, treat the server as compromised.
What to do when you find something
- Do not just delete the file you found and carry on. There is almost always a way back in that you have not seen yet.
- Preserve evidence. Take a snapshot or disk image before you change things, so you can find out how they got in.
- Contain it. Block outgoing traffic you do not need, take the server off the network or put up a maintenance page if it is attacking others or serving malware.
- Change every password and key the server could see: SSH keys, control panel, database, email and API keys, from a clean computer.
- Rebuild rather than clean, where you can. A fresh server with patched software and your data restored from a known clean backup is safer than a server you hope you cleaned completely.
- Find the way in and close it: an outdated plugin, a weak password, an exposed admin panel or an unpatched service.
- Tell the people who need to know. If personal data may have been taken, check what Sri Lanka’s Personal Data Protection Act asks of you, and tell the customers affected.
Make the next one easier to spot
- Keep the operating system and every application patched.
- Use SSH keys instead of passwords, and turn off root login over SSH.
- Run a firewall that allows only the ports you need.
- Send logs to another server, where an attacker cannot erase them.
- Monitor CPU, disk and outgoing mail, with alerts that reach a person.
- Keep backups off the server, and test that they restore.
The sooner a break-in is noticed, the less it costs. A server that someone looks at every week is much harder to stay hidden on.