我的朋友,答案是在str\\u repl()的正则表达式中吹出的-使用开始和结束标记从post\\u内容中删除恶意软件脚本
首先,我在数据库中找到一些特定帖子,其中包含恶意软件的示例,以获取其开头字符串,在我的情况下:
<script>;\',\'OPR\'
然后,我编写了以下脚本,以提供字符串的精确长度,并查看它在数据库中的样本行上是否稳定:
ignore_user_abort(true);
set_time_limit(30);
$path = $_SERVER[\'DOCUMENT_ROOT\'];
require( $path.\'/wp-load.php\' );
$test_posts = array(1,15002,9664,3342);
foreach ($test_posts as $post){
$post = get_post($post);
$content = $post->post_content;
$strlen = strlen($content);
// to delete a script tag... preg_replace(\'/(<script>.+?)+(<\\/script>)/i\', \'\', $string);
// starting virus text is <script>;\',\'OPR\' must use backslash to escape the folling characters: \\ ^ . $ | ( ) [ ] * + ? { } ,
$new_content = preg_replace(\'/(<script>;\\\'\\,\\\'OPR\\\'.+?)+(<\\/script>)/i\', \'\', $content);
$new_strlen = strlen($new_content);
$difference = $strlen - $new_strlen;
echo \'Post \'.$post->ID.\': \'.$strlen.\'-\'.$new_strlen.\'=<b>\'.($difference).\'</b><br>\';
}
echo \'<br>Done.\';
我在所有条目中都看到了相同的数字:2409。因此,我将2409插入到第二个脚本中,该脚本实际执行后期更新:
ignore_user_abort(true);
set_time_limit(90);
$path = $_SERVER[\'DOCUMENT_ROOT\'];
require( $path.\'/wp-load.php\' );
$args = array(
\'post_type\' => array(
\'post\',
\'page\',
\'revision\',
\'item\',
\'wpsl_stores\',
\'nav_menu_item\',
\'accordion_menu\',
\'et_pb_layout\',
\'scheduled-action\',
\'wpsl_stores\',
\'popup_theme\',
),
\'post_status\' => array(\'publish\', \'draft\', \'inherit\'),
\'posts_per_page\' => -1,
);
$posts = get_posts($args);
echo \'Post count is \'.count($posts).\'<br>\';
$post_of_interest = 1;
foreach($posts as $post){
$content = $post->post_content;
$strlen = strlen($content);
// starting virus text is <script>;\',\'OPR\'
$new_content = preg_replace(\'/(<script>;\\\'\\,\\\'OPR\\\'.+?)+(<\\/script>)/i\', \'\', $content);
$new_strlen = strlen($new_content);
if (($strlen - $new_strlen) == 2409){ // I know my target string has a specific number of characters
echo \'<br><b>*** HIT \'.$post->ID.\' ***</b><br>\';
} else {
echo \'-\';
}
if($post->ID == $post_of_interest){
echo \'<br>\'.$post_of_interest.\' original strlen=\'.$strlen.\' New strlen=\'.$new_strlen.\' Difference=\'.($strlen - $new_strlen).\'<br>\';
}
$args = array(
\'ID\' => $post->ID,
\'post_content\' => $new_content,
);
wp_update_post( $args );
}
echo \'<br>Done.\';
希望这对别人有帮助。