diff --git a/src/network-services-pentesting/pentesting-631-internet-printing-protocol-ipp.md b/src/network-services-pentesting/pentesting-631-internet-printing-protocol-ipp.md index 5249e067b..e6d0ff8ed 100644 --- a/src/network-services-pentesting/pentesting-631-internet-printing-protocol-ipp.md +++ b/src/network-services-pentesting/pentesting-631-internet-printing-protocol-ipp.md @@ -1,23 +1,103 @@ +# Internet Printing Protocol + {{#include ../banners/hacktricks-training.md}} -# Internet Printing Protocol \(IPP\) +**互联网打印协议 (IPP)**,如 **RFC 2910** 和 **RFC 2911** 中所规定,是网络打印的事实标准。它基于 **HTTP/1.1**(无论是明文还是 TLS)并提供了丰富的 API,用于创建打印作业、查询打印机功能和管理队列。现代扩展如 **IPP Everywhere** 甚至允许在移动和云环境中进行无驱动打印,同时相同的数据包格式也被用于 3D 打印机。 -**互联网打印协议 (IPP)**,如**RFC2910**和**RFC2911**中所规定,是互联网打印的基础。其可扩展性通过**IPP Everywhere**等发展得以展示,旨在标准化移动和云打印,并引入**3D 打印**的扩展。 +不幸的是,暴露端口 **631/tcp(以及用于打印机发现的 631/udp)** 通常会导致严重的安全问题——无论是在传统的办公室打印机上,还是在任何运行 **CUPS** 的 Linux/Unix 主机上。 -利用**HTTP**协议,IPP 受益于已建立的安全实践,包括**基本/摘要认证**和**SSL/TLS 加密**。提交打印作业或查询打印机状态等操作通过指向 IPP 服务器的**HTTP POST 请求**进行,该服务器在**port 631/tcp**上运行。 - -IPP 的一个著名实现是**CUPS**,这是一个在各种 Linux 发行版和 OS X 中普遍使用的开源打印系统。尽管其有用,IPP 与 LPD 类似,可能被利用通过**PostScript**或**PJL 文件**传输恶意内容,突显出潜在的安全风险。 +--- +## Quick PoC – crafting raw IPP with Python ```python -# Example of sending an IPP request using Python -import requests +import struct, requests -url = "http://printer.example.com:631/ipp/print" -headers = {"Content-Type": "application/ipp"} -data = b"..." # IPP request data goes here +# Minimal IPP Get-Printer-Attributes request (operation-id 0x000B) +ipp = struct.pack( +">IHHIHH", # version 2.0, operation-id, request-id +0x0200, # 2.0 +0x000B, # Get-Printer-Attributes +0x00000001, # request-id +0x01, 0x47, # operation-attributes-tag, charset attr (skipped) +) + b"\x03" # end-of-attributes -response = requests.post(url, headers=headers, data=data, verify=True) -print(response.status_code) +r = requests.post("http://printer:631/ipp/print", headers={"Content-Type":"application/ipp"}, data=ipp) +print(r.status_code, r.content[:40]) ``` -如果你想了解更多关于[**黑客打印机,请阅读此页面**](http://hacking-printers.net/wiki/index.php/Main_Page)。 +--- +## 枚举与侦察 +### 1. Nmap NSE +```bash +# run all CUPS/IPP scripts +nmap -sV -p631 --script=cups* +# or only basic info +nmap -p631 --script=cups-info,cups-queue-info +``` +`cups-info` 脚本提取模型、状态和队列统计信息,而 `cups-queue-info` 列举待处理的作业。 + +### 2. 来自 CUPS 的 IPP 工具 +* `ippfind` – 多播/UDP 发现(适用于 cups-browsed): +```bash +ippfind --timeout 3 --txt -v "@local and port=631" # 列出打印机 +``` +* `ipptool` – 在 *.test* 文件中定义的任意请求: +```bash +ipptool -tv ipp:///ipp/print get-printer-attributes.test +``` +捆绑的 *get-printer-attributes.test* 文件查询固件版本、支持的文档格式等。 + +### 3. Shodan / Censys dorks +```bash +shodan search 'product:"CUPS (IPP)" port:631' +``` +超过 **70,000** 个主机在2025年4月公开暴露CUPS。 + +--- +## 最近的漏洞 (2023-2025) + +| 年份 | CVE ID(s) | 受影响组件 | 影响 | +|------|-----------|--------------------|--------| +| 2025 | CVE-2023-50739 | Lexmark固件 (IPP解析器) | 堆溢出 → 通过Wi-Fi/LAN的RCE | +| 2024 | CVE-2024-47076, 47175, 47176, 47177 | cups-browsed, libcupsfilters, libppd, cups-filters | 在任何启用CUPS浏览的Linux桌面/服务器上实现完全未认证的RCE链 | +| 2024 | CVE-2024-35235 | cupsd 2.4.8- | 符号链接技巧 → 任意 **chmod 666** → 权限提升 | +| 2023 | CVE-2023-0856 (佳能) + Pwn2Own | `sides`属性中的堆溢出 → 远程代码执行 | + +### cups-browsed RCE链 (2024年9月) +1. `cups-browsed` 在 **UDP/631** 上监听打印机广告。 +2. 攻击者发送一个指向恶意IPP URL的伪造数据包 (CVE-2024-47176)。 +3. `libcupsfilters` 自动获取远程 **PPD** 而不进行验证 (CVE-2024-47076 & 47175)。 +4. 精心制作的PPD利用 **foomatic-rip** 过滤器在每次打印时执行任意shell命令 (CVE-2024-47177)。 + +概念验证代码在研究者的博客上公开,利用该漏洞 **不需要认证**;对UDP/631的网络访问即可。 + +#### 临时缓解措施 +``` +sudo systemctl stop cups-browsed +sudo systemctl disable cups-browsed +sudo ufw deny 631/udp # or equivalent firewall rule +``` +补丁在2024年10月由主要发行版发布 - 确保 **cups-filters ≥ 2.0.0**。 + +### cupsd符号链接 `Listen` 配置错误 (CVE-2024-35235) +在 *cupsd.conf* 的 `Listen` 指令中放置符号链接会导致 **cupds (root)** 对攻击者选择的路径执行 `chmod 666`,从而导致可写的系统文件,并且在Ubuntu上,通过恶意PPD与 `FoomaticRIPCommandLine` 实现代码执行。 + +--- +## 攻击技术 + +* **未经身份验证的原始打印作业** - 许多打印机接受 `POST /ipp/print` 而无需身份验证。恶意的 **PostScript** 负载可以在高端设备上调用 shell 命令 (`system("/bin/nc ...")`)。 +* **作业劫持** - `Cancel-Job` 后跟 `Send-Document` 允许攻击者在文档被物理打印之前替换其他人的文档。 +* **SNMP → IPP 组合** - 默认社区 `public` 通常会泄露 IPP URL 中所需的内部队列名称。 + +--- +## 防御最佳实践 +1. 及时修补 CUPS 和打印机固件;订阅供应商 PSIRT 信息。 +2. 禁用 `cups-browsed` 和 UDP/631,除非需要零配置打印。 +3. 将 TCP/631 限制在受信任的子网/VPN,并强制使用 **TLS (ipps://)**。 +4. 要求 **Kerberos/Negotiate** 或证书身份验证,而不是匿名打印。 +5. 监控日志:`/var/log/cups/error_log` 配置为 `LogLevel debug2` 将显示不可靠的 PPD 下载或可疑的过滤器调用。 +6. 在高安全性网络中,将打印移至一个加固的、隔离的打印服务器,该服务器仅通过 USB 将作业代理到设备。 + +## 参考文献 +- Akamai – “CUPS中的关键Linux RCE漏洞 — 我们所知道的以及如何准备”,2025年4月。 +- Debian安全跟踪器 – CVE-2024-35235 详细信息。 {{#include ../banners/hacktricks-training.md}}