스크립트는 다음과 같습니다.
<?php
//Create back files?
define('CREATE_BACKUPS', FALSE);
if (!is_dir($argv[1]))
{
echo "You must enter a valid path such as /home/apresv/public_html or apresv/public_html for this script to function.\n";
exit;
}
//Search the path for all php files, opening each one, and checking to see if it's infected
//First, get an array list of all valid .php files.
$files = listdir($argv[1]);
foreach ($files as $filename)
{
//We only need to check php files, so we add that here
if (file_extension($filename) == 'php')
{
//This is a php file so lets check it to see if it's infected.
$contents = file_get_contents($filename);
$backup = $contents;
//There will always be 2 opening tags in an infected file and since the hack is always at the top, it's easiest to test for this right away.
$test = between('<?php', '<?php', $contents);
//This particular hack likes to use toolbarqueries so we test to see if our chunk is an infected chunk. If your website uses this url somehow, then add extra if statements as necessary.
if (after('toolbarqueries', $test))
{
//This chunk is infected. So lets replace it and resave the file.
$contents = str_replace('<?php'.$test.'<?php', '<?php', $contents);
//Now save it! Woohoo!
file_put_contents($filename, $contents);
if (CREATE_BACKUPS)
{
file_put_contents($filename.'.orig', $backup);
}
echo "$filename has been cleaned.\n";
}
}
}
function after ($this, $inthat)
{
if (!is_bool(strpos($inthat, $this)))
return substr($inthat, strpos($inthat,$this)+strlen($this));
};
function after_last ($this, $inthat)
{
if (!is_bool(strrevpos($inthat, $this)))
return substr($inthat, strrevpos($inthat, $this)+strlen($this));
};
function before ($this, $inthat)
{
return substr($inthat, 0, strpos($inthat, $this));
};
function before_last ($this, $inthat)
{
return substr($inthat, 0, strrevpos($inthat, $this));
};
function between ($this, $that, $inthat)
{
return before($that, after($this, $inthat));
};
function between_last ($this, $that, $inthat)
{
return after_last($this, before_last($that, $inthat));
};
// USES
function strrevpos($instr, $needle)
{
$rev_pos = strpos (strrev($instr), strrev($needle));
if ($rev_pos===false) return false;
else return strlen($instr) - $rev_pos - strlen($needle);
};
function listdir($dir='.') {
if (!is_dir($dir)) {
return false;
}
$files = array();
listdiraux($dir, $files);
return $files;
}
function listdiraux($dir, &$files) {
$handle = opendir($dir);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$filepath = $dir == '.' ? $file : $dir . '/' . $file;
if (is_link($filepath))
continue;
if (is_file($filepath))
$files[] = $filepath;
else if (is_dir($filepath))
listdiraux($filepath, $files);
}
closedir($handle);
}
function file_extension($filename)
{
$info = pathinfo($filename);
return $info['extension'];
}
?>
cron을 통해 이를 실행하려고 하면 "이 스크립트가 작동하려면 /home/apresv/public_html 또는 apresv/public_html과 같은 유효한 경로를 입력해야 합니다.
CRON JOB을 통해 실행하려면 어떻게 해야 합니까?
감사해요!
답변1
CRON을 사용하여 스크립트를 실행하는 기본은 파일을 실행 가능하게 만드는 것입니다. 파일에 대해 설명하려면 php
인터프리터 명령이 있는 경로를 파일에 제공해야 합니다 shebang
.여기) 스크립트의 맨 위에 배치해야 합니다.
따라서 다음을 수행해야 합니다.
$ chmod +x script.php
$ sed -i '1 i\#!/usr/bin/php' script.php #This is to insert the shebang
따라서 CRON을 구성할 수 있습니다.
$ crontab -e
* * * * * /path/to/script.php
메모:물론 스크립트가 작동하는지 확인해야 합니다.