Created
January 17, 2019 01:13
-
-
Save dreilly369/feb510c9b5ce3f1cc7ebdd93f3b6431d to your computer and use it in GitHub Desktop.
Find potentially active Git Hooks and print their SHA256 value
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
import os | |
import hashlib | |
import json | |
def sha256sum(filename): | |
h = hashlib.sha256() | |
b = bytearray(128*1024) | |
mv = memoryview(b) | |
with open(filename, 'rb', buffering=0) as f: | |
for n in iter(lambda : f.readinto(mv), 0): | |
h.update(mv[:n]) | |
return h.hexdigest() | |
print("Collecting Repos") | |
repos = [] | |
hook_hashes = {} | |
for root, dirs, files in os.walk("/"): | |
#print(root) | |
if ".git" in dirs: | |
#print(("%s/.git/ found" % root)) | |
loc = os.path.join(root, ".git", "hooks") | |
repos.append(loc) | |
print("Found %d repos" % len(repos)) | |
print("checking git hooks") | |
for hook_dir in repos: | |
for root, dirs, files in os.walk(hook_dir): | |
for f in files: | |
if ".sample" in f: | |
continue | |
fp = os.path.join(root, f) | |
fh = sha256sum(fp) | |
print(fp) | |
print(fh) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment