If you suspect your server has been compromised: a step-by-step response
If you have spotted an unknown process, an unexpected user account or an abuse report on your server, this guide gives you the order to follow, from containing the attack to a clean reinstall, along with the commands to run at each step.
Which signs point to a compromise?
A single sign does not always mean an attack. If several of the following appear together, however, treat the server as compromised and follow the steps in this guide. Cryptocurrency miners often use names that imitate system processes such as kworker or systemd-, while web shells usually sit in upload folders, hidden behind obfuscated code such as eval(base64_decode(.
| Sign | Likely cause | Command to check |
|---|---|---|
| Constant 100% CPU, unknown process | Cryptocurrency miner | top -c, ls -l /proc/PID/exe |
| Report that the server is sending spam | Compromised web application or email account | ss -tnp state established, mailq |
| Successful SSH login from an unknown IP | Leaked password or key | journalctl -u ssh | grep Accepted |
| New user or a UID 0 account | Account created for persistent access | awk -F: '$3 == 0' /etc/passwd |
| Unknown cron job or systemd unit | Malware that returns after a reboot | crontab -l -u USER, systemctl list-timers --all |
| Redirects or foreign content on the site | Web shell or injected code | find /var/www -type f -ctime -3 |
| Inconsistent output from basic commands | Rootkit | rpm -Va, debsums -c, cat /etc/ld.so.preload |
Deleting suspicious files right away or rebooting the server repeatedly destroys the traces that show how the attacker got in. If you cannot find the root cause, the same hole will be used again after a clean reinstall. The order is always the same: contain first, then investigate, and clean up last.
First response: contain, take a snapshot, switch to the console
1. Contain the attack
The first goal is to stop the server from harming others and to stop the attacker from keeping access. If the attack is ongoing (outgoing spam, heavy traffic, high CPU load), you have two options:
- Restrict the network: Block outgoing traffic in the firewall and allow incoming connections only from your own IP address. The server keeps running, so you can investigate the live system.
- Stop the server: Use Stop Server in the client area for a clean shutdown. An attacker with root access can also turn off the firewall, so this is the most reliable form of containment. If VMware Tools does not respond, you can use Force Stop; see the power actions guide for the differences. The VNC Console does not open on a stopped server, so when you start it again to investigate, restrict the network first.
Run the commands below from the VNC Console in case your SSH session drops. Replace 203.0.113.10 with your own IP address, and 22 with your SSH port if you have changed it.
# Ubuntu/Debian (UFW): allow SSH from your IP first, then close the defaults
sudo ufw allow from 203.0.113.10 to any port 22 proto tcp
sudo ufw default deny incoming
sudo ufw default deny outgoing
sudo ufw enable
# Find public SSH and other allow rules by number and delete them
sudo ufw status numbered
sudo ufw delete 2 # example: rule number 2
# AlmaLinux (firewalld): drops all incoming and outgoing traffic
sudo firewall-cmd --panic-on
sudo firewall-cmd --query-panic
# When the investigation is over
sudo firewall-cmd --panic-off2. Take a snapshot before you investigate
To freeze the current state, create a snapshot in the Snapshots section of the client area. This copy serves two purposes: you can roll back if you break something during the investigation, and you keep evidence for answering the question "what did the attacker do?" later. A snapshot preserves the disk as it was at that moment, not the memory (RAM), so examine traces of processes that live only in memory on the live system. You can keep at most 2 snapshots at a time, so if the limit is reached, delete one of the older ones.
Keep in mind that the snapshot also contains the malware, the backdoors and the modified files. Restoring it does not clean the server; it only takes the disk back to its compromised state. A snapshot is not a full backup either, so copy the data you want to recover off the server separately. Details: snapshot guide.
3. Use the VNC Console if you do not trust SSH
The attacker may have changed the SSH configuration, may be watching sessions or may be connected with their own key. In that case, connect through the VNC Console in the client area. The console runs in your browser, is relayed through the client area and does not depend on the server's network settings, so it works even if you have blocked all traffic in the firewall. The console opens only while the server is running (see the VNC Console guide).
Investigate the traces
The commands below only collect information; they do not change the system. Remember that an attacker with root access may have replaced tools such as ps and ls, so clean-looking output is not proof. If you record the whole session to a file, you can copy your findings to your own computer later.
# Record commands and output to a file (when finished: exit)
script -a /root/investigation-$(date +%F).logSessions and logins
# Recent successful logins and who is connected now
last -n 30
who
# Failed logins (lastb may be missing on newer releases such as Debian 13)
sudo lastb -n 30
# SSH logs (the unit is called sshd on AlmaLinux)
sudo journalctl -u ssh --since "7 days ago" | grep -E "Accepted|Failed|Invalid"If you see an IP address you do not recognize on an Accepted line, the way in was most likely a password or a key.
Processes and network connections
# Process tree and the heaviest CPU users
ps auxf
top -c
# Listening ports and the processes that opened them
sudo ss -tulpn
# Established connections: mining pools, outbound SMTP traffic on port 25
sudo ss -tnp state established
# Programs deleted from disk but still running (common with miners)
sudo ls -l /proc/*/exe 2>/dev/null | grep deleted
# File path and command line of a suspicious process
sudo ls -l /proc/PID/exe
sudo cat /proc/PID/cmdline | tr '\0' ' '; echoThe vmtoolsd process is VMware Tools (open-vm-tools). Client area actions such as a clean shutdown or a password reset depend on this service, so do not stop or remove it thinking it is malicious. The /var/log/wisecp-task.log file is likewise the in-server log of client area actions.
Persistence: cron, systemd, users and keys
# Every user's crontab and the system cron directories
for u in $(cut -d: -f1 /etc/passwd); do sudo crontab -l -u "$u" 2>/dev/null | sed "s/^/$u: /"; done
ls -la /etc/cron.d /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly
cat /etc/crontab
# Timers, enabled services and recently added unit files
systemctl list-timers --all
systemctl list-unit-files --state=enabled
ls -lt /etc/systemd/system | head -20
# Accounts with UID 0, users with a login shell, sudo rights
awk -F: '$3 == 0 {print $1}' /etc/passwd
grep -vE 'nologin|false$' /etc/passwd
sudo cat /etc/sudoers; sudo ls -la /etc/sudoers.d
# Authorized SSH keys (with line numbers) and which key file sshd reads
sudo find / -xdev -name 'authorized_keys*' -ls
sudo cat -n /root/.ssh/authorized_keys
sudo sshd -T | grep -i authorizedkeysfile
# Preload file that normally should not exist
cat /etc/ld.so.preloadKeys added with the SSH Keys tool in the client area are written to the login user's ~/.ssh/authorized_keys file (root on Linux templates), between the # BEGIN WISECP and # END WISECP lines. Lines outside these markers were added from inside the server and do not appear in the client area list; an attacker's key is often there. Look for keys you do not recognize in both parts.
Web files and package integrity
# Web files changed in the last 3 days and PHP files in upload folders
sudo find /var/www -type f -mtime -3 -ls
sudo find /var/www -type f -ctime -3 -ls
sudo find /var/www -path '*uploads*' -name '*.php'
sudo grep -rlE 'eval\(base64_decode|gzinflate\(base64_decode' /var/www
# AlmaLinux: integrity of package files (5 = content changed, c = configuration file)
sudo rpm -Va | grep -v ' c '
# Debian/Ubuntu: changed package files
sudo apt install debsums
sudo debsums -cAttackers can set a file's modification time (mtime) back with touch, whereas -ctime shows when the file's metadata last changed and is not easy to fake. If you have blocked outgoing traffic, debsums cannot be installed; you can skip this check, as the recommendation is a clean reinstall anyway.
Change your credentials
Assume that every password and key the attacker could see on the server has been stolen. Make the changes from a computer you know is clean. Revoke keys for services outside the server right away, and set the passwords used inside the server again after the clean reinstall.
- root / Administrator: Use Reset Root Password in the client area. The client area signs in to the server with the stored password; if the reset fails with an error saying it could not sign in with the stored password and you did not change it yourself, the attacker may have changed it. Treat that as another sign.
- SSH keys: Generate a new key pair on your own computer, and remove the old keys from the SSH Keys list in the client area; delete keys outside the
# BEGIN WISECPblock by editing theauthorized_keysfile. If private keys were stored on the server (for example, deploy keys for a Git repository), revoke them in the service they belong to. - Database and application: MariaDB/MySQL user passwords, CMS administrator accounts, and secrets in files such as
.envandwp-config.php. - API keys and access tokens: Keys for payment gateways, email delivery services, cloud storage and DNS providers.
- Panels: Control panel passwords such as cPanel or Plesk, and your client area password.
Clean reinstall and closing the root cause
Recommended recovery: reinstall and restore only the data
A compromised system does not become trustworthy because someone says it has been cleaned. Missing a single backdoor left by the attacker is enough, and kernel-level rootkits can hide even from the commands above. The recommended path is:
- Copy the data you need to recover (database dumps, user uploads, configuration notes) off the server. Do not consider it trustworthy; you will review it before restoring it.
- Use Reinstall OS in the client area to install a current LTS template. This erases all data on the disk; set a new, strong root password in the form (see the reinstall guide).
- Harden the new system before it goes live: the first 30 minutes checklist, SSH key login, a firewall, Fail2ban and automatic security updates.
- Reinstall the application code from version control or its official source; do not bulk-copy PHP files from the old server. Restore only the data, from a clean backup taken before the compromise, and check the database for administrator accounts you do not recognize. For a backup plan, see the backup strategy guide.
Close the root cause
Do not go live until the entry point you found during the investigation is closed on the new system. The most common causes are:
- An outdated CMS, plugin or theme, or a PHP version that is no longer supported.
- Root SSH login left open with a weak password, or one reused elsewhere.
- Services exposed to the internet without authentication: Redis (6379), the Docker API (2375), Elasticsearch (9200), MongoDB (27017). Remember that ports published by Docker can bypass UFW rules (see the Docker guide).
- A leaked SSH key, or an
.envfile committed to a Git repository by mistake.
Notifications and legal obligations
If you have received an abuse report about your server, reply to the related support ticket and share the measures you have taken and the server's current state (stopped, network restricted, reinstalled) in the same ticket. The rules for server use are set out in the Acceptable Use Policy. Never share passwords, card details or one-time codes in support messages.
If the server holds personal data such as customer, employee or member information and you think it may have been accessed without authorization, review your notification obligations under the Personal Data Protection Law No. 6698 (KVKK) with your legal counsel. Under a decision of the Personal Data Protection Board, notification is expected within 72 hours of learning of the breach, and this deadline can pass before your investigation is finished. For current information, see kvkk.gov.tr.
A short note for Windows servers
The order is the same on Windows: contain, take a snapshot, investigate, reinstall cleanly. Open the Security log in Event Viewer: 4624 is a successful logon (logon type 10 is Remote Desktop), 4625 is a failed logon, 4720 is a new user account, and 4732 means a member was added to a local security group such as Administrators. List new local users and scheduled tasks with PowerShell. To harden RDP, see the RDP security guide.
# Last 50 failed logons
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} -MaxEvents 50 | Format-List TimeCreated, Message
# Local users and members of the Administrators group (by SID, language independent)
Get-LocalUser | Format-Table Name, Enabled, LastLogon
Get-LocalGroupMember -SID S-1-5-32-544
# Scheduled tasks outside the Microsoft folder
Get-ScheduledTask | Where-Object TaskPath -notlike '\Microsoft\*' | Format-Table TaskName, TaskPath, StateFrequently asked questions
Isn't it enough to kill the malicious process and delete its file?
Usually not. Miners typically set up persistence through cron, systemd or authorized_keys and come back within minutes. If you have not closed the way in, the attacker gets back in too. Stopping the process gives temporary relief; the lasting fix is a clean reinstall.
Will Hostimor clean my server for me?
Our servers are an unmanaged service, so managing the operating system and applications, and with it the investigation and cleanup inside the server, is up to you (Service Scope and Support Terms). Client area tools such as the VNC Console, Snapshots and Reinstall OS are there so that you can run this process yourself. If you run into a problem with these tools, you can open a support ticket; for what to include, see the support ticket guide.
Related articles
Thanks for your feedback!