Skip to content

Instantly share code, notes, and snippets.

@kaashmonee
Created December 23, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaashmonee/a64fea71c82673918962d292987a29da to your computer and use it in GitHub Desktop.
Save kaashmonee/a64fea71c82673918962d292987a29da to your computer and use it in GitHub Desktop.
Solution to Leaf of the Tree challenge in PicoCTF. Traverses all directories in path and retrieves flag file.
# picoCTF leaf of the tree
import os
path = "/problems/5da315e9c7f1c9886ea371abee5ae8d0"
def getPath(path):
if not os.path.isdir(path):
return path
else:
for dir in listdir_fullpath(path):
#print("dir", dir)
p = getPath(dir)
if p is not None and "flag" in p: return p
return None
def listdir_fullpath(d):
return [os.path.join(d, f) for f in os.listdir(d)]
path = getPath(path)
with open(path) as f: print(f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment