import pickle import pickletools import another_torch import torch class Vuln(): def __reduce__(self): return (another_torch.run_bash, ()) class Vuln2(): def __reduce__(self): return (torch.run_bash, ()) def run(): with open("vuln.pkl", 'wb') as f: pickle.dump(Vuln(), f) with open("vuln2.pkl", 'wb') as f: pickle.dump(Vuln2(), f) if __name__ == '__main__': run() with open("vuln.pkl", "rb") as f: pickle.load(f)