Created
July 6, 2015 16:02
-
-
Save eni23/503e509610838dca3b10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DB_USER', 'dbuser'); | |
define('DB_PASSWORD', 'dbpass'); | |
$db = mysql_connect('localhost', DB_USER, DB_PASSWORD); | |
mysql_select_db("dbname",$db); | |
$result = mysql_query("SELECT ID, post_content FROM wp_posts"); | |
while ($row = mysql_fetch_array($result)) { | |
$match=strpos($row[1],"<script"); | |
if ($match){ | |
echo "Post with ID {$row['ID']} seems infected, cleanup\n"; | |
$cleaned = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $row[1]); | |
$escaped=mysql_real_escape_string($cleaned); | |
$query="UPDATE wp_posts SET post_content='{$escaped}' WHERE ID={$row[0]} LIMIT 1"; | |
$res=mysql_query($query); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment