How to Detect and Remove Linux Mining Malware: Step-by-Step Guide
This guide explains how to identify high CPU usage caused by mining trojans on Linux servers, isolate and block malicious network traffic, clean scheduled tasks, startup services, compromised libraries, SSH keys, and finally terminate and delete the malicious processes and files.
1. Check CPU Usage
If your host's CPU usage remains unusually high, it may be infected by a mining trojan that can disrupt other applications and requires immediate investigation.
top -c2. Clean the Mining Trojan
Isolation and network blocking
Isolate the host promptly.
Block abnormal network communication; mining trojans may also connect to C2 servers.
Check current iptables rules for suspicious addresses or ports that are outside normal business scope. iptables -L -n Remove suspicious addresses and ports from the rules. vi /etc/sysconfig/iptables Block the malicious traffic:
iptables -A INPUT -s <span style="color: rgb(0, 0, 255)">SUSPICIOUS_IP</span> -j DROP
iptables -A OUTPUT -d <span style="color: rgb(0, 0, 255)">SUSPICIOUS_IP</span> -j DROPClear scheduled tasks
Mining trojans often persist via cron jobs. List current user’s crontab: crontab -l List a specific user’s crontab: crontab -u username -l Inspect system-wide cron files:
cat /etc/crontab
cat /var/spool/cron
cat /etc/anacrontab
cat /etc/cron.d/*
cat /etc/cron.daily/*
cat /etc/cron.hourly/*
cat /etc/cron.weekly/*
cat /etc/cron.monthly/*
cat /var/spool/cron/*Remove malicious startup services
For CentOS 7 and earlier: chkconfig --list For CentOS 7 and later: systemctl list-unit-files Disable any identified malicious services:
chkconfig SERVICE_NAME off
systemctl disable SERVICE_NAMEAlso inspect common startup directories such as /usr/lib/systemd/system, /etc/rc.d, etc., and remove suspicious entries.
Check and clean /etc/ld.so.preload
This file can be used to preload malicious shared objects. Ensure it is empty or contains only legitimate entries, then clear it:
> /etc/ld.so.preloadRemove unauthorized SSH keys
Inspect ~/.ssh/authorized_keys for unknown keys and delete them.
Terminate and delete malicious processes
Identify mining processes:
top -c
ps -efFind the executable path of a suspicious PID: ls -l /proc/$PID/exe Kill the process and remove its file:
kill -9 $PIDCheck for other unauthorized listening ports:
netstat -antpFor each suspicious PID, repeat the path‑lookup, kill, and file‑deletion steps.
Search for recently created files that may belong to the trojan:
find /etc -ctime -2
lsof -c kinsing3. Frequently Asked Questions
Why is the cleanup not thorough? Remove cron jobs, startup services, and daemons before killing mining processes.
How to determine if a process is malicious? Verify the executable path, upload the binary to VirusTotal, or dump the process via cat /proc/$PID/exe > /tmp/t.bin for analysis.
Why does CPU stay near 100% while no process shows high usage? The top binary may be replaced or preloaded with a malicious shared object that hides the real usage. Restoring the original binary or clearing /etc/ld.so.preload resolves the issue.
rm -rf /usr/bin/top && mv /usr/bin/top.original /usr/bin/top > /etc/ld.so.preload && rm -rf /path/to/malicious.soAlternatively, replace compromised system binaries with clean copies from a matching system version or use busybox as a temporary toolbox.
yum -y install wget make gcc perl glibc-static ncurses-devel libgcrypt-devel
wget http://busybox.net/downloads/busybox-1.33.0.tar.bz2
tar -jxvf busybox-1.33.0.tar.bz2
cd busybox-1.33.0 && make && make installSigned-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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
