Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Get file list
- $filelist = "all_js_files_list.txt";
- //$filelist = "test_js_files.txt";
- $log_file = "js_antivirus.log";
- $fp = fopen($filelist, "r");
- $fp_log = fopen($log_file, "a");
- if( $fp )
- {
- fwrite($fp_log, "\n\n=========================\n");
- fwrite($fp_log, "Start JS antivirus clean\n");
- fwrite($fp_log, date("Y-m-d H:i:s")."\n");
- fwrite($fp_log, "=========================\n");
- while( ($filename = fgets($fp)) !== false )
- {
- $filename = trim($filename);
- if( file_exists($filename) )
- {
- // Run antivirus
- $content = file_get_contents($filename);
- $res = virus_clear($content);
- if( $res )
- {
- file_put_contents($filename, $content);
- echo "$filename - OK\n";
- fwrite($fp_log, "$filename - OK\n");
- }
- else
- {
- echo "$filename - not found\n";
- fwrite($fp_log, "$filename - not found\n");
- }
- }
- else
- {
- echo "File not exists: $filename\n";
- fwrite($fp_log, "File not exists: $filename\n");
- }
- }
- if (!feof($fp))
- {
- echo "Error: unexpected fgets() fail\n";
- fwrite($fp_log, "Error: unexpected fgets() fail\n");
- }
- fclose($fp_log);
- fclose($fp);
- }
- function virus_clear(&$js)
- {
- $js_lenght = strlen($js);
- $max_length = min($js_lenght, 2000);
- $js_slice = substr($js, 0-$max_length);
- $keys = array();
- $found = false;
- if( preg_match_all("#([\d\w]+)\(([\d\w]+)\(([\d\w]+)\[\d+\]\)\);#is", $js_slice, $match) && isset($match[3][0]) )
- {
- foreach( $match[0] as $m_i=>$fns_full )
- {
- $fns1 = $match[1][$m_i];
- $fns2 = $match[2][$m_i];
- $var = $match[3][$m_i];
- if( preg_match("#var\s$var=\[[\"'\d,]{100,}\];#is", $js_slice, $match2) && isset($match2) )
- {
- if( preg_match("#function\s$fns2\([\d\w]+\){return\s([\d\w]+)\(([\d\w]+)#is", $js_slice, $match3) && isset($match3) )
- {
- $keys = array(
- $fns_full,
- 'function '.$fns1,
- 'function '.$fns2,
- $match2[0],
- $match3[0],
- 'function '.$match3[1],
- 'function '.$match3[2]
- );
- }
- }
- if( $keys )
- {
- $pos = array();
- foreach( $keys as $key ) $pos[] = strpos($js_slice, $key);
- $pos = min($pos);
- //$lenght = strlen($js_slice)-$pos;
- // Caught!
- //if( $pos && $lenght <= $max_length )
- //{
- $js_slice = substr($js_slice, 0, $pos);
- $found = true;
- //}
- }
- }
- }
- if( $found )
- {
- $js = substr($js, 0, 0-$max_length) . $js_slice;
- }
- return $found;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement