Phase 1: Identify and Isolate
- Check for unusually high CPU usage: Use commands like
top,htop, ornmonto identify processes consuming excessive CPU. - Examine running processes: Look for unfamiliar or suspicious processes that might indicate a cryptominer. Pay attention to processes with generic names or those running from unusual directories.
- Review network activity: Use
netstat -tulnporss -tulnpto check for unusual outbound connections to mining pools or unknown IP addresses. - Scrutinise log files: Check system logs in
/var/logfor any error messages or suspicious entries that might point to a cryptominer. - Isolate the affected machine: Disconnect the compromised Linux machine from the internet to prevent further mining operations and communication with command-and-control servers.
Important
Phase 2: Identify and Stop Cryptominer Processes
- Identify the process ID (PID): Use
ps aux | grep [process_name]to find the PID of the suspicious process. - Stop the process: Use the command
sudo kill -9 [PID]to terminate the cryptominer process. Be sure to replace[PID]with the actual process ID. - Check for persistent processes: After stopping, run
ps aux | grep [process_name]again to confirm the process is no longer running. If it restarts, it might be launched by a service or scheduled task.
Tip
Phase 3: Remove Malicious Files and Persistence Mechanisms
- Locate cryptominer files: Search for files associated with the cryptominer using commands like
find / -name "[miner_executable]". Common locations include/tmp,/opt,/usr/local/bin, or hidden directories. - Remove cron jobs: Check for suspicious scheduled tasks by running
crontab -lfor the current user andsudo cat /etc/cron*for system-wide cron jobs. Remove any malicious entries usingcrontab -eor by editing the relevant files. - Disable systemd services: Look for unusual systemd service units in
/etc/systemd/system/or/lib/systemd/system/. Disable and remove them withsudo systemctl disable [service_name]andsudo rm [service_file]. - Check for startup scripts: Examine
/etc/rc.local,/etc/init.d/, and user-specific startup files in~/.bashrc,~/.profile, or~/.config/autostart/for suspicious entries. - Delete malicious files: Once identified, remove these files using
sudo rm -rf [file_or_directory_path]. Be extremely careful with this command.
Important
Phase 4: Post-Removal Cleanup and Security Hardening
- Update all software: Ensure your operating system and all installed software packages are up to date using
sudo apt update && sudo apt upgrade(for Debian/Ubuntu) or equivalent commands for your distribution. - Change all passwords: Assume any credentials stored on the compromised system may have been exposed. Change passwords for user accounts, SSH keys, and any services accessed from the machine.
- Review firewall rules: Verify your firewall (e.g.,
ufw statusorfirewall-cmd --list-all) to ensure only necessary ports are open. - Install a reputable antivirus/anti-malware scanner: Consider using tools like ClamAV to perform a full system scan.
- Monitor system performance: Keep an eye on CPU usage, network activity, and system logs to confirm the cryptominer has been completely eradicated and no new suspicious activity emerges.
- Consider a fresh installation: For critical systems or if you are unsure about the completeness of the removal, a reinstallation of the operating system is the safest option.
Good to know
Was this guide helpful?
Know someone who needs this? Send them the guide.
Written by
Jordan DicksonFounder, CyberSecurityGuides
Founder of CyberSecurityGuides, writing practical, jargon-free guides that help everyday people recover from and protect against online attacks.
Reviewed by CSG Security Engineers