深入理解多種 PHP 系統函數的差別 (system, shell_exec, exec, passthru, popen, proc_open)
在戳 Webshell 時,時常會被 Disable Function 給雷,而網路上的各種 Cheat Sheet 也常常會教我們, Bypass Disable Function 的其他函數。這邊先不考慮 LD_PRELOAD 或是其他奇技淫巧的繞過方法,我們從最常見的 6 種可執行系統指令的 Function 開始,探討它們在正常使用時的不同。明明功能都差不多,甚至一樣,為什麼 PHP 要定義出這麼多的函數呢? ~~因為 PHP 是一個非常 Hacker Friendly 的語言,有各種方法可以讓駭客繞繞繞!~~~ 本文會比較 system、shell_exec、exec、passthru、popen 以及 proc_open 等 Function 的差異。 system 讓我們從 system 函數開始,觀察 Spec 可以看出,官方的敘述。 system — Execute an external program and display the output system 指令會執行外部程式,並且直接把結果輸出 (類似於 echo 到螢幕上),這邊也有一個特性就是,當程式每輸出一行,畫面結果就會刷新一次 (儘管程式可能還沒結束)。 system 指令有兩個參數,分別是 $command 以及 &$result_code。$command 應該不用特別敘述,而 &$result_code 會使用 Pass by reference 方式把 Linux 的 Return Status Code 給回傳到該參數。 ...