Remove specific line from php file

My site is hacked and on every first line of the file php

I have a line:

<?php $knitglx = '<%G]y6d]281Ld]245]K2

... $knitglx=$fmfqhx-1; ?><?php

(it is very long). Since I am using Wordpress there are millions of files and it is not possible to open 1 by 1 and delete this line. Is there a way to remove them all at once?

I read something about some of the features sed

, but I don't know how to use them, and after some discussion, I know it won't solve my problem, so now I'm looking for a way to scan and remove viruses from my files. Any help would be ok.

+3


source to share


1 answer


If your site has been hacked, you REALLY shouldn't try to clean up the source code they entered! ... It is very likely that you will forget something and you may be distributing malware or something else to your WordPress site visitors. Also try to figure out why you were hacked and fix the hole.

Make sure to delete all files from the server and change all your passwords (FTP, WordPress, etc.).

Here's what you can do:

1) Contact your ISP and ask for the latest clean backup

2) Create your own latest backup

3) If you really don't have a backup (which is very bad), follow these steps:



  • Make a fresh install of WordPress.
  • download your wp content folder and check it for any malicious code.
  • download your database and check for malicious code
  • put the clean code / database into your WordPress installation.

Simply deleting the first line of each file is probably not enough. However, there are solutions for this:

Batch file to remove first three lines of text file

Remove specific lines in txt file via batch file

Note. In an IDE like Netbeans or IntelliJ, you can search / replace on a huge number of PHP files. It can also help if step three is the only option.

The third option is not good because it means a lot of work ... good luck!

+2


source







All Articles