> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/offensive-security-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/offensive-security-writeups/port-swigger-insecure-desiralization-labs/lab-1.md).

# lab-1

## Modifying Serialized Objects

**Difficulty:** Apprentice

### Lab Description

This lab uses a serialization-based session mechanism and is vulnerable to privilege escalation.

**Objective:** Edit the serialized object in the session cookie to gain administrative privileges, then delete the user `carlos`.

**Credentials:** `wiener:peter`

### Root Cause

PHP uses a mostly human-readable string format for serialization, with letters representing the data type and numbers representing the length of each entry. For example, a `User` object with the attributes:

```php
$user->name = "carlos";
$user->isLoggedIn = true;
```

When serialized, looks like:

```
O:4:"User":2:{s:4:"name";s:6:"carlos";s:10:"isLoggedIn";b:1;}
```

This serialized object can be stored anywhere — browser cookies, local storage, session — in any encoded format (such as Base64) within the HTTP request. Anyone can decode it, identify it as a PHP serialized object, modify its values, and send it back to the server. If the server blindly trusts and deserializes the modified object without checking whether it was legitimately generated by the application, the attacker gets whatever access the modified data grants. This leads to account takeover, access control bypass, and privilege escalation.

### Exploitation

1. Start the login flow as `wiener:peter`.
2. After login, inspect the session cookie — in the browser's Network tab or Burp, URL-decode it, then Base64-decode it to reveal the raw PHP serialized object.
3. Find the `isAdmin` attribute and change `b:0` to `b:1`.
4. Re-encode the modified object: Base64-encode it, then URL-encode the result.
5. Replace the session cookie with the modified value and reload the page.
6. The admin panel is now accessible — delete `carlos` to complete the lab.

### Lesson Learned

The server must verify — before deserializing — that the serialized object was legitimately generated by the application. Never blindly trust user-controlled objects. If serialized data must be stored client-side, protect it with cryptographic integrity (for example, an HMAC or authenticated encryption) so that any modification can be detected before deserialization occurs.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ganesha-hk.gitbook.io/offensive-security-writeups/port-swigger-insecure-desiralization-labs/lab-1.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
