Skip to content

Commit a3d70b1

Browse files
committedMay 9, 2022
bug fix
1 parent 9b60035 commit a3d70b1

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed
 

‎GitHack.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,34 @@ def __init__(self):
4848
f.write(data)
4949
if not os.path.exists(self.domain):
5050
os.mkdir(self.domain)
51+
self.dest_dir = os.path.abspath(self.domain)
5152
self.queue = Queue.Queue()
5253
for entry in parse('index'):
5354
if "sha1" in entry.keys():
54-
if entry["name"].strip().find('..') < 0:
55-
self.queue.put((entry["sha1"].strip(), entry["name"].strip()))
56-
try:
57-
print('[+] %s' % entry['name'])
58-
except Exception as e:
59-
pass
55+
entry_name = entry["name"].strip()
56+
if self.is_valid_name(entry_name):
57+
self.queue.put((entry["sha1"].strip(), entry_name))
58+
try:
59+
print('[+] %s' % entry['name'])
60+
except Exception as e:
61+
pass
62+
6063
self.lock = threading.Lock()
6164
self.thread_count = 10
6265
self.STOP_ME = False
6366

67+
def is_valid_name(self, entry_name):
68+
if entry_name.find('..') >= 0 or \
69+
entry_name.startswith('/') or \
70+
entry_name.startswith('\\') or \
71+
not os.path.abspath(os.path.join(self.domain, entry_name)).startswith(self.dest_dir):
72+
try:
73+
print('[ERROR] Invalid entry name: %s' % entry_name)
74+
except Exception as e:
75+
pass
76+
return False
77+
return True
78+
6479
@staticmethod
6580
def _request_data(url):
6681
request = urllib2.Request(url, None, {'User-Agent': user_agent})

‎README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# GitHack
22

33

4+
### This is important
5+
### All users please git pull to update source code. (2022-05-09)
6+
47
GitHack is a `.git` folder disclosure exploit.
58

69
It rebuild source code from .git folder while keep directory structure unchanged.
@@ -11,7 +14,8 @@ GitHack是一个.git泄露利用脚本,通过泄露的.git文件夹下的文
1114

1215
## Change Log
1316

14-
* 2022-04-07:Fix abitrary file write vulnerability. Thanks for [@justinsteven](https://github.com/justinsteven) \'s bug report, it's very helpful.
17+
* 2022-05-09: Bug fix, thanks [@justinsteven](https://github.com/justinsteven) .
18+
* 2022-04-07:Fix arbitrary file write vulnerability. Thanks for [@justinsteven](https://github.com/justinsteven) \'s bug report, it's very helpful.
1519
* 2022-04-07:Add python3.x support
1620

1721
## How It works ##

0 commit comments

Comments
 (0)
Please sign in to comment.