Iframe code injection
After a long days I am back for blog post. Last one month I was very much irritated with the problem occurred in some of my client website. In a Sunday morning while I was sleeping one of my client ranged me and asked me to check her website as she got a mail from google that her website is spreading malware. I got confused as I had never faced this kind of problem. I started checking the website. But the antivirus in my Laptop didn’t allowed me to open the site at all. Then I decided to go to my office to check the situation.
In my office I checked the site thoroughly(OMG, I was able to open the site in my office). I found iframe code with hidden visibility was inserted in some pages. To be more specific index pages. I checked all the index pages in office PC, deleted the infected pages in the server and uploaded the pages from PC. Checked, cleaned all the html, php, temporary files. Almost near about afternoon I was back to my home while thinking how this happened.
Next Morning after arriving in the office I started checking the website and I found it was again infected by the hidden iframe. Site url was different as earler it was .cn and next day it was .ru I was upset about how to fix the things. Believe me or not in the last one month this site got infected 27 times. Our team had experienced the same attack for 5 more site. It was a horrible experience for us.
We had done lot of googleing to find out the preventive measurement. We found out lots of information regarding this. Some of them are good and some of them are misleading too. So here I like to point out some effective ones only.
- You should have good antivirus installed in your system from where you access web. I am using avast free edition and it works fine for me.
- Please check your websites on a regular basis. If you see if any web page with a blank section in the top them be almost sure that it is infected. Your antivirus should give you warning.
- If you find any of your website get infected then start following the next steps.
- First of all scan your machine with the antivirus. A boot time scan is more preferable.
- Replace all the pages in the website using a local copy from your system. If the web site is too big to repalce then try to repalce all the pages with name index. Then check the site again.
- Once the site is cleaned change the ftp details for the site and if possible do the same for the other sites whose details are kept in your ftp application.
- Keep checking the site in a short span of interval.
You should also check your site in google too. If google find out some problem with your site they may have shown a warning message like “This site may harm your computer”. Another way to check your site is
http://www.google.com/safebrowsing/diagnostic?site=http://www.yourdomain.tld
If you find that google is showing the warning message for your site you can request Google for a recheck via Google Webmaster Tool. But you should check the site twice after cleaning and then request for review.
However I have designed a code in php for checking mainly the index pages in the website. Here is the code.
[code lang=”php”]
“;
$dir_handle = @opendir($path) or die(“Unable to open $path”);
echo “Directory Structure of $WebPath
“;
navigate($dir_handle, $path, ”);
function navigate($dir_handle,$path, $WebPth)
{
global $WebPath, $content_pattern;
echo “
- “;
- “;
echo ““.$WebPth.$file.”
“;
$handle = @fopen($dir, “r”);
if ($handle)
{
while (!feof($handle))
{
$content = fgets($handle);
if(stristr($content, $content_pattern))
{
$test = stristr($content, $content_pattern);
echo $test.”
“;
$ChcekFlag = TRUE;
}
}
}
fclose($handle);
if($ChcekFlag)
{
echo “Infected
“;
}
else
{
echo “Clean
“;
}
echo “
while (false !== ($file = readdir($dir_handle)))
{
$dir = $path.’/’.$file;
if(is_dir($dir) && $file != ‘.’ && $file !=’..’ )
{
$handle = @opendir($dir) or die(“undable to open file $file”);
$WebRef = $file.’/’;
navigate($handle, $dir, $WebRef);
}
elseif($file != ‘.’ && $file !=’..’)
{
if(preg_match(‘/^index+/’,$file))
{
$ChcekFlag = FALSE;
echo “
“;
}
}
}
echo “
“;
}
?>
[/code]
you can put this code in the root level of your website (in www or public_html or httpdocs). Browsing this page will show all the index pages with status of it.
Current I am working upon extending the code so that it can clean the infected pages automatically. Hopefully I will post it within few days.
WOW THATS GRATTT
Hi,
Have added to my blog
http://www.ygoel.com/
the write-up & all the photographs of the Kolkata Bloggers Meet 2009.
Do take some time to visit and do not forget to put down your inputs for the same.
Regards & Love,
Yours ever in blogging,
Yogesh Goel
ygoel.com
All credits to you – same problem happened to me too… & now I am exhausted. I uploaded your file at my root dir
but its giving error
Checking files for IFRAME Infection
Directory Structure of http://www.ampiflow.com/
Fatal error: Call to undefined function list_dir() in /home/lena9164/public_html/remove.php on line 22
http://www.ampiflow.com/remove.php here is file,
Could you please suggest what could be prob ?
Many Many thanks n advance
I am really sorry for the mistake. the function list_dir() should be changed with navigate(). I have already made that correction. You can correct your code as:
On line 22
list_dir($handle, $dir, $WebRef);
replace with –
navigate($handle, $dir, $WebRef);
Thanks for pointing out such a crusial mistake.
Superb , Thanks Susenjit.. Any idea how they get access to our ftp ?
Superb , Thanks Susenjit.. Any idea how they get access to our ftp ? Is this any trojan or spam … do you recommend any tool or anti-virus to stay away from this ?
Your help solution is outstanding.
I am not sure about how they get access of ftp details but there may be possibilities. The trojan [HTML:Iframe-inf] either access the file where the ftp application stores ftp access details of different site or they hack these information at the time when we type them while connesting via ftp application.
Since I am using avast free edition(version 4.8) it aborts the connection while opening a webpage with iframe. Also it detects the malware download.
I never would have thought of that
[…] your site using Google Diagonestic tool for safe browsing mentioned in my earlier post – Iframe code injection. In this kind of attack none of your web pages get infected but your .htaccess file gets modified […]
I seriously enjoyed reading through this specific post. I am going to be coming back in order to read even more fascinating opinions. With thanks.
I’m a huge fan of this website and I read it regularly. Keep up the good work!