Problem with Malware on VPS (Docker/PHP)

ynot

Junior Member
Joined
Apr 25, 2020
Messages
106
Reaction score
122
Hey guys,

I have a really nasty problem with some of my VPS's.

I am not a server admin and couldn't find a solution by myself, so will appreciate any answers.

My VPS configuration:
  • Docker containers - PHP-FPM, Redis, MariaDB, Adminer, SFTP + Mailserver
  • I have Apache installed directly over the servers and the traffic is routed via Proxy to the PHP container.
  • I have installed a Firewall, but so far I couldn't manage to configure it to work correctly with Docker.
  • SSH access is limited only with pair of keys, root login is forbidden. I only work with sudo inside.
Everything is latest version, downloaded from official Docker containers.

The problem - there is a Malware inside the PHP package which runs after some time. It's mining Bitcoins and respectively draining 100% of my CPU which causes the servers to crash.

At the beginning I did not have a password for Redis. I didn't believe it's necessary since the Redis port was closed. Right now I did set a password.

The malware appears in the PHP container and generates files:
Code:
/tmp/kdevtmpfsi
/var/tmp/kinsing
/tmp/zzz
/tmp/zzz.sh

I clean it with following commands:

Code:
kill -9 $(pidof kdevtmpfsi)
kill -9 $(pidof kinsing)
rm -f /tmp/kdevtmpfsi ; echo "ALL_GOOD_HERE" > /tmp/kdevtmpfsi
rm -f /var/tmp/kinsing ; echo "ALL_GOOD_HERE" > /var/tmp/kinsing
rm -f /tmp/zzz ; echo "ALL_GOOD_HERE" > /tmp/zzz
rm -f /tmp/zzz.sh ; echo "ALL_GOOD_HERE" > /tmp/zzz.sh
chmod -R go-x /tmp
chmod -R 0777 /tmp/
chmod -R go-x /var/tmp
chmod -R 0777 /var/tmp/

The problem is that periodically those files are replaced with those of the malware with rights of user www-data.

Right now my only temporarily solution is to clean those files via Cron every minute.

A really nasty problem, all comments will be appreciated :)
 
Maybe you're getting attacked by someone ?. Did you try to renew it ?
 
Is it running as a process? Try ps command and see the existing processes.

Also, is it being run from crontab? That's another thing to see.

Also see if there is any weird request being made to your server. Something is probably exploiting your vulnerable script periodically?

If it doesn't help, then I would recommend making a new dockr instance with the same config, and copy just the php files and db in there. Basically, you will need to re install the site again.
 

I really don't want to start everything over, but probably this will be the final option...

Doesn't really found a permanent fix as well.

Maybe you're getting attacked by someone ?. Did you try to renew it ?

To renew what? I did not understand :)

Is it running as a process? Try ps command and see the existing processes.

Also, is it being run from crontab? That's another thing to see.

Also see if there is any weird request being made to your server. Something is probably exploiting your vulnerable script periodically?

If it doesn't help, then I would recommend making a new dockr instance with the same config, and copy just the php files and db in there. Basically, you will need to re install the site again.

Yeah, as I've mentioned above, this will be the final option, to reinstall everything.

So far I killed the process everywhere, but it still manages to run after a couple of hours.
 
To renew what? I did not understand
I am talking about this. Try to renew it but be care full you may lose your data so better to make a backup

download.png
 
I faced similar issue. After attack my acc sheet and PayPal details hacked..
 
I am talking about this. Try to renew it but be care full you may lose your data so better to make a backup

View attachment 152764

I will postpone this as much as possible.

you need to find out what is being exploited so you know the entry point of the attacker. there is likely some bug in one of your scripts that is exploitable to execute code.

I believe it was on no pass Redis port, but I am not sure. It's strange that I do have password now and the problem persist.

I faced similar issue. After attack my acc sheet and PayPal details hacked..

I don't believe they have some access outside of mining BTC.
 
the attacker probably placed a backdoor (or multiple) to get access. see if there are any weird scripts, but can also have been injected in your existing php files etc.
you can use "find" on linux to check for files created or modified the last days.
 
I will postpone this as much as possible.



I believe it was on no pass Redis port, but I am not sure. It's strange that I do have password now and the problem persist.



I don't believe they have some access outside of mining BTC.
Did you check your crontab by the way (check crontabs for the root user as well as your non root users including apache)?
 
the attacker probably placed a backdoor (or multiple) to get access. see if there are any weird scripts, but can also have been injected in your existing php files etc.
you can use "find" on linux to check for files created or modified the last days.

There are no modified files or backdoors. At least I couldn't find them.

Did you check your crontab by the way (check crontabs for the root user as well as your non root users including apache)?

Yes and everything is fine there.
 
The problem is with an open port in the PHP. After reinstalling the PHP package and moving it to a different port from the default one, everything looks ok. I am testing since 4-5 days and there are no more problems so far.
 
can you provide more details? php-fpm or cgi? what port number you are referring?
thanks


The problem is with an open port in the PHP. After reinstalling the PHP package and moving it to a different port from the default one, everything looks ok. I am testing since 4-5 days and there are no more problems so far.
 
Back
Top