How to Detect and Remove Hidden Linux Mining Malware – A Step‑by‑Step Guide
This guide explains how to identify the symptoms of a hidden cryptocurrency‑mining virus on a Linux server, locate and terminate the concealed processes, disable the malicious startup service, block suspicious IPs, and secure the system using tools such as sysdig, Safedog, and ClamAV.
Linux Server Mining Virus Handling Plan
Infection Overview
The mining process is hidden (CPU usage 50% shown by htop/top but no abnormal process appears), and after killing it the process restarts even though crontab -l shows no scheduled tasks.
1. Infection Symptoms
High CPU usage without any running application (check with top or htop).
Abnormal IP addresses discovered via netstat -natp.
Severe overheating and fan running at full speed.
Server becomes unexpectedly sluggish.
2. Remediation Steps
2.1 Disconnect Network and Change Root Password
Immediately isolate the server from the network and reset the root password.
2.2 Locate Hidden Mining Process
Use sysdig and unhide to find concealed processes.
# Install sysdig
sudo apt install sysdig
# Install unhide
sudo apt install unhide # Show CPU‑heavy processes (including hidden ones)
sudo sysdig -c topprocs_cpu # Search hidden processes in /proc
sudo unhide procAfter obtaining the PID, kill it with kill -9 PID. If a new mining process appears quickly, it is being restarted by a service.
2.3 Stop the Malicious Startup Service
Identify the service managing the PID using systemctl status PID. The service name ends with .service. Stop and disable it:
# Stop the service
systemctl stop xxxxX.service
# Disable autostart
systemctl disable xxxxX.service2.4 Kill the Mining Process
After the service is disabled, kill the process again; CPU usage returns to normal and no hidden processes remain.
kill -9 PID3. Prevent Future Intrusions
3.1 Identify Suspicious IPs
# List network connections and look for abnormal IPs
netstat -natpSearch the IPs online for more information.
3.2 Block Malicious IPs
# Block IP with iptables
sudo iptables -I INPUT -s <em>IP</em> -j DROP
# Verify the rule
iptables -L INPUT -v -nPersist the rules after reboot using iptables-persistent:
# Install persistence tool
sudo apt-get install iptables-persistent
# Save current rules
sudo netfilter-persistent save
# Enable on boot
systemctl enable iptables
systemctl start iptables3.3 Remove Unknown SSH Public Keys
cat ~/.ssh/authorized_keysDelete any unfamiliar keys immediately.
4. Install Safedog for Protection
Installation instructions: https://www.safedog.cn/install_desc_server.html Manual: https://www.safedog.cn/download/software/safedogfwq_linux_Help.pdf
5. Linux Virus Scanning with ClamAV
Reference: https://www.moewah.com/archives/5296.html
ClamAV is an open‑source antivirus engine offering command‑line scanning, database updates, and rapid response to new threats. It works on Windows, macOS, and Linux.
5.1 Installation
For Debian/Ubuntu:
sudo apt-get update
sudo apt-get install clamav clamav-daemonFor CentOS/RHEL:
sudo yum install epel-release
sudo yum install clamav clamav-update5.2 Configuration
# Update virus database
sudo freshclam5.3 Usage
Scanning a single file: clamscan /path/to/your/file Scanning a directory recursively: clamscan -r /path/to/directory Automatically remove detected viruses: clamscan --remove -r /path/to/directory Generate a scan report: clamscan -r /path/to/directory > scanreport.txt Use clamdscan with the ClamAV daemon for faster, multi‑threaded scans:
# Ensure the daemon is running
sudo systemctl start clamav-daemon
# Scan a file
clamdscan /path/to/your/file
# Scan a directory recursively
clamdscan -r /path/to/your/directory
# Multi‑scan with file descriptor passing
clamdscan --multiscan --fdpass /path/to/scan6. Install Sysdig
Sysdig is a powerful system‑level tracing tool, more capable than strace, tcpdump, or lsof. Install it with a one‑line script:
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bashVerify the installation:
sysdig -pc -c topconns7. Resolve Missing Command Errors for Safedog
Install required utilities:
yum -y install mlocate # locate command
yum -y install pciutils # lspci command
yum install lsof # lsof command
yum install psmisc # killall command8. Fix "No Available Packages" Errors on CentOS 7
Install the EPEL repository to obtain missing packages:
yum install -y epel-releaseSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
