'How to remove appended PHP code to file using script
I've got multiple files that look like this:
<?php
if($_SERVER["SCRIPT_NAME"] != "/index.php"){ header("HTTP/1.0 403 Forbidden");echo base64_decode("PCF..redacted.HRtbD4=");die(); }
?>
<?php
/**
* actual PHP code starts here
*/
phpinfo();
I've got a script to clean these files which looks like this:
sed -i -e '/if($_SERVER["SCRIPT_NAME"] != "/index.php")/d' -e '/header("HTTP\/1.0 403 Forbidden");echo base64_decode(/d'
However, with this solution, my resulting "clean" file looks like this:
<?php
?>
<?php
/**
* actual PHP code starts here
*/
phpinfo();
So I'd like to remove the (now duplicate) PHP tags, I could just delete the line before and after my match but I want to make sure I'm deleting the duplicate tabs otherwise the scripts will stop working.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
