How a Hidden Cron Job Hijacked My Server and How I Fixed It

A production server running Tomcat, MySQL, MongoDB and ActiveMQ was taken down by a malicious cron job that executed a cryptomining script, and the article walks through the investigation, removal, and hardening steps to fully recover and secure the system.

Java Backend Technology
Java Backend Technology
Java Backend Technology
How a Hidden Cron Job Hijacked My Server and How I Fixed It

Incident Overview

My online server, which hosts Tomcat, MySQL, MongoDB and ActiveMQ, suddenly became inaccessible.

Investigation

After logging in with a fast 150‑plus keystroke speed, I saw that Tomcat had crashed and any restart attempts were killed. Running top revealed a mysterious process repeatedly consuming CPU.

Suspecting a scheduled task, I examined the crontab and discovered a hidden entry that kept respawning the process.

The task downloaded and executed a cryptomining script, as shown in the captured script image.

For those interested, the full source can be retrieved with a single command (the exact command is shown in the original blog image).

Remediation Steps

1. Kill the malicious process and remove the crontab entry. 2. Locate the temporary directory (in my case /var/tmp) and delete the malicious files. 3. Restart Tomcat and other services.

These actions restored service availability, but they only addressed the symptom.

Hardening Measures

To prevent recurrence, I performed the following:

Upgrade all software to the latest versions.

Change default ports for all services.

Inspect ~/.ssh/authorized_keys and remove unknown keys.

Delete unfamiliar user accounts.

Block the attacker’s IP address.

Configure SSH to use key‑based authentication only and disable password login.

The root cause was a vulnerability in an old version of ActiveMQ exposing port 61616, which allowed the attacker to deploy the mining script.

Final Thoughts

One community‑suggested “ultimate” fix is to replace the attacker’s script with your own mining script, ensuring any future attempts fail, but a proper security patch and system hardening are the recommended solutions.

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.

incident responseServer Securitycron jobcryptominingLinux Hardening
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

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.