Exemplo n.º 1
0
 def git_parse_info_refs(self):
     info_refs = 'info/refs'
     refs = self.download_file(info_refs)
     if not refs:
         return
     _print('[*] Detect .git/info/refs')
     refs_info = re.findall(r'([a-z0-9]{40})\t(.*)', refs)
     for _hash, ref in refs_info:
         _mkdir(ref)
         open(ref, 'wb').write(_hash + '\n')
         self.git_refs([ref])
Exemplo n.º 2
0
 def git_parse_tree(self, _hash, _dir='../'):
     _mkdir(_dir)
     _print('[*] Parse Tree {} {}'.format(_dir, _hash[:6]))
     tree = self.git_ls_tree(_hash)
     for _type, _hash, _path in tree:
         if _type == 'blob':
             self.git_save_blob(_dir, _path, _hash)
         elif _type == 'tree':
             self.git_parse_tree(_hash, '{}{}/'.format(_dir, _path))
         elif _type == 'commit':
             self.git_commit(_hash)
         else:
             _print('[-] unknown {} {}'.format(
                 self.git_object_parse(_hash)[0], _hash), 'red')
Exemplo n.º 3
0
 def pack_to_object_file(self):
     for _object in self.objects.values():
         try:
             object_format = '{} {}\x00{}'.format(_object['type'],
                                                  _object['length'],
                                                  _object['file'])
         except KeyError:
             continue
         sha = hashlib.sha1(object_format).hexdigest()
         path = 'objects/{}/{}'.format(sha[:2], sha[2:])
         zlib_object = zlib.compress(object_format)
         _mkdir(path)
         _print('[+] Pack {}'.format(path), 'green', end='\r')
         open(path, 'wb').write(zlib_object)
     _print('', logtime=False)
Exemplo n.º 4
0
 def __init__(self, git_host):
     self.git_host = git_host
     if 'http' in self.git_host:
         self.git_path = re.search(r'https?://(.*)',
                                   git_host).group(1).replace(':', '_')
         self.local = False
     else:
         self.git_path = git_host
         self.local = True
     self.objects = {}
     self.refs_hash = set()
     _mkdir(self.git_path)
     os.chdir(self.git_path)
     self._logo()
     _print('[*] Start Git Extract')
     _print('[*] Target Url: {}'.format(self.git_host))
Exemplo n.º 5
0
 def download_file(self, path):
     if os.path.exists(path):
         return open(path, 'rb').read()
     if self.local:
         return
     url = self.git_host + path
     try:
         resp = http_resp(url)
         if resp.getcode() == 200:
             data = resp.read()
             _mkdir(path)
             open(path, 'wb').write(data)
             return data
     except Exception as e:
         # _print('[-] File not exist {} '.format(path), 'red')
         pass
Exemplo n.º 6
0
 def download_file(self, path):
     if os.path.exists(path):
         return open(path, 'rb').read()
     if self.local:
         return
     url = self.git_host + path
     try:
         ctx = ssl.create_default_context()
         ctx.check_hostname = False
         ctx.verify_mode = ssl.CERT_NONE
         resp = urllib2.urlopen(url, context=ctx)
         if resp.getcode() == 200:
             data = resp.read()
             _mkdir(path)
             open(path, 'wb').write(data)
             return data
     except Exception as e:
         # _print('[-] File not exist {} '.format(path), 'red')
         return
Exemplo n.º 7
0
 def __init__(self, git_host):
     if os.path.exists(git_host):
         self.git_path = git_host
         self.local = True
     elif (git_host.startswith('http')
             and git_host.endswith('/')):
         self.git_path = re.search(
             r'https?://(.*)', git_host
         ).group(1).replace(':', '_')
         self.local = False
         _mkdir(self.git_path)
     else:
         _print('Usage:\n\tpython {} http://example.com/.git/'.format((sys.argv[0])), 'red')
         sys.exit(0)
     self.objects = {}
     self.refs_hash = set()
     self.git_host = git_host
     self._logo()
     _print('[*] Start Extract')
     _print('[*] Target Git: {}'.format(self.git_host))
     os.chdir(self.git_path)
Exemplo n.º 8
0
 def git_save_blob(self, _dir, _path, _hash, save_file=False):
     filename = _dir + _path
     try:
         data = self.git_object_parse(_hash)[2]
     except TypeError:
         return
     _mkdir(filename)
     if os.path.isfile(filename):
         file = open(filename, 'rb').read()
         if file != data:
             filename = '{}{}.{}'.format(_dir, _path, _hash[:6])
             if not os.path.isfile(filename):
                 save_file = True
     else:
         save_file = True
     if save_file:
         try:
             _print('[+] Save {}'.format(filename), 'green')
             open(filename, 'wb').write(data)
         except Exception:
             pass