You need to agree to share your contact information to access this dataset

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this dataset content.

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

optuna Pickle Deserialization RCE PoC (CWE-502)

Proof of Concept for arbitrary code execution via two independent pickle.loads() sinks in optuna <= 4.9.0 (latest on PyPI).

Vulnerability

optuna uses raw pickle.loads() on data from shared external storage backends with zero security mitigations:

Sink 1: CMA-ES Sampler (samplers/_cmaes.py:504)

return pickle.loads(bytes.fromhex(optimizer_str))

The CMA-ES sampler serializes optimizer state via pickle.dumps().hex() and stores it in trial system_attrs in the shared database (MySQL/PostgreSQL/SQLite). When any optuna worker restores a previous optimizer via _restore_optimizer(), the hex-encoded pickle is deserialized without any validation.

Attack vector: An attacker with write access to the shared database inserts a malicious hex-encoded pickle payload into the trial_system_attributes table with a key matching cma:optimizer:N. Any worker using CmaEsSampler that reads trials from this database will execute arbitrary code.

Sink 2: JournalRedisBackend Snapshot (storages/journal/_storage.py:129)

r: JournalStorageReplayResult | None = pickle.loads(snapshot)

The JournalStorage saves periodic snapshots via pickle.dumps() to Redis. When a new JournalStorage instance is created, the constructor calls load_snapshot() then restore_replay_result() which calls pickle.loads() on the raw Redis bytes.

Attack vector: An attacker with write access to the Redis server (commonly unprotected, default no-auth) sets the {prefix}:snapshot key to a malicious pickle payload. Any optuna process that connects to this Redis backend will execute arbitrary code during initialization, before any user code runs.

Note: The isinstance() check on line 135 is NOT a security mitigation -- it runs after pickle.loads() has already executed. In pickle attacks, __reduce__ runs during deserialization itself.

Reproduction

pip install optuna==4.9.0
python verify_bypass.py

Expected output: [+] *** RCE CONFIRMED via Sink 1 (CMA-ES)! *** and [+] *** RCE CONFIRMED via Sink 2 (Redis snapshot)! ***

Downloads last month
6