Webpage virus cleanup method

Source: Internet
Author: User

Does your webpage often add Trojan addresses in the background of files such as php, asp, html, and js for no reason? I used to have a website like this, so I wrote this code in hate. Although this article is a waste of resources, it is always better than manually clearing it, next I will talk about how the program clears viruses.

First, read the $ checkFile file to determine whether an article is infected. If yes, all the files in the txt file path in the $ savafile variable will be executed, clear the virus list by your infecFile.

<? Php
Class clear_virus {
// Public $ content;
Public $ infectFile named 'virus.txt '; // virus file list file
Public $ savefile = "save.txt"; // list of virus files
Public $ timep specify 'time.txt '; // The time when some records are cleared.
Public $ checkFile = 'E. php'; // here is the setting
Public $ run = 0;
Public $ virus_type;
Public $ replace;
Public $ filepath;
Public $ tag = 0;

Function open_file (){
$ This-> read_virus ();
$ This-> check_File ();
If ($ this-> run ){
$ This-> update_time ();
$ This-> read_file ();
Foreach ($ this-> filepath as $ tmppath ){
If (file_exists ($ tmppath )){
$ Tmp_file = file_get_contents ($ tmppath );
Print_r ($ this-> virus_type );
For ($ I = 0; $ I <sizeof ($ this-> virus_type); $ I ++ ){
If (strrpos ($ tmp_file, $ this-> virus_type [$ I])! = False ){
$ Tmp_file = str_replace ($ this-> virus_type [$ I], '', $ tmp_file );
$ This-> tag = 1;
}
}
If ($ this-> tag ){
$ Handle = fopen ($ tmppath, 'w ');
Fwrite ($ handle, $ tmp_file );
Fclose ($ handle );
Unset ($ tmp_file );
}

} Else {
;
}
}
}
}

Function check_File (){
If (file_exists ($ this-> checkFile )){
$ Temp = file_get_contents ($ this-> checkFile );
Echo $ temp;
Foreach ($ this-> virus_type as $ v_tmp ){
If (strrpos ($ temp, $ v_tmp )! = False ){
$ This-> run = 1;
Break;
}
}
Echo $ this-> run;
Unset ($ temp );
} Else {
$ This-> show_error (5 );
}
}

Function update_time (){
If (file_exists ($ this-> timep )){
$ Tmp_time = date ("Y-m-d H: I: s"). chr (13). '| ';
$ Tmp_fp = fopen ($ this-> timep, 'a + ');
Fwrite ($ tmp_fp, $ tmp_time );
Fclose ($ tmp_fp );
}

}


Function read_File (){
If (file_exists ($ this-> savefile )){
$ This-> content = file ($ this-> savefile );
If (is_array ($ this-> content )){
$ This-> filepath = $ this-> content;
} Else {
$ This-> show_error (3 );
}
} Else {
$ This-> show_error (4 );
}
}


Function read_virus (){
If (file_exists ($ this-> infectFile )){
$ This-> replace = file ($ this-> infectFile );
If (is_array ($ this-> replace )){
$ This-> virus_type = $ this-> replace;
} Else {
$ This-> show_error (1 );
}
} Else {
$ This-> show_error (2 );
}
}


Function show_error ($ number ){
$ Array = array (
'1' => 'the virus file cannot be read! ',
'2' => 'the virus file list does not exist! ',
'3' => 'the file list is not saved ',
'4' => 'no files saved for clean ',
'5' => $ this-> $ checkFile. 'no longer exists. Please set the virus infection file'
);
Echo $ array [$ number];
}

}
$ Virus = new clear_virus;
$ Virus-> open_file ();
?>
Finally, declare that the original site conversion from www.111cn.cn/phper/php.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.