Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete specific line from php file

Tags:

php

wordpress

My site got hacked and at every first line of php file i have 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 impossible to open 1 by 1 and delete this line. Is there a way to delete them all at once?

I read something about some sed functions but i do not know how to use it and after some discussion i know that will not solve my problem so now i am looking a way how to scan and remove viruse from my files. Any help would be okay.

like image 926
Aleksa Ristic Avatar asked Jul 29 '26 21:07

Aleksa Ristic


1 Answers

If your site got hacked you REALLY should not try to clean the source code they injected!. It is very likely that you will forget something and you may spread malware or whatever to the visitors of your WordPress site. Also try to figure out why you got hacked and fix the hole.

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

Here is what you can do:

1) Contact your provider and ask them to setup the latest clean backup

2) Setup your own latest clean backup

3) If you really have no backup (which is very bad) do the following:

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

Simple deleting the first line of each file is most probably not enough. However there are solutions to this:

Batch file to delete first 3 lines of a text file

Delete certain lines in a txt file via a batch file

Note: With an IDE like Netbeans or IntelliJ you can do a search / replace on a huge number of PHP files. This might also help if step three is the only option.

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

like image 65
Blackbam Avatar answered Aug 01 '26 11:08

Blackbam