2011-06-30 4 views
1

私はここで概要を説明したハックの対象となったいくつかのウェブサイトを管理しています:http://frazierit.com/blog/?p=103コマンドラインではなくhtmlフォーム要素を使ってPHPスクリプトを呼び出す方法は?

すべてのPHPファイルに埋め込まれたコードを削除する必要があります。

ユーザーCrystaldawnはここで利用可能なクリーンアップスクリプトを作成しましたhttp://crystaldawn.net/fix_hackしかし、それは私がよく慣れていないコマンドラインで実行する必要があります。

質問: htmlフォーム送信ボタンなどを使用してこのスクリプトを実行することはできますか?そしてもしそうなら、どうですか?

おかげさまで、本当に助けていただきありがとうございます。私は8つのサイトを整理する必要があり、これは私(と他の人)に何時間も節約することができます。

<?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.\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']; 
} 
?> 

答えて

1

これは単なるスクリプトです。どこかに「cleanupscript.php」としてあなたのドキュメントルートへのもの、それをして、それをあなたのブラウザをポイント:

http://yoursite.com/cleanupscript.php

フォームまたはコマンドラインへのアクセスは必要ありません。

$argv[1] = '/path/to/your/site/document/root';をスクリプトの先頭に置くだけで、コマンドライン引数には依存しません。

+1

ありがとう、これは私のために完全に動作します。私は、ジョージカミンズのコメントは適切であると付け加えるべきですが、特に、クリーンアップが完了するとすぐにパーミッションとファイルの削除に関しては関係しています。助けてくれてありがとう。 – theothersimon

0

$_POSTにフォームデータがあります。したがって、フォームを作成してactionをスクリプトに設定すると、すべてのフィールドが$_POSTにあります。

そこから、あなたのスクリプトを修正できるはずです。

0

現在のフォームでは、このスクリプトをWebサーバー経由で効果的に実行することはできません。

  1. スクリプトは、コマンドライン引数への参照である$ ARGVのを、使用しています:2つの理由があります。 Webサーバー経由で(HTMLページとして)スクリプトを実行すると、変数には値が設定されません。

  2. スクリプトはファイルを変更します。 Webサーバーユーザーには、これらのファイルを編集する権限がある場合とない場合があります。

は、コマンドラインからこのスクリプトを実行するシェルを開いて、あなたがきれいにしたいディレクトリがある

php <script_name> <path_to_direcotry> 
<script_name>がCrystaldawnのスクリプトの名前です

、および<path_to_directory>を実行します。

あなたは、コマンドラインを介してこれを実行できない場合は、あなたのような何かに$ ARGVへの参照を変更する必要があります。このようなスクリプト

$_GET['directory']; 

およびコール:

http://yourwebsite/script_name.php?directory=/home/www/ 

た場合をこのメソッドを使用すると、検証やエスケープを追加して、誰かが無効または危険な値を入力できないようにします。directory.

第2に、ch Webサーバーユーザーが指定したディレクトリ内のファイルを編集できるように、ファイルのアクセス許可を確認します。

関連する問題