Web (PHP) Hacking, Risk Code Checker

It was created to monitor the installation of malicious PHP through server hacking and to make it easy to check for dangerous code.

  1. Write the code in the server account and upload it.
    <?
    /**
    * Name: Kilho's PHP Diagnosis
    * Author: Kilho Oh ([email protected])
    * Author URI: http://kilho.net/
    */
    class TDiagnosis
    {
    public $dir;public function __construct()
    {
    $this->dir = $_SERVER['DOCUMENT_ROOT'].'/';
    }private function SeekFile($dir, &$files)
    {
    $hnd = opendir($dir);
    while (false !== ($entry = readdir($hnd)))
    {
    if(in_array($entry, array('.', '..'))) continue;if(is_dir($dir.$entry) && !in_array($entry, array('.', '..')))
    {
    $this->SeekFile($dir.$entry.'/', $files);
    }else{
    if(!in_array(substr($entry, strrpos($entry, '.')+1), array('php', 'inc', 'html', 'htm', 'php3'))) continue;$file = $dir.$entry;
    if(!in_array($file, $files)) $files[] = $file;
    }
    }
    closedir($hnd);
    }private function Diagnosis($files)
    {
    $suspicion = array();
    $loop = 0;
    do {
    $file = $files[$loop];
    $loop++;if($file == $_SERVER['SCRIPT_FILENAME']) continue;$data = file_get_contents($file);
    $data = preg_replace('//*(.*?)*//is', '', $data);
    $data = preg_replace('///*(.*)n/', '', $data);if(preg_match('/(^|s|?php3|[?])(eval|system|exec)s*(/i', $data))
    $suspicion[] = $file;
    } while ($loop < count($files));return $suspicion;
    }public function Run()
    {
    $files = array();
    $this->SeekFile($_SERVER['DOCUMENT_ROOT'].'/', $files);
    return $this->Diagnosis($files);
    }
    }/**
    * Main
    */
    $diagnosis = new TDiagnosis;$result['host'] = $_SERVER['HTTP_HOST'];
    $result['suspicion'] = $diagnosis->run();
    
    echo json_encode($result);
    ?>
    
  2. Click the Download button below to download the monitoring program.
  3. Run the downloaded program and enter the URL created in (1) in URL (s).
  4. If you click Diagnose, the name of the suspicious file will be shown below.
  5. If you have any unusual code, be sure to check the file.

 

  Download

arrow