Injecting Backdoor Into Ml Model
The author demonstrates that Python pickle files can contain instructions that execute arbitrary code when loaded, and shows injecting a backdoor into a legitimate machine-learning model pickle file. An attacker who can supply a malicious pickle file could run code on the victim's machine when the model is loaded.
I am Harish SG, a security researcher who studies Masters in Cybersecurity at UT Dallas,previously hunted on the Microsoft Bug Bounty Program and Google VRP.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The pickle format allows arbitrary function calls during deserialisation, so loading an untrusted pickle file can execute attacker-controlled code.
Impact
An attacker who can supply a malicious pickle file could execute arbitrary code on the victim's machine when the model is loaded.
What the attacker needed
Victim loads an untrusted pickle file
The fix
Use safer serialization formats such as JSON, validate file hashes, run with least privilege, sandbox unpickling, and restrict global imports by overriding find_class.
How it was found
- Write a Python script that loads an existing pickle file and modifies it to include arbitrary Python code.
- Save the modified pickle back to disk.
- Load the modified pickle file, which executes the injected code.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A pickle file is a way Python saves objects, including trained machine-learning models, so they can be loaded later. The pickle format can include instructions to run functions, so loading a pickle from an untrusted source can run the attacker's code on your computer. The author shows how to modify a model file so that loading it runs a harmless print statement.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.