dst8922 2011-06-30 15:12
浏览 71
已采纳

如何使用html表单元素而不是命令行调用php脚本?

I admin several websites which have just been subject to the hack outlined here: http://frazierit.com/blog/?p=103

I need to clean the code that has been injected into all the php files.

User Crystaldawn has made a clean up script available here http://crystaldawn.net/fix_hack but it needs to be run via command line which I am unfamiliar with.

QUESTION: Is it possible to execute this script (below) using an html form submit button or similar? And if so, how?

Thanks in advance, really appreciate any help, I need to clean up 8 sites and this could save me (and others) many many hours.

<?php
//Create back files?
define('CREATE_BACKUPS', FALSE);

if (!is_dir($argv[1]))
{
   echo "You must enter a valid path such as /home/infected_dir or infected_dir for this script to function.
";
   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.
";
      }
   }
}

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'];
}
?>
  • 写回答

3条回答 默认 最新

  • doucheng9304 2011-06-30 15:15
    关注

    It's just a script. stuff it into your document root somewhere as "cleanupscript.php", and then point your browser at it:

    http://yoursite.com/cleanupscript.php

    no need for forms or command line access.

    Just put $argv[1] = '/path/to/your/site/document/root'; at the start of the script, so it's not dependent on command line arguments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序