I have a malware java script that was added to the end of every post. I tried using an SQL statement in phpMyAdmin. Here is a shortened version of that:
SET @virus = "<script>var _0x2cf4=['MSIE"+CHAR(59)+"','OPR','Chromium','Chrome','ppkcookie','location','https://www.wow-robotics.xyz','onload','getElementById'...(and a lot more obfuscated script)...;
UPDATE
wp_posts
SET
post_content =
REPLACE
(
post_content,
@virus COLLATE utf8mb4_unicode_520_ci,
''
);
This was not initially successful because many false matches caused deletions all over the website. I didn't have time to find out why, so I shortened the search text to be only the beginning of the script, which broke the malware and rendered it merely ugly. This got me out of trouble, but obviously it's not the best solution.
How should I do this? I have tried to tokenize the post content, using the text of the malware script as the token:
<?php
ignore_user_abort(true);
set_time_limit(30);
$path = $_SERVER['DOCUMENT_ROOT'];
require( $path.'/wp-load.php' );
$post_table = $wpdb->prefix . 'posts';
$meta_table = $wpdb->prefix . 'postmeta';
$starting_virus_text = "<script>['MSIE;','OPR','Chromium','Chrome','ppkcookie','location','https://www.wow-robotics.xy";
$args = array(
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => -1,
);
$posts = get_posts($args);
echo 'Post count is '.count($posts).'<br>';
foreach($posts as $post){
$new_content = strtok($post->post_content, $starting_virus_text);
if ($post->ID == 192) { // my home page, just for example
echo 'POST 192<br><pre>';
var_dump($post->post_content);
}
if (strlen($new_content) > 20){
echo $new_content;
die;
}
}
echo '<br>Done.';
?>
This was also unsuccessful. The token is never found in the post content, even though it is there. Should I do a character-ny-character type examination and store post_content in an intermediate variable? Any advice is appreciated.