# Insecure Deserialization

## PHP

{% embed url="<https://book.hacktricks.xyz/pentesting-web/deserialization#php>" %}

You can use phpggc to generate payloads.

{% embed url="<https://github.com/ambionics/phpggc>" %}

## Deserialization via PHAR archive

<https://i.blackhat.com/us-18/Thu-August-9/us-18-Thomas-Its-A-PHP-Unserialization-Vulnerability-Jim-But-Not-As-We-Know-It.pdf>

If you can upload a file that is a valid PHAR:&#x20;

* Phar file&#x20;
* Tar file&#x20;
* Zip file&#x20;
* Image polyglot

Then if that file is opened with the `phar://` protocol, then insecure deserialization can occur.

So basically, to execute the attack, you need two things:&#x20;

1. Uploaded valid phar archive with malicious content&#x20;
2. Injection into a filesystem call, where you can specify the `phar://` protocol and open up the archive


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heinosass.gitbook.io/leet-sheet/web-app-hacking/server-attacks/page-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
