Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6537573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:37:57+00:00 2026-05-25T10:37:57+00:00

I am facing issues with my server as sometimes the malwares are adding their

  • 0

I am facing issues with my server as sometimes the malwares are adding their code at the end or start of the files. I have fixed the security loopholes to the extent of my knowledge. My hosting provider has informed that the security is adequate now, but I have become paranoid with the viral/malware activity on my site. I have a plan, but I am not well versed with Linux editors like sed or awk or gawk so help needed from your side. I can do this using my PHP knowledge but that would be very resource intensive.

Since malwares/virus add code at the start or end of the file (so that the website does not show any error), can you please let me know how to write a command which would recursively look into all .php files (I will use the help to make changes in other type of files) in parent and all sub-directories and add a particular tag at the start and end of the file, say, XXXXXX_START, and YYYYYY_END.

Then I need a script which would read all the .php files and check if the first line of the code is XXXXX_START and last line is YYYYYYY_END and create a report if any file is found to be different.

I will setup a cron to check all the files and email the report to me if any discrepancy found.

I know this is not 100% foolproof as virus may add the data after the commented lines, but this is the best option I could think of.


I have tried the following commands to add data at the start –

sed -i -r  '1i add here' *.txt

but this isn’t recursive and it adds line to only the parent directory files.

Then I found this –
BEGIN and END are special patterns. They are not used to match input records. Rather, they are used for supplying start-up or clean-up information to your awk script. A BEGIN rule is executed, once, before the first input record has been read. An END rule is executed, once, after all the input has been read. For example:

awk 'BEGIN { print "Analysis of `foo'" }
     /foo/ { ++foobar }
     END   { print "`foo' appears " foobar " times." }' BBS-list

But unfortunately, I could not decipher anything.

Any help on above mentioned details is highly appreciated. Any other suggestions are welcomed.

Regards,

Nitin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:37:57+00:00Added an answer on May 25, 2026 at 10:37 am

    You can use the following to modify the files (also creates backup files called .bak):

    find . -name "*.php" | xargs sed -i.bak '1iSTART_XXXX
    $aEND_YYYY'
    

    You could use the following shell script for checking the files:

    for f in `find . -name "*.php" -print`
    do
        START_LINE=`head -1 $f`
        END_LINE=`tail -1 $f`
    
        if [[ $START_LINE != "START_XXXX" ]]
        then
            echo "$f: Mismatched header!"
        fi
    
        if [[ $END_LINE != "END_YYYY" ]]
        then
            echo "$f: Mismatched footer!"
        fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing issues whereby I can't open a SQLCE 4 database using SQL Server
I have Apache running on a public-facing Debian server, and am a bit worried
After installing the new server, I am facing an issue. I have lot of
I am facing issues in configuring JPA with Spring 3 in JBoss 4.2.2 server.
I am using Appweb server (mini http server) and facing an issue while opening
I am facing some issues while serializing objects (I am using JBoss Drools, and
Well, since I am facing some issues with OAuth implementation, I decided to go
I'm working using scriptaculous library. However I'm facing some issues with inclusion of the
I am new to MVC and facing one issue. I have a xml file
I am facing issue of the WCF Services on staging server. The same service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.