简体   繁体   English

使用sed从php文件中删除行

[英]Remove line from php file using sed

Website got hacked and it puts code at top line of every php page before the opening <?php tag, i want to use sed to remove it from all files with one command. 网站遭到黑客攻击,并且在打开<?php标签之前,将代码放置在每个php页面的顶部,我想使用sed通过一个命令将其从所有文件中删除。

It starts with 它开始于

<?php if(!isset($GLOBALS["\x61\156\x75\156\x61"]))

and ends with 并以

-1; ?><?php

I think this is caused by old version of mailpoet (wysija) wordpress plugin. 我认为这是由旧版本的mailpoet(wysija)wordpress插件引起的。 http://blog.sucuri.net/2014/10/wordpress-websites-continue-to-get-hacked-via-mailpoet-plugin-vulnerability.html http://blog.sucuri.net/2014/10/wordpress-websites-continue-to-get-hacked-via-mailpoet-plugin-vulnerability.html

I tried the answers of these two, but solutions isnt removing these lines for me. 我尝试了这两个答案,但是解决方案并没有为我消除这些限制。 I would appreciate any and all help as im no expert with unix commands. 我将不胜感激,因为我不是unix命令专家。

Mass removal of malicious line from php files 从php文件中批量删除恶意行

Removing a string in a PHP file with Start and End 使用Start和End删除PHP文件中的字符串

///EDIT ///编辑

Sample input i used, supposed to remove the line from file, but file stays same, doesnt print anything to terminal 我使用的样本输入,应该从文件中删除该行,但文件保持不变,不向终端打印任何内容

sed -i '1 s/^<\?php if(!isset($GLOBALS\[.*-1; \?>//' *.php

Once i have this command working i want to combine it with find command to run on whole server 一旦我运行了此命令,我想将其与find命令结合起来在整个服务器上运行

You could try this GNU sed command, 您可以尝试使用此GNU sed命令,

sed -r '1s/^<\?php if\(!isset\(\$GLOBALS\[.*-1; \?>//' *.php

Add inline edit option i to save the changes made. 添加内联编辑选项i以保存所做的更改。

sed -ri '1s/^<\?php if\(!isset\(\$GLOBALS\[.*-1; \?>//' *.php
find . -name "*.php" -print0 | xargs -0 sed -ri '1s/^<\?php if\(!isset\(\$GLOBALS\[.*-1; \?>//' *.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM