This solution will work on UNIX like systems. It will also work on Windows systems if you install Cygwin or something similar.
If the offending line is always the first line then "tail +2" would be the best way to get rid of it.
I would suggest that you redirect the output of "tail" to a new file so that you can do a bit of validation. Using a third file that contains just the malware line (e.g. malware_line.txt) would enable you to verify that you did not change your files in some unexpected way.
If the script outputs the following message you will want to manually inspect the file:
Files FILENAME.orig and FILENAME.check differ
Here is a script that will only strip the first line form files named *.php or *.PHP
(An alternate solution is given if the malware line exists elsewhere in the file but then then validation won't work.)
find . -name "*.php" -o -name "*.PHP" 2>/dev/null | while read FILENAME
do
BADFILE=0
# If the file contians the malware line, we want to remove it
grep -q 'eval(gzinflate(base64_decode' $FILENAME && BADFILE=1
if [[ $BADFILE != 0 ]]
then
echo "Processing: $FILENAME"
cp $FILENAME ${FILENAME}.orig # Save a backup copy of file
# Remove the offending "first" line.
tail +2 ${FILENAME}.orig > ${FILENAME}.fixed
##
## Alternatively, you could use "grep -v" here instead of the above "tail +2"
## to stip the malware line form anywhere in the file.
##grep -v 'eval(gzinflate(base64_decode' $FILENAME > ${FILENAME}.fixed
# Validate that we did not munge up our file
cat malware_line.txt ${FILENAME}.fixed > ${FILENAME}.check # Recreate the bad file
# Compare the original with the recreated file to prove that you only removed
# the malware line
diff -q ${FILENAME}.orig ${FILENAME}.check && cp ${FILENAME}.fixed $FILENAME
# Cleanup after ourselves
rm -f ${FILENAME}.check
fi
done