Question

Can not delete or edit file.

Hello, I am working on a hacked wordpress site. and i have seen many malicious content inside. i have deleted most of those files except one. i can not delete that root file index.php or even can not edit that. can not change the file permission too. changing file permission, bring back the previous permission.

what should i do?

Thank you

Subscribe
Share

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

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.

A quick and rather superficial solution that worked for me:

  1. change the “index.php” file rights as previously explained.
  2. rename the “html” folder, for example to “html_temp” (be careful, your site and everything on it will be off and not operational as long as there is no “html” folder!!)
  3. delete the file “index.php”
  4. upload the proper “index.php” file
  5. rename “html_temp” folder back to “html”

I assume this specific hacked code searches for a root path starting from “html”, thus if you “break” this path it will not run. Consequently, it seems that if you manage to properly replace the “index.php” file you will be actually “protected” by the hacked code, since that proper file will eventually look immutable. Of course this assumption may not cover all cases.

Hope it helps someone in the thread.

Athanasios

I’ve had exactly the same problem. Ended up downloading my wp-content and wp-config to my pc then uploaded all other wordpress files to a new location because, when I deleted every single file and folder from the root, index.php and corrupt htaccess file still reloaded, so nothing on my website included hacked files. I found a cron job with (Ha ha ha) in the title, so deleted that. But that didn’t make any difference to the index.php. Permissions couldn’t be changed either. And to finally delete pyrocrafts.co.uk from its original location, I had to rename it before I was able to delete the folder. Very strange and worrying that something is still lurking in my home directory. Anyway pyrocrafts.co.uk is working well in it’s new home … for now I shall download a backup to a USB stick

@bobbyiliev Thank you. We didn’t get any error any time so it might be recreated after it is deleted. The .htaccess file can be deleted but is being recreated as a hidden file within 3 or 4 seconds.

@bobbyiliev the .htaccess file now been deleted but the index.php is still there. and again the .htaccess come with the following rules.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^(.*)\/(benzylpenicillin)\/([0-9]+)_([0-9]+)\/(.*)$ ?benzylpenicillin$4=$3&%{QUERY_STRING}[L]
</IfModule>

This comment has been deleted

Thank you @bobbyiliev I have checked the cronjob, but nothing found. wordfence works find, except removing bad code from that index.php file. i have changed the .htaccess file, but after update, it rewrite again autometically and the following line added.

#----------------------------------------------------------------------
# Rewrite from HTTP to HTTPS - if you want to use it, comment it out
# ----------------------------------------------------------------------
#<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*)\/(benzylpenicillin)\/([0-9]+)_([0-9]+)\/(.*)$ ?benzylpenicillin$4=$3&%{QUERY_STRING}[L]
#</IfModule>```

how this is happening autometically?

Hello,

Probably the file is immutable.

You could check that by running this command:

lsattr

If you see an i tag in the attribures, then you could run the following to remove the immutable tag:

chattr -i index.php

Then you should be able to delete the file.

Hope that this helps! Bobby