Question

Some process is changing index.php and .htaccess file contents as well as permissions as soon as we change the owner to www-data

We are encountering a problem on our digital ocean droplet. we have a Laravel application running on the droplet but some malicious process is creating folders such as (wp-admin, wp-includes) and php files with obfuscated code inside. This process is also modifying .htaccess and index.php files as soon as we change the permission to www-data.

we used auditctl for monitoring the file changes and also used rkhunter for scanning rootkits.

so far we were not able to trace down the process.

It would be really helpful if we can find out which process is creating and modifying those files.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
December 30, 2024

Heya,

This means there is a security breach somewhere either in your droplet or in your code from where access is granted. Given that files are being created, I would say it’s somehow getting access to your Droplet.

See if there are any accounts on the Droplet that have access to those files. See if you have any outdated software on your Droplet. Also if you don’t find the source of this even if you make changes now the access to your system will still be there.

You can also try to create a new droplet and migrate only your website there to see if this will resolve the issue. All in all, the best way would be to track down exactly what it’s doing this and stop it’s access but it’s tricky.

alexdo
Site Moderator
Site Moderator badge
December 31, 2024

Heya, @61cada0754504c92b74676e29079ea

You can use top, htop, or ps to look for processes running as www-data or any unexpected processes:

ps aux | grep www-data ps aux | grep php
  • If you see any unfamiliar or suspicious commands, note the PID and inspect their details:
ls -l /proc/<PID> cat /proc/<PID>/cmdline

Also you can use inotifywait to monitor changes in your directories:

sudo apt install inotify-tools sudo inotifywait -m -r /var/www/your-laravel-app --format '%w%f %e' -e modify,create,delete

This will show live updates of which files are being modified or created.

Also look for unauthorized SSH keys or reverse shell scripts:

cat /root/.ssh/authorized_keys 
cat /home/www-data/.ssh/authorized_keys

and check for suspicious files in /tmp, /var/tmp, or /dev/shm.

Hope that this helps!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.